diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..0e5ec3d --- /dev/null +++ b/Makefile @@ -0,0 +1,3 @@ +.PHONY: pb +pb: + protoc --go_out=. pb/*.proto diff --git a/connection.go b/connection.go index d0e9909..040732c 100644 --- a/connection.go +++ b/connection.go @@ -8,7 +8,7 @@ import ( "sync" "time" - "github.com/gogo/protobuf/proto" + "github.com/golang/protobuf/proto" "github.com/nknorg/ncp-go/pb" ) diff --git a/go.mod b/go.mod index fc0af08..b46224c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/nknorg/ncp-go go 1.13 require ( - github.com/gogo/protobuf v1.3.1 + github.com/golang/protobuf v1.4.1 github.com/imdario/mergo v0.3.8 github.com/stretchr/testify v1.4.0 // indirect gopkg.in/yaml.v2 v2.2.8 // indirect diff --git a/go.sum b/go.sum index f53e212..1d4ca43 100644 --- a/go.sum +++ b/go.sum @@ -1,17 +1,32 @@ github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls= -github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.1 h1:ZFgWrT+bLgsYPirOnRfKLYJLvssAegOj/hgyMFdJZe0= +github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/imdario/mergo v0.3.8 h1:CGgOkSJeqMRmt0D9XLWExdT4m4F1vd3FV3VPt+0VxkQ= github.com/imdario/mergo v0.3.8/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA= -github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= -github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= -golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.22.0 h1:cJv5/xdbk1NnMPR1VP9+HU6gupuG9MLBoH1r6RHZ2MY= +google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= diff --git a/pb/packet.pb.go b/pb/packet.pb.go index d131aff..2c538a5 100644 --- a/pb/packet.pb.go +++ b/pb/packet.pb.go @@ -1,19 +1,11 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. +// Code generated by protoc-gen-go. DO NOT EDIT. // source: pb/packet.proto package pb -import proto "github.com/gogo/protobuf/proto" +import proto "github.com/golang/protobuf/proto" import fmt "fmt" import math "math" -import _ "github.com/gogo/protobuf/gogoproto" - -import bytes "bytes" - -import strings "strings" -import reflect "reflect" - -import io "io" // Reference imports to suppress errors if they are not otherwise used. var _ = proto.Marshal @@ -24,46 +16,41 @@ var _ = math.Inf // is compatible with the proto package it is being compiled against. // A compilation error at this line likely means your copy of the // proto package needs to be updated. -const _ = proto.GoGoProtoPackageIsVersion2 // please upgrade the proto package +const _ = proto.ProtoPackageIsVersion2 // please upgrade the proto package type Packet struct { - SequenceId uint32 `protobuf:"varint,1,opt,name=sequence_id,json=sequenceId,proto3" json:"sequence_id,omitempty"` - Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` - AckStartSeq []uint32 `protobuf:"varint,3,rep,packed,name=ack_start_seq,json=ackStartSeq" json:"ack_start_seq,omitempty"` - AckSeqCount []uint32 `protobuf:"varint,4,rep,packed,name=ack_seq_count,json=ackSeqCount" json:"ack_seq_count,omitempty"` - BytesRead uint64 `protobuf:"varint,5,opt,name=bytes_read,json=bytesRead,proto3" json:"bytes_read,omitempty"` - ClientIds []string `protobuf:"bytes,6,rep,name=client_ids,json=clientIds" json:"client_ids,omitempty"` - WindowSize uint32 `protobuf:"varint,7,opt,name=window_size,json=windowSize,proto3" json:"window_size,omitempty"` - Mtu uint32 `protobuf:"varint,8,opt,name=mtu,proto3" json:"mtu,omitempty"` - Close bool `protobuf:"varint,9,opt,name=close,proto3" json:"close,omitempty"` - Handshake bool `protobuf:"varint,10,opt,name=handshake,proto3" json:"handshake,omitempty"` -} - -func (m *Packet) Reset() { *m = Packet{} } -func (*Packet) ProtoMessage() {} + SequenceId uint32 `protobuf:"varint,1,opt,name=sequence_id,json=sequenceId,proto3" json:"sequence_id,omitempty"` + Data []byte `protobuf:"bytes,2,opt,name=data,proto3" json:"data,omitempty"` + AckStartSeq []uint32 `protobuf:"varint,3,rep,packed,name=ack_start_seq,json=ackStartSeq,proto3" json:"ack_start_seq,omitempty"` + AckSeqCount []uint32 `protobuf:"varint,4,rep,packed,name=ack_seq_count,json=ackSeqCount,proto3" json:"ack_seq_count,omitempty"` + BytesRead uint64 `protobuf:"varint,5,opt,name=bytes_read,json=bytesRead,proto3" json:"bytes_read,omitempty"` + ClientIds []string `protobuf:"bytes,6,rep,name=client_ids,json=clientIds,proto3" json:"client_ids,omitempty"` + WindowSize uint32 `protobuf:"varint,7,opt,name=window_size,json=windowSize,proto3" json:"window_size,omitempty"` + Mtu uint32 `protobuf:"varint,8,opt,name=mtu,proto3" json:"mtu,omitempty"` + Close bool `protobuf:"varint,9,opt,name=close,proto3" json:"close,omitempty"` + Handshake bool `protobuf:"varint,10,opt,name=handshake,proto3" json:"handshake,omitempty"` + XXX_NoUnkeyedLiteral struct{} `json:"-"` + XXX_unrecognized []byte `json:"-"` + XXX_sizecache int32 `json:"-"` +} + +func (m *Packet) Reset() { *m = Packet{} } +func (m *Packet) String() string { return proto.CompactTextString(m) } +func (*Packet) ProtoMessage() {} func (*Packet) Descriptor() ([]byte, []int) { - return fileDescriptor_packet_31a3274a712aed0f, []int{0} + return fileDescriptor_packet_dc5a9d1a21ec3142, []int{0} } func (m *Packet) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) + return xxx_messageInfo_Packet.Unmarshal(m, b) } func (m *Packet) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_Packet.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalTo(b) - if err != nil { - return nil, err - } - return b[:n], nil - } + return xxx_messageInfo_Packet.Marshal(b, m, deterministic) } func (dst *Packet) XXX_Merge(src proto.Message) { xxx_messageInfo_Packet.Merge(dst, src) } func (m *Packet) XXX_Size() int { - return m.Size() + return xxx_messageInfo_Packet.Size(m) } func (m *Packet) XXX_DiscardUnknown() { xxx_messageInfo_Packet.DiscardUnknown(m) @@ -144,897 +131,25 @@ func (m *Packet) GetHandshake() bool { func init() { proto.RegisterType((*Packet)(nil), "pb.Packet") } -func (this *Packet) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*Packet) - if !ok { - that2, ok := that.(Packet) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.SequenceId != that1.SequenceId { - return false - } - if !bytes.Equal(this.Data, that1.Data) { - return false - } - if len(this.AckStartSeq) != len(that1.AckStartSeq) { - return false - } - for i := range this.AckStartSeq { - if this.AckStartSeq[i] != that1.AckStartSeq[i] { - return false - } - } - if len(this.AckSeqCount) != len(that1.AckSeqCount) { - return false - } - for i := range this.AckSeqCount { - if this.AckSeqCount[i] != that1.AckSeqCount[i] { - return false - } - } - if this.BytesRead != that1.BytesRead { - return false - } - if len(this.ClientIds) != len(that1.ClientIds) { - return false - } - for i := range this.ClientIds { - if this.ClientIds[i] != that1.ClientIds[i] { - return false - } - } - if this.WindowSize != that1.WindowSize { - return false - } - if this.Mtu != that1.Mtu { - return false - } - if this.Close != that1.Close { - return false - } - if this.Handshake != that1.Handshake { - return false - } - return true -} -func (this *Packet) GoString() string { - if this == nil { - return "nil" - } - s := make([]string, 0, 14) - s = append(s, "&pb.Packet{") - s = append(s, "SequenceId: "+fmt.Sprintf("%#v", this.SequenceId)+",\n") - s = append(s, "Data: "+fmt.Sprintf("%#v", this.Data)+",\n") - s = append(s, "AckStartSeq: "+fmt.Sprintf("%#v", this.AckStartSeq)+",\n") - s = append(s, "AckSeqCount: "+fmt.Sprintf("%#v", this.AckSeqCount)+",\n") - s = append(s, "BytesRead: "+fmt.Sprintf("%#v", this.BytesRead)+",\n") - s = append(s, "ClientIds: "+fmt.Sprintf("%#v", this.ClientIds)+",\n") - s = append(s, "WindowSize: "+fmt.Sprintf("%#v", this.WindowSize)+",\n") - s = append(s, "Mtu: "+fmt.Sprintf("%#v", this.Mtu)+",\n") - s = append(s, "Close: "+fmt.Sprintf("%#v", this.Close)+",\n") - s = append(s, "Handshake: "+fmt.Sprintf("%#v", this.Handshake)+",\n") - s = append(s, "}") - return strings.Join(s, "") -} -func valueToGoStringPacket(v interface{}, typ string) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("func(v %v) *%v { return &v } ( %#v )", typ, typ, pv) -} -func (m *Packet) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalTo(dAtA) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *Packet) MarshalTo(dAtA []byte) (int, error) { - var i int - _ = i - var l int - _ = l - if m.SequenceId != 0 { - dAtA[i] = 0x8 - i++ - i = encodeVarintPacket(dAtA, i, uint64(m.SequenceId)) - } - if len(m.Data) > 0 { - dAtA[i] = 0x12 - i++ - i = encodeVarintPacket(dAtA, i, uint64(len(m.Data))) - i += copy(dAtA[i:], m.Data) - } - if len(m.AckStartSeq) > 0 { - dAtA2 := make([]byte, len(m.AckStartSeq)*10) - var j1 int - for _, num := range m.AckStartSeq { - for num >= 1<<7 { - dAtA2[j1] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j1++ - } - dAtA2[j1] = uint8(num) - j1++ - } - dAtA[i] = 0x1a - i++ - i = encodeVarintPacket(dAtA, i, uint64(j1)) - i += copy(dAtA[i:], dAtA2[:j1]) - } - if len(m.AckSeqCount) > 0 { - dAtA4 := make([]byte, len(m.AckSeqCount)*10) - var j3 int - for _, num := range m.AckSeqCount { - for num >= 1<<7 { - dAtA4[j3] = uint8(uint64(num)&0x7f | 0x80) - num >>= 7 - j3++ - } - dAtA4[j3] = uint8(num) - j3++ - } - dAtA[i] = 0x22 - i++ - i = encodeVarintPacket(dAtA, i, uint64(j3)) - i += copy(dAtA[i:], dAtA4[:j3]) - } - if m.BytesRead != 0 { - dAtA[i] = 0x28 - i++ - i = encodeVarintPacket(dAtA, i, uint64(m.BytesRead)) - } - if len(m.ClientIds) > 0 { - for _, s := range m.ClientIds { - dAtA[i] = 0x32 - i++ - l = len(s) - for l >= 1<<7 { - dAtA[i] = uint8(uint64(l)&0x7f | 0x80) - l >>= 7 - i++ - } - dAtA[i] = uint8(l) - i++ - i += copy(dAtA[i:], s) - } - } - if m.WindowSize != 0 { - dAtA[i] = 0x38 - i++ - i = encodeVarintPacket(dAtA, i, uint64(m.WindowSize)) - } - if m.Mtu != 0 { - dAtA[i] = 0x40 - i++ - i = encodeVarintPacket(dAtA, i, uint64(m.Mtu)) - } - if m.Close { - dAtA[i] = 0x48 - i++ - if m.Close { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - if m.Handshake { - dAtA[i] = 0x50 - i++ - if m.Handshake { - dAtA[i] = 1 - } else { - dAtA[i] = 0 - } - i++ - } - return i, nil -} - -func encodeVarintPacket(dAtA []byte, offset int, v uint64) int { - for v >= 1<<7 { - dAtA[offset] = uint8(v&0x7f | 0x80) - v >>= 7 - offset++ - } - dAtA[offset] = uint8(v) - return offset + 1 -} -func NewPopulatedPacket(r randyPacket, easy bool) *Packet { - this := &Packet{} - this.SequenceId = uint32(r.Uint32()) - v1 := r.Intn(100) - this.Data = make([]byte, v1) - for i := 0; i < v1; i++ { - this.Data[i] = byte(r.Intn(256)) - } - v2 := r.Intn(10) - this.AckStartSeq = make([]uint32, v2) - for i := 0; i < v2; i++ { - this.AckStartSeq[i] = uint32(r.Uint32()) - } - v3 := r.Intn(10) - this.AckSeqCount = make([]uint32, v3) - for i := 0; i < v3; i++ { - this.AckSeqCount[i] = uint32(r.Uint32()) - } - this.BytesRead = uint64(uint64(r.Uint32())) - v4 := r.Intn(10) - this.ClientIds = make([]string, v4) - for i := 0; i < v4; i++ { - this.ClientIds[i] = string(randStringPacket(r)) - } - this.WindowSize = uint32(r.Uint32()) - this.Mtu = uint32(r.Uint32()) - this.Close = bool(bool(r.Intn(2) == 0)) - this.Handshake = bool(bool(r.Intn(2) == 0)) - if !easy && r.Intn(10) != 0 { - } - return this -} - -type randyPacket interface { - Float32() float32 - Float64() float64 - Int63() int64 - Int31() int32 - Uint32() uint32 - Intn(n int) int -} - -func randUTF8RunePacket(r randyPacket) rune { - ru := r.Intn(62) - if ru < 10 { - return rune(ru + 48) - } else if ru < 36 { - return rune(ru + 55) - } - return rune(ru + 61) -} -func randStringPacket(r randyPacket) string { - v5 := r.Intn(100) - tmps := make([]rune, v5) - for i := 0; i < v5; i++ { - tmps[i] = randUTF8RunePacket(r) - } - return string(tmps) -} -func randUnrecognizedPacket(r randyPacket, maxFieldNumber int) (dAtA []byte) { - l := r.Intn(5) - for i := 0; i < l; i++ { - wire := r.Intn(4) - if wire == 3 { - wire = 5 - } - fieldNumber := maxFieldNumber + r.Intn(100) - dAtA = randFieldPacket(dAtA, r, fieldNumber, wire) - } - return dAtA -} -func randFieldPacket(dAtA []byte, r randyPacket, fieldNumber int, wire int) []byte { - key := uint32(fieldNumber)<<3 | uint32(wire) - switch wire { - case 0: - dAtA = encodeVarintPopulatePacket(dAtA, uint64(key)) - v6 := r.Int63() - if r.Intn(2) == 0 { - v6 *= -1 - } - dAtA = encodeVarintPopulatePacket(dAtA, uint64(v6)) - case 1: - dAtA = encodeVarintPopulatePacket(dAtA, uint64(key)) - dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) - case 2: - dAtA = encodeVarintPopulatePacket(dAtA, uint64(key)) - ll := r.Intn(100) - dAtA = encodeVarintPopulatePacket(dAtA, uint64(ll)) - for j := 0; j < ll; j++ { - dAtA = append(dAtA, byte(r.Intn(256))) - } - default: - dAtA = encodeVarintPopulatePacket(dAtA, uint64(key)) - dAtA = append(dAtA, byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256)), byte(r.Intn(256))) - } - return dAtA -} -func encodeVarintPopulatePacket(dAtA []byte, v uint64) []byte { - for v >= 1<<7 { - dAtA = append(dAtA, uint8(uint64(v)&0x7f|0x80)) - v >>= 7 - } - dAtA = append(dAtA, uint8(v)) - return dAtA -} -func (m *Packet) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.SequenceId != 0 { - n += 1 + sovPacket(uint64(m.SequenceId)) - } - l = len(m.Data) - if l > 0 { - n += 1 + l + sovPacket(uint64(l)) - } - if len(m.AckStartSeq) > 0 { - l = 0 - for _, e := range m.AckStartSeq { - l += sovPacket(uint64(e)) - } - n += 1 + sovPacket(uint64(l)) + l - } - if len(m.AckSeqCount) > 0 { - l = 0 - for _, e := range m.AckSeqCount { - l += sovPacket(uint64(e)) - } - n += 1 + sovPacket(uint64(l)) + l - } - if m.BytesRead != 0 { - n += 1 + sovPacket(uint64(m.BytesRead)) - } - if len(m.ClientIds) > 0 { - for _, s := range m.ClientIds { - l = len(s) - n += 1 + l + sovPacket(uint64(l)) - } - } - if m.WindowSize != 0 { - n += 1 + sovPacket(uint64(m.WindowSize)) - } - if m.Mtu != 0 { - n += 1 + sovPacket(uint64(m.Mtu)) - } - if m.Close { - n += 2 - } - if m.Handshake { - n += 2 - } - return n -} - -func sovPacket(x uint64) (n int) { - for { - n++ - x >>= 7 - if x == 0 { - break - } - } - return n -} -func sozPacket(x uint64) (n int) { - return sovPacket(uint64((x << 1) ^ uint64((int64(x) >> 63)))) -} -func (this *Packet) String() string { - if this == nil { - return "nil" - } - s := strings.Join([]string{`&Packet{`, - `SequenceId:` + fmt.Sprintf("%v", this.SequenceId) + `,`, - `Data:` + fmt.Sprintf("%v", this.Data) + `,`, - `AckStartSeq:` + fmt.Sprintf("%v", this.AckStartSeq) + `,`, - `AckSeqCount:` + fmt.Sprintf("%v", this.AckSeqCount) + `,`, - `BytesRead:` + fmt.Sprintf("%v", this.BytesRead) + `,`, - `ClientIds:` + fmt.Sprintf("%v", this.ClientIds) + `,`, - `WindowSize:` + fmt.Sprintf("%v", this.WindowSize) + `,`, - `Mtu:` + fmt.Sprintf("%v", this.Mtu) + `,`, - `Close:` + fmt.Sprintf("%v", this.Close) + `,`, - `Handshake:` + fmt.Sprintf("%v", this.Handshake) + `,`, - `}`, - }, "") - return s -} -func valueToStringPacket(v interface{}) string { - rv := reflect.ValueOf(v) - if rv.IsNil() { - return "nil" - } - pv := reflect.Indirect(rv).Interface() - return fmt.Sprintf("*%v", pv) -} -func (m *Packet) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: Packet: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: Packet: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SequenceId", wireType) - } - m.SequenceId = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SequenceId |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field Data", wireType) - } - var byteLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - byteLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if byteLen < 0 { - return ErrInvalidLengthPacket - } - postIndex := iNdEx + byteLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.Data = append(m.Data[:0], dAtA[iNdEx:postIndex]...) - if m.Data == nil { - m.Data = []byte{} - } - iNdEx = postIndex - case 3: - if wireType == 0 { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.AckStartSeq = append(m.AckStartSeq, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthPacket - } - postIndex := iNdEx + packedLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - for iNdEx < postIndex { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.AckStartSeq = append(m.AckStartSeq, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field AckStartSeq", wireType) - } - case 4: - if wireType == 0 { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.AckSeqCount = append(m.AckSeqCount, v) - } else if wireType == 2 { - var packedLen int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - packedLen |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - if packedLen < 0 { - return ErrInvalidLengthPacket - } - postIndex := iNdEx + packedLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - for iNdEx < postIndex { - var v uint32 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.AckSeqCount = append(m.AckSeqCount, v) - } - } else { - return fmt.Errorf("proto: wrong wireType = %d for field AckSeqCount", wireType) - } - case 5: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field BytesRead", wireType) - } - m.BytesRead = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.BytesRead |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 6: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field ClientIds", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthPacket - } - postIndex := iNdEx + intStringLen - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.ClientIds = append(m.ClientIds, string(dAtA[iNdEx:postIndex])) - iNdEx = postIndex - case 7: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field WindowSize", wireType) - } - m.WindowSize = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.WindowSize |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 8: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Mtu", wireType) - } - m.Mtu = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Mtu |= (uint32(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - case 9: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Close", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Close = bool(v != 0) - case 10: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Handshake", wireType) - } - var v int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowPacket - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - v |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - m.Handshake = bool(v != 0) - default: - iNdEx = preIndex - skippy, err := skipPacket(dAtA[iNdEx:]) - if err != nil { - return err - } - if skippy < 0 { - return ErrInvalidLengthPacket - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} -func skipPacket(dAtA []byte) (n int, err error) { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowPacket - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - wireType := int(wire & 0x7) - switch wireType { - case 0: - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowPacket - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - iNdEx++ - if dAtA[iNdEx-1] < 0x80 { - break - } - } - return iNdEx, nil - case 1: - iNdEx += 8 - return iNdEx, nil - case 2: - var length int - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowPacket - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - length |= (int(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - iNdEx += length - if length < 0 { - return 0, ErrInvalidLengthPacket - } - return iNdEx, nil - case 3: - for { - var innerWire uint64 - var start int = iNdEx - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return 0, ErrIntOverflowPacket - } - if iNdEx >= l { - return 0, io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - innerWire |= (uint64(b) & 0x7F) << shift - if b < 0x80 { - break - } - } - innerWireType := int(innerWire & 0x7) - if innerWireType == 4 { - break - } - next, err := skipPacket(dAtA[start:]) - if err != nil { - return 0, err - } - iNdEx = start + next - } - return iNdEx, nil - case 4: - return iNdEx, nil - case 5: - iNdEx += 4 - return iNdEx, nil - default: - return 0, fmt.Errorf("proto: illegal wireType %d", wireType) - } - } - panic("unreachable") -} - -var ( - ErrInvalidLengthPacket = fmt.Errorf("proto: negative length found during unmarshaling") - ErrIntOverflowPacket = fmt.Errorf("proto: integer overflow") -) - -func init() { proto.RegisterFile("pb/packet.proto", fileDescriptor_packet_31a3274a712aed0f) } -var fileDescriptor_packet_31a3274a712aed0f = []byte{ - // 354 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0x90, 0xb1, 0x8e, 0xda, 0x30, - 0x18, 0xc7, 0x63, 0x02, 0x94, 0x98, 0xa2, 0x56, 0x56, 0x07, 0xab, 0x6a, 0xdd, 0x88, 0x29, 0x4b, - 0x61, 0xe8, 0xda, 0xa9, 0x9d, 0xd8, 0xaa, 0xf0, 0x00, 0x91, 0x63, 0x7f, 0x85, 0x28, 0x10, 0x27, - 0xd8, 0x11, 0x2a, 0x53, 0x1f, 0xe1, 0x1e, 0xe3, 0x74, 0x4f, 0x70, 0x8f, 0x70, 0x23, 0x23, 0xe3, - 0xc5, 0x2c, 0x37, 0x32, 0xde, 0x78, 0x8a, 0xa3, 0x3b, 0xb6, 0xff, 0xff, 0xf7, 0xfb, 0x6c, 0x7d, - 0xfa, 0xf0, 0x87, 0x32, 0x9d, 0x97, 0x5c, 0xe4, 0x60, 0x66, 0xe5, 0x4e, 0x19, 0x45, 0x7a, 0x65, - 0xfa, 0xf9, 0xfb, 0x2a, 0x33, 0xeb, 0x3a, 0x9d, 0x09, 0xb5, 0x9d, 0xaf, 0xd4, 0x4a, 0xcd, 0x9d, - 0x4a, 0xeb, 0xbf, 0xae, 0xb9, 0xe2, 0x52, 0xf7, 0x64, 0x7a, 0xd7, 0xc3, 0xc3, 0x3f, 0xee, 0x0f, - 0xf2, 0x0d, 0x8f, 0x35, 0x54, 0x35, 0x14, 0x02, 0x92, 0x4c, 0x52, 0x14, 0xa2, 0x68, 0x12, 0xe3, - 0x57, 0xb4, 0x90, 0x84, 0xe0, 0xbe, 0xe4, 0x86, 0xd3, 0x5e, 0x88, 0xa2, 0xf7, 0xb1, 0xcb, 0x64, - 0x8a, 0x27, 0x5c, 0xe4, 0x89, 0x36, 0x7c, 0x67, 0x12, 0x0d, 0x15, 0xf5, 0x43, 0x3f, 0x9a, 0xc4, - 0x63, 0x2e, 0xf2, 0x65, 0xcb, 0x96, 0x50, 0xbd, 0xcd, 0x40, 0x95, 0x08, 0x55, 0x17, 0x86, 0xf6, - 0xaf, 0x33, 0x50, 0xfd, 0x6e, 0x11, 0xf9, 0x8a, 0x71, 0xfa, 0xcf, 0x80, 0x4e, 0x76, 0xc0, 0x25, - 0x1d, 0x84, 0x28, 0xea, 0xc7, 0x81, 0x23, 0x31, 0x70, 0xd9, 0x6a, 0xb1, 0xc9, 0xa0, 0x30, 0x49, - 0x26, 0x35, 0x1d, 0x86, 0x7e, 0x14, 0xc4, 0x41, 0x47, 0x16, 0x52, 0xb7, 0xab, 0xef, 0xb3, 0x42, - 0xaa, 0x7d, 0xa2, 0xb3, 0x03, 0xd0, 0x77, 0xdd, 0xea, 0x1d, 0x5a, 0x66, 0x07, 0x20, 0x1f, 0xb1, - 0xbf, 0x35, 0x35, 0x1d, 0x39, 0xd1, 0x46, 0xf2, 0x09, 0x0f, 0xc4, 0x46, 0x69, 0xa0, 0x41, 0x88, - 0xa2, 0x51, 0xdc, 0x15, 0xf2, 0x05, 0x07, 0x6b, 0x5e, 0x48, 0xbd, 0xe6, 0x39, 0x50, 0xec, 0xcc, - 0x15, 0xfc, 0xfa, 0x79, 0x6c, 0x98, 0x77, 0x6a, 0x98, 0x77, 0x69, 0x18, 0x7a, 0x6e, 0x18, 0xfa, - 0x6f, 0x19, 0xba, 0xb5, 0x0c, 0xdd, 0x5b, 0x86, 0x1e, 0x2c, 0x43, 0x47, 0xcb, 0xd0, 0xa3, 0x65, - 0xe8, 0xc9, 0x32, 0xef, 0x62, 0x19, 0xba, 0x39, 0x33, 0xef, 0x78, 0x66, 0xde, 0xe9, 0xcc, 0xbc, - 0x74, 0xe8, 0x2e, 0xfe, 0xe3, 0x25, 0x00, 0x00, 0xff, 0xff, 0xdf, 0x9e, 0x98, 0xf7, 0xb7, 0x01, - 0x00, 0x00, +func init() { proto.RegisterFile("pb/packet.proto", fileDescriptor_packet_dc5a9d1a21ec3142) } + +var fileDescriptor_packet_dc5a9d1a21ec3142 = []byte{ + // 255 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x44, 0xd0, 0xbd, 0x4e, 0xc3, 0x30, + 0x14, 0x05, 0x60, 0xe5, 0xa7, 0xa1, 0xb9, 0x25, 0x02, 0x59, 0x0c, 0x1e, 0x40, 0x58, 0x9d, 0x3c, + 0xc1, 0xc0, 0x23, 0x30, 0x75, 0x43, 0xce, 0x03, 0x58, 0x37, 0xf6, 0x95, 0x6a, 0xa5, 0xe4, 0xcf, + 0x8e, 0x2a, 0xfa, 0x48, 0x3c, 0x25, 0x8a, 0x23, 0xda, 0xed, 0xfa, 0x3b, 0x67, 0x38, 0x32, 0x3c, + 0x0c, 0xcd, 0xfb, 0x80, 0xa6, 0xa5, 0xf0, 0x36, 0x4c, 0x7d, 0xe8, 0x59, 0x3a, 0x34, 0xfb, 0xdf, + 0x14, 0x8a, 0xaf, 0x88, 0xec, 0x15, 0x76, 0x9e, 0xc6, 0x99, 0x3a, 0x43, 0xda, 0x59, 0x9e, 0x88, + 0x44, 0x56, 0x0a, 0xfe, 0xe9, 0x60, 0x19, 0x83, 0xdc, 0x62, 0x40, 0x9e, 0x8a, 0x44, 0xde, 0xab, + 0x78, 0xb3, 0x3d, 0x54, 0x68, 0x5a, 0xed, 0x03, 0x4e, 0x41, 0x7b, 0x1a, 0x79, 0x26, 0x32, 0x59, + 0xa9, 0x1d, 0x9a, 0xb6, 0x5e, 0xac, 0xa6, 0xf1, 0xda, 0xa1, 0x51, 0x9b, 0x7e, 0xee, 0x02, 0xcf, + 0x6f, 0x1d, 0x1a, 0x3f, 0x17, 0x62, 0x2f, 0x00, 0xcd, 0x4f, 0x20, 0xaf, 0x27, 0x42, 0xcb, 0x37, + 0x22, 0x91, 0xb9, 0x2a, 0xa3, 0x28, 0x42, 0xbb, 0xc4, 0xe6, 0xe4, 0xa8, 0x0b, 0xda, 0x59, 0xcf, + 0x0b, 0x91, 0xc9, 0x52, 0x95, 0xab, 0x1c, 0xac, 0x5f, 0xa6, 0x9f, 0x5d, 0x67, 0xfb, 0xb3, 0xf6, + 0xee, 0x42, 0xfc, 0x6e, 0x9d, 0xbe, 0x52, 0xed, 0x2e, 0xc4, 0x1e, 0x21, 0xfb, 0x0e, 0x33, 0xdf, + 0xc6, 0x60, 0x39, 0xd9, 0x13, 0x6c, 0xcc, 0xa9, 0xf7, 0xc4, 0x4b, 0x91, 0xc8, 0xad, 0x5a, 0x1f, + 0xec, 0x19, 0xca, 0x23, 0x76, 0xd6, 0x1f, 0xb1, 0x25, 0x0e, 0x31, 0xb9, 0x41, 0x53, 0xc4, 0x7f, + 0xfb, 0xf8, 0x0b, 0x00, 0x00, 0xff, 0xff, 0x94, 0xb5, 0xa3, 0x8f, 0x4a, 0x01, 0x00, 0x00, } diff --git a/pb/packet.proto b/pb/packet.proto index 029df20..7ff450f 100644 --- a/pb/packet.proto +++ b/pb/packet.proto @@ -2,19 +2,6 @@ syntax = "proto3"; package pb; -import "github.com/gogo/protobuf/gogoproto/gogo.proto"; - -option (gogoproto.gostring_all) = true; -option (gogoproto.goproto_stringer_all) = false; -option (gogoproto.stringer_all) = true; -option (gogoproto.marshaler_all) = true; -option (gogoproto.sizer_all) = true; -option (gogoproto.unmarshaler_all) = true; - -option (gogoproto.testgen_all) = true; -option (gogoproto.equal_all) = true; -option (gogoproto.populate_all) = true; - message Packet { uint32 sequence_id = 1; bytes data = 2; diff --git a/pb/packetpb_test.go b/pb/packetpb_test.go deleted file mode 100644 index aa2198e..0000000 --- a/pb/packetpb_test.go +++ /dev/null @@ -1,169 +0,0 @@ -// Code generated by protoc-gen-gogo. DO NOT EDIT. -// source: pb/packet.proto - -package pb - -import testing "testing" -import math_rand "math/rand" -import time "time" -import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" -import github_com_gogo_protobuf_jsonpb "github.com/gogo/protobuf/jsonpb" -import fmt "fmt" -import go_parser "go/parser" -import proto "github.com/gogo/protobuf/proto" -import math "math" -import _ "github.com/gogo/protobuf/gogoproto" - -// Reference imports to suppress errors if they are not otherwise used. -var _ = proto.Marshal -var _ = fmt.Errorf -var _ = math.Inf - -func TestPacketProto(t *testing.T) { - seed := time.Now().UnixNano() - popr := math_rand.New(math_rand.NewSource(seed)) - p := NewPopulatedPacket(popr, false) - dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) - if err != nil { - t.Fatalf("seed = %d, err = %v", seed, err) - } - msg := &Packet{} - if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { - t.Fatalf("seed = %d, err = %v", seed, err) - } - littlefuzz := make([]byte, len(dAtA)) - copy(littlefuzz, dAtA) - for i := range dAtA { - dAtA[i] = byte(popr.Intn(256)) - } - if !p.Equal(msg) { - t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) - } - if len(littlefuzz) > 0 { - fuzzamount := 100 - for i := 0; i < fuzzamount; i++ { - littlefuzz[popr.Intn(len(littlefuzz))] = byte(popr.Intn(256)) - littlefuzz = append(littlefuzz, byte(popr.Intn(256))) - } - // shouldn't panic - _ = github_com_gogo_protobuf_proto.Unmarshal(littlefuzz, msg) - } -} - -func TestPacketMarshalTo(t *testing.T) { - seed := time.Now().UnixNano() - popr := math_rand.New(math_rand.NewSource(seed)) - p := NewPopulatedPacket(popr, false) - size := p.Size() - dAtA := make([]byte, size) - for i := range dAtA { - dAtA[i] = byte(popr.Intn(256)) - } - _, err := p.MarshalTo(dAtA) - if err != nil { - t.Fatalf("seed = %d, err = %v", seed, err) - } - msg := &Packet{} - if err := github_com_gogo_protobuf_proto.Unmarshal(dAtA, msg); err != nil { - t.Fatalf("seed = %d, err = %v", seed, err) - } - for i := range dAtA { - dAtA[i] = byte(popr.Intn(256)) - } - if !p.Equal(msg) { - t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) - } -} - -func TestPacketJSON(t *testing.T) { - seed := time.Now().UnixNano() - popr := math_rand.New(math_rand.NewSource(seed)) - p := NewPopulatedPacket(popr, true) - marshaler := github_com_gogo_protobuf_jsonpb.Marshaler{} - jsondata, err := marshaler.MarshalToString(p) - if err != nil { - t.Fatalf("seed = %d, err = %v", seed, err) - } - msg := &Packet{} - err = github_com_gogo_protobuf_jsonpb.UnmarshalString(jsondata, msg) - if err != nil { - t.Fatalf("seed = %d, err = %v", seed, err) - } - if !p.Equal(msg) { - t.Fatalf("seed = %d, %#v !Json Equal %#v", seed, msg, p) - } -} -func TestPacketProtoText(t *testing.T) { - seed := time.Now().UnixNano() - popr := math_rand.New(math_rand.NewSource(seed)) - p := NewPopulatedPacket(popr, true) - dAtA := github_com_gogo_protobuf_proto.MarshalTextString(p) - msg := &Packet{} - if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { - t.Fatalf("seed = %d, err = %v", seed, err) - } - if !p.Equal(msg) { - t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) - } -} - -func TestPacketProtoCompactText(t *testing.T) { - seed := time.Now().UnixNano() - popr := math_rand.New(math_rand.NewSource(seed)) - p := NewPopulatedPacket(popr, true) - dAtA := github_com_gogo_protobuf_proto.CompactTextString(p) - msg := &Packet{} - if err := github_com_gogo_protobuf_proto.UnmarshalText(dAtA, msg); err != nil { - t.Fatalf("seed = %d, err = %v", seed, err) - } - if !p.Equal(msg) { - t.Fatalf("seed = %d, %#v !Proto %#v", seed, msg, p) - } -} - -func TestPacketGoString(t *testing.T) { - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) - p := NewPopulatedPacket(popr, false) - s1 := p.GoString() - s2 := fmt.Sprintf("%#v", p) - if s1 != s2 { - t.Fatalf("GoString want %v got %v", s1, s2) - } - _, err := go_parser.ParseExpr(s1) - if err != nil { - t.Fatal(err) - } -} -func TestPacketSize(t *testing.T) { - seed := time.Now().UnixNano() - popr := math_rand.New(math_rand.NewSource(seed)) - p := NewPopulatedPacket(popr, true) - size2 := github_com_gogo_protobuf_proto.Size(p) - dAtA, err := github_com_gogo_protobuf_proto.Marshal(p) - if err != nil { - t.Fatalf("seed = %d, err = %v", seed, err) - } - size := p.Size() - if len(dAtA) != size { - t.Errorf("seed = %d, size %v != marshalled size %v", seed, size, len(dAtA)) - } - if size2 != size { - t.Errorf("seed = %d, size %v != before marshal proto.Size %v", seed, size, size2) - } - size3 := github_com_gogo_protobuf_proto.Size(p) - if size3 != size { - t.Errorf("seed = %d, size %v != after marshal proto.Size %v", seed, size, size3) - } -} - -func TestPacketStringer(t *testing.T) { - popr := math_rand.New(math_rand.NewSource(time.Now().UnixNano())) - p := NewPopulatedPacket(popr, false) - s1 := p.String() - s2 := fmt.Sprintf("%v", p) - if s1 != s2 { - t.Fatalf("String want %v got %v", s1, s2) - } -} - -//These tests are generated by github.com/gogo/protobuf/plugin/testgen diff --git a/session.go b/session.go index f533cd8..6a4b73c 100644 --- a/session.go +++ b/session.go @@ -9,7 +9,7 @@ import ( "sync" "time" - "github.com/gogo/protobuf/proto" + "github.com/golang/protobuf/proto" "github.com/nknorg/ncp-go/pb" )