diff --git a/benchmarks/codec_test.go b/benchmarks/codec_test.go new file mode 100644 index 000000000..35dc591ea --- /dev/null +++ b/benchmarks/codec_test.go @@ -0,0 +1,110 @@ +package benchmarks + +import ( + "testing" + + "github.com/tendermint/go-crypto" + "github.com/tendermint/go-p2p" + "github.com/tendermint/go-wire" + proto "github.com/tendermint/tendermint/benchmarks/proto" + ctypes "github.com/tendermint/tendermint/rpc/core/types" +) + +func BenchmarkEncodeStatusWire(b *testing.B) { + b.StopTimer() + pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) + status := &ctypes.ResultStatus{ + NodeInfo: &p2p.NodeInfo{ + PubKey: pubKey, + Moniker: "SOMENAME", + Network: "SOMENAME", + RemoteAddr: "SOMEADDR", + ListenAddr: "SOMEADDR", + Version: "SOMEVER", + Other: []string{"SOMESTRING", "OTHERSTRING"}, + }, + PubKey: pubKey, + LatestBlockHash: []byte("SOMEBYTES"), + LatestBlockHeight: 123, + LatestBlockTime: 1234, + } + b.StartTimer() + + counter := 0 + for i := 0; i < b.N; i++ { + jsonBytes := wire.JSONBytes(status) + counter += len(jsonBytes) + } + +} + +func BenchmarkEncodeNodeInfoWire(b *testing.B) { + b.StopTimer() + pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) + nodeInfo := &p2p.NodeInfo{ + PubKey: pubKey, + Moniker: "SOMENAME", + Network: "SOMENAME", + RemoteAddr: "SOMEADDR", + ListenAddr: "SOMEADDR", + Version: "SOMEVER", + Other: []string{"SOMESTRING", "OTHERSTRING"}, + } + b.StartTimer() + + counter := 0 + for i := 0; i < b.N; i++ { + jsonBytes := wire.JSONBytes(nodeInfo) + counter += len(jsonBytes) + } +} + +func BenchmarkEncodeNodeInfoBinary(b *testing.B) { + b.StopTimer() + pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) + nodeInfo := &p2p.NodeInfo{ + PubKey: pubKey, + Moniker: "SOMENAME", + Network: "SOMENAME", + RemoteAddr: "SOMEADDR", + ListenAddr: "SOMEADDR", + Version: "SOMEVER", + Other: []string{"SOMESTRING", "OTHERSTRING"}, + } + b.StartTimer() + + counter := 0 + for i := 0; i < b.N; i++ { + jsonBytes := wire.BinaryBytes(nodeInfo) + counter += len(jsonBytes) + } + +} + +func BenchmarkEncodeNodeInfoProto(b *testing.B) { + b.StopTimer() + pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) + pubKey2 := &proto.PubKey{Ed25519: &proto.PubKeyEd25519{Bytes: pubKey[:]}} + nodeInfo := &proto.NodeInfo{ + PubKey: pubKey2, + Moniker: "SOMENAME", + Network: "SOMENAME", + RemoteAddr: "SOMEADDR", + ListenAddr: "SOMEADDR", + Version: "SOMEVER", + Other: []string{"SOMESTRING", "OTHERSTRING"}, + } + b.StartTimer() + + counter := 0 + for i := 0; i < b.N; i++ { + bytes, err := nodeInfo.Marshal() + if err != nil { + b.Fatal(err) + return + } + //jsonBytes := wire.JSONBytes(nodeInfo) + counter += len(bytes) + } + +} diff --git a/benchmarks/proto/README b/benchmarks/proto/README new file mode 100644 index 000000000..87ece2576 --- /dev/null +++ b/benchmarks/proto/README @@ -0,0 +1,2 @@ +Doing some protobuf tests here. +Using gogoprotobuf. diff --git a/benchmarks/proto/test.pb.go b/benchmarks/proto/test.pb.go new file mode 100644 index 000000000..6539cae32 --- /dev/null +++ b/benchmarks/proto/test.pb.go @@ -0,0 +1,1503 @@ +// Code generated by protoc-gen-gogo. +// source: test.proto +// DO NOT EDIT! + +/* + Package test is a generated protocol buffer package. + + It is generated from these files: + test.proto + + It has these top-level messages: + ResultStatus + NodeInfo + PubKey + PubKeyEd25519 +*/ +package test + +import proto "github.com/gogo/protobuf/proto" +import fmt "fmt" +import math "math" + +import bytes "bytes" + +import strings "strings" +import github_com_gogo_protobuf_proto "github.com/gogo/protobuf/proto" +import sort "sort" +import strconv "strconv" +import reflect "reflect" + +import io "io" + +// Reference imports to suppress errors if they are not otherwise used. +var _ = proto.Marshal +var _ = fmt.Errorf +var _ = math.Inf + +type ResultStatus struct { + NodeInfo *NodeInfo `protobuf:"bytes,1,opt,name=nodeInfo" json:"nodeInfo,omitempty"` + PubKey *PubKey `protobuf:"bytes,2,req,name=pubKey" json:"pubKey,omitempty"` + LatestBlockHash []byte `protobuf:"bytes,3,req,name=latestBlockHash" json:"latestBlockHash"` + LatestBlockHeight int64 `protobuf:"varint,4,req,name=latestBlockHeight" json:"latestBlockHeight"` + LatestBlocktime int64 `protobuf:"varint,5,req,name=latestBlocktime" json:"latestBlocktime"` +} + +func (m *ResultStatus) Reset() { *m = ResultStatus{} } +func (*ResultStatus) ProtoMessage() {} + +func (m *ResultStatus) GetNodeInfo() *NodeInfo { + if m != nil { + return m.NodeInfo + } + return nil +} + +func (m *ResultStatus) GetPubKey() *PubKey { + if m != nil { + return m.PubKey + } + return nil +} + +func (m *ResultStatus) GetLatestBlockHash() []byte { + if m != nil { + return m.LatestBlockHash + } + return nil +} + +func (m *ResultStatus) GetLatestBlockHeight() int64 { + if m != nil { + return m.LatestBlockHeight + } + return 0 +} + +func (m *ResultStatus) GetLatestBlocktime() int64 { + if m != nil { + return m.LatestBlocktime + } + return 0 +} + +type NodeInfo struct { + PubKey *PubKey `protobuf:"bytes,1,req,name=pubKey" json:"pubKey,omitempty"` + Moniker string `protobuf:"bytes,2,req,name=moniker" json:"moniker"` + Network string `protobuf:"bytes,3,req,name=network" json:"network"` + RemoteAddr string `protobuf:"bytes,4,req,name=remoteAddr" json:"remoteAddr"` + ListenAddr string `protobuf:"bytes,5,req,name=listenAddr" json:"listenAddr"` + Version string `protobuf:"bytes,6,req,name=version" json:"version"` + Other []string `protobuf:"bytes,7,rep,name=other" json:"other,omitempty"` +} + +func (m *NodeInfo) Reset() { *m = NodeInfo{} } +func (*NodeInfo) ProtoMessage() {} + +func (m *NodeInfo) GetPubKey() *PubKey { + if m != nil { + return m.PubKey + } + return nil +} + +func (m *NodeInfo) GetMoniker() string { + if m != nil { + return m.Moniker + } + return "" +} + +func (m *NodeInfo) GetNetwork() string { + if m != nil { + return m.Network + } + return "" +} + +func (m *NodeInfo) GetRemoteAddr() string { + if m != nil { + return m.RemoteAddr + } + return "" +} + +func (m *NodeInfo) GetListenAddr() string { + if m != nil { + return m.ListenAddr + } + return "" +} + +func (m *NodeInfo) GetVersion() string { + if m != nil { + return m.Version + } + return "" +} + +func (m *NodeInfo) GetOther() []string { + if m != nil { + return m.Other + } + return nil +} + +type PubKey struct { + Ed25519 *PubKeyEd25519 `protobuf:"bytes,1,opt,name=ed25519" json:"ed25519,omitempty"` +} + +func (m *PubKey) Reset() { *m = PubKey{} } +func (*PubKey) ProtoMessage() {} + +func (m *PubKey) GetEd25519() *PubKeyEd25519 { + if m != nil { + return m.Ed25519 + } + return nil +} + +type PubKeyEd25519 struct { + Bytes []byte `protobuf:"bytes,1,req,name=bytes" json:"bytes"` +} + +func (m *PubKeyEd25519) Reset() { *m = PubKeyEd25519{} } +func (*PubKeyEd25519) ProtoMessage() {} + +func (m *PubKeyEd25519) GetBytes() []byte { + if m != nil { + return m.Bytes + } + return nil +} + +func init() { + proto.RegisterType((*ResultStatus)(nil), "ResultStatus") + proto.RegisterType((*NodeInfo)(nil), "NodeInfo") + proto.RegisterType((*PubKey)(nil), "PubKey") + proto.RegisterType((*PubKeyEd25519)(nil), "PubKeyEd25519") +} +func (this *ResultStatus) Equal(that interface{}) bool { + if that == nil { + if this == nil { + return true + } + return false + } + + that1, ok := that.(*ResultStatus) + if !ok { + that2, ok := that.(ResultStatus) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + if this == nil { + return true + } + return false + } else if this == nil { + return false + } + if !this.NodeInfo.Equal(that1.NodeInfo) { + return false + } + if !this.PubKey.Equal(that1.PubKey) { + return false + } + if !bytes.Equal(this.LatestBlockHash, that1.LatestBlockHash) { + return false + } + if this.LatestBlockHeight != that1.LatestBlockHeight { + return false + } + if this.LatestBlocktime != that1.LatestBlocktime { + return false + } + return true +} +func (this *NodeInfo) Equal(that interface{}) bool { + if that == nil { + if this == nil { + return true + } + return false + } + + that1, ok := that.(*NodeInfo) + if !ok { + that2, ok := that.(NodeInfo) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + if this == nil { + return true + } + return false + } else if this == nil { + return false + } + if !this.PubKey.Equal(that1.PubKey) { + return false + } + if this.Moniker != that1.Moniker { + return false + } + if this.Network != that1.Network { + return false + } + if this.RemoteAddr != that1.RemoteAddr { + return false + } + if this.ListenAddr != that1.ListenAddr { + return false + } + if this.Version != that1.Version { + return false + } + if len(this.Other) != len(that1.Other) { + return false + } + for i := range this.Other { + if this.Other[i] != that1.Other[i] { + return false + } + } + return true +} +func (this *PubKey) Equal(that interface{}) bool { + if that == nil { + if this == nil { + return true + } + return false + } + + that1, ok := that.(*PubKey) + if !ok { + that2, ok := that.(PubKey) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + if this == nil { + return true + } + return false + } else if this == nil { + return false + } + if !this.Ed25519.Equal(that1.Ed25519) { + return false + } + return true +} +func (this *PubKeyEd25519) Equal(that interface{}) bool { + if that == nil { + if this == nil { + return true + } + return false + } + + that1, ok := that.(*PubKeyEd25519) + if !ok { + that2, ok := that.(PubKeyEd25519) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + if this == nil { + return true + } + return false + } else if this == nil { + return false + } + if !bytes.Equal(this.Bytes, that1.Bytes) { + return false + } + return true +} +func (this *ResultStatus) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 9) + s = append(s, "&test.ResultStatus{") + if this.NodeInfo != nil { + s = append(s, "NodeInfo: "+fmt.Sprintf("%#v", this.NodeInfo)+",\n") + } + if this.PubKey != nil { + s = append(s, "PubKey: "+fmt.Sprintf("%#v", this.PubKey)+",\n") + } + s = append(s, "LatestBlockHash: "+fmt.Sprintf("%#v", this.LatestBlockHash)+",\n") + s = append(s, "LatestBlockHeight: "+fmt.Sprintf("%#v", this.LatestBlockHeight)+",\n") + s = append(s, "LatestBlocktime: "+fmt.Sprintf("%#v", this.LatestBlocktime)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func (this *NodeInfo) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 11) + s = append(s, "&test.NodeInfo{") + if this.PubKey != nil { + s = append(s, "PubKey: "+fmt.Sprintf("%#v", this.PubKey)+",\n") + } + s = append(s, "Moniker: "+fmt.Sprintf("%#v", this.Moniker)+",\n") + s = append(s, "Network: "+fmt.Sprintf("%#v", this.Network)+",\n") + s = append(s, "RemoteAddr: "+fmt.Sprintf("%#v", this.RemoteAddr)+",\n") + s = append(s, "ListenAddr: "+fmt.Sprintf("%#v", this.ListenAddr)+",\n") + s = append(s, "Version: "+fmt.Sprintf("%#v", this.Version)+",\n") + if this.Other != nil { + s = append(s, "Other: "+fmt.Sprintf("%#v", this.Other)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *PubKey) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&test.PubKey{") + if this.Ed25519 != nil { + s = append(s, "Ed25519: "+fmt.Sprintf("%#v", this.Ed25519)+",\n") + } + s = append(s, "}") + return strings.Join(s, "") +} +func (this *PubKeyEd25519) GoString() string { + if this == nil { + return "nil" + } + s := make([]string, 0, 5) + s = append(s, "&test.PubKeyEd25519{") + s = append(s, "Bytes: "+fmt.Sprintf("%#v", this.Bytes)+",\n") + s = append(s, "}") + return strings.Join(s, "") +} +func valueToGoStringTest(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 extensionToGoStringTest(e map[int32]github_com_gogo_protobuf_proto.Extension) string { + if e == nil { + return "nil" + } + s := "map[int32]proto.Extension{" + keys := make([]int, 0, len(e)) + for k := range e { + keys = append(keys, int(k)) + } + sort.Ints(keys) + ss := []string{} + for _, k := range keys { + ss = append(ss, strconv.Itoa(k)+": "+e[int32(k)].GoString()) + } + s += strings.Join(ss, ",") + "}" + return s +} +func (m *ResultStatus) 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 *ResultStatus) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.NodeInfo != nil { + data[i] = 0xa + i++ + i = encodeVarintTest(data, i, uint64(m.NodeInfo.Size())) + n1, err := m.NodeInfo.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n1 + } + if m.PubKey == nil { + return 0, github_com_gogo_protobuf_proto.NewRequiredNotSetError("pubKey") + } else { + data[i] = 0x12 + i++ + i = encodeVarintTest(data, i, uint64(m.PubKey.Size())) + n2, err := m.PubKey.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n2 + } + if m.LatestBlockHash != nil { + data[i] = 0x1a + i++ + i = encodeVarintTest(data, i, uint64(len(m.LatestBlockHash))) + i += copy(data[i:], m.LatestBlockHash) + } + data[i] = 0x20 + i++ + i = encodeVarintTest(data, i, uint64(m.LatestBlockHeight)) + data[i] = 0x28 + i++ + i = encodeVarintTest(data, i, uint64(m.LatestBlocktime)) + return i, nil +} + +func (m *NodeInfo) 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 *NodeInfo) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.PubKey == nil { + return 0, github_com_gogo_protobuf_proto.NewRequiredNotSetError("pubKey") + } else { + data[i] = 0xa + i++ + i = encodeVarintTest(data, i, uint64(m.PubKey.Size())) + n3, err := m.PubKey.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n3 + } + data[i] = 0x12 + i++ + i = encodeVarintTest(data, i, uint64(len(m.Moniker))) + i += copy(data[i:], m.Moniker) + data[i] = 0x1a + i++ + i = encodeVarintTest(data, i, uint64(len(m.Network))) + i += copy(data[i:], m.Network) + data[i] = 0x22 + i++ + i = encodeVarintTest(data, i, uint64(len(m.RemoteAddr))) + i += copy(data[i:], m.RemoteAddr) + data[i] = 0x2a + i++ + i = encodeVarintTest(data, i, uint64(len(m.ListenAddr))) + i += copy(data[i:], m.ListenAddr) + data[i] = 0x32 + i++ + i = encodeVarintTest(data, i, uint64(len(m.Version))) + i += copy(data[i:], m.Version) + if len(m.Other) > 0 { + for _, s := range m.Other { + data[i] = 0x3a + 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) + } + } + return i, nil +} + +func (m *PubKey) 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 *PubKey) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Ed25519 != nil { + data[i] = 0xa + i++ + i = encodeVarintTest(data, i, uint64(m.Ed25519.Size())) + n4, err := m.Ed25519.MarshalTo(data[i:]) + if err != nil { + return 0, err + } + i += n4 + } + return i, nil +} + +func (m *PubKeyEd25519) 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 *PubKeyEd25519) MarshalTo(data []byte) (int, error) { + var i int + _ = i + var l int + _ = l + if m.Bytes != nil { + data[i] = 0xa + i++ + i = encodeVarintTest(data, i, uint64(len(m.Bytes))) + i += copy(data[i:], m.Bytes) + } + return i, nil +} + +func encodeFixed64Test(data []byte, offset int, v uint64) int { + data[offset] = uint8(v) + data[offset+1] = uint8(v >> 8) + data[offset+2] = uint8(v >> 16) + data[offset+3] = uint8(v >> 24) + data[offset+4] = uint8(v >> 32) + data[offset+5] = uint8(v >> 40) + data[offset+6] = uint8(v >> 48) + data[offset+7] = uint8(v >> 56) + return offset + 8 +} +func encodeFixed32Test(data []byte, offset int, v uint32) int { + data[offset] = uint8(v) + data[offset+1] = uint8(v >> 8) + data[offset+2] = uint8(v >> 16) + data[offset+3] = uint8(v >> 24) + return offset + 4 +} +func encodeVarintTest(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 (m *ResultStatus) Size() (n int) { + var l int + _ = l + if m.NodeInfo != nil { + l = m.NodeInfo.Size() + n += 1 + l + sovTest(uint64(l)) + } + if m.PubKey != nil { + l = m.PubKey.Size() + n += 1 + l + sovTest(uint64(l)) + } + if m.LatestBlockHash != nil { + l = len(m.LatestBlockHash) + n += 1 + l + sovTest(uint64(l)) + } + n += 1 + sovTest(uint64(m.LatestBlockHeight)) + n += 1 + sovTest(uint64(m.LatestBlocktime)) + return n +} + +func (m *NodeInfo) Size() (n int) { + var l int + _ = l + if m.PubKey != nil { + l = m.PubKey.Size() + n += 1 + l + sovTest(uint64(l)) + } + l = len(m.Moniker) + n += 1 + l + sovTest(uint64(l)) + l = len(m.Network) + n += 1 + l + sovTest(uint64(l)) + l = len(m.RemoteAddr) + n += 1 + l + sovTest(uint64(l)) + l = len(m.ListenAddr) + n += 1 + l + sovTest(uint64(l)) + l = len(m.Version) + n += 1 + l + sovTest(uint64(l)) + if len(m.Other) > 0 { + for _, s := range m.Other { + l = len(s) + n += 1 + l + sovTest(uint64(l)) + } + } + return n +} + +func (m *PubKey) Size() (n int) { + var l int + _ = l + if m.Ed25519 != nil { + l = m.Ed25519.Size() + n += 1 + l + sovTest(uint64(l)) + } + return n +} + +func (m *PubKeyEd25519) Size() (n int) { + var l int + _ = l + if m.Bytes != nil { + l = len(m.Bytes) + n += 1 + l + sovTest(uint64(l)) + } + return n +} + +func sovTest(x uint64) (n int) { + for { + n++ + x >>= 7 + if x == 0 { + break + } + } + return n +} +func sozTest(x uint64) (n int) { + return sovTest(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (this *ResultStatus) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&ResultStatus{`, + `NodeInfo:` + strings.Replace(fmt.Sprintf("%v", this.NodeInfo), "NodeInfo", "NodeInfo", 1) + `,`, + `PubKey:` + strings.Replace(fmt.Sprintf("%v", this.PubKey), "PubKey", "PubKey", 1) + `,`, + `LatestBlockHash:` + fmt.Sprintf("%v", this.LatestBlockHash) + `,`, + `LatestBlockHeight:` + fmt.Sprintf("%v", this.LatestBlockHeight) + `,`, + `LatestBlocktime:` + fmt.Sprintf("%v", this.LatestBlocktime) + `,`, + `}`, + }, "") + return s +} +func (this *NodeInfo) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&NodeInfo{`, + `PubKey:` + strings.Replace(fmt.Sprintf("%v", this.PubKey), "PubKey", "PubKey", 1) + `,`, + `Moniker:` + fmt.Sprintf("%v", this.Moniker) + `,`, + `Network:` + fmt.Sprintf("%v", this.Network) + `,`, + `RemoteAddr:` + fmt.Sprintf("%v", this.RemoteAddr) + `,`, + `ListenAddr:` + fmt.Sprintf("%v", this.ListenAddr) + `,`, + `Version:` + fmt.Sprintf("%v", this.Version) + `,`, + `Other:` + fmt.Sprintf("%v", this.Other) + `,`, + `}`, + }, "") + return s +} +func (this *PubKey) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&PubKey{`, + `Ed25519:` + strings.Replace(fmt.Sprintf("%v", this.Ed25519), "PubKeyEd25519", "PubKeyEd25519", 1) + `,`, + `}`, + }, "") + return s +} +func (this *PubKeyEd25519) String() string { + if this == nil { + return "nil" + } + s := strings.Join([]string{`&PubKeyEd25519{`, + `Bytes:` + fmt.Sprintf("%v", this.Bytes) + `,`, + `}`, + }, "") + return s +} +func valueToStringTest(v interface{}) string { + rv := reflect.ValueOf(v) + if rv.IsNil() { + return "nil" + } + pv := reflect.Indirect(rv).Interface() + return fmt.Sprintf("*%v", pv) +} +func (m *ResultStatus) Unmarshal(data []byte) error { + var hasFields [1]uint64 + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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: ResultStatus: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: ResultStatus: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field NodeInfo", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.NodeInfo == nil { + m.NodeInfo = &NodeInfo{} + } + if err := m.NodeInfo.Unmarshal(data[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PubKey == nil { + m.PubKey = &PubKey{} + } + if err := m.PubKey.Unmarshal(data[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + hasFields[0] |= uint64(0x00000001) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LatestBlockHash", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + byteLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + byteLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LatestBlockHash = append([]byte{}, data[iNdEx:postIndex]...) + iNdEx = postIndex + hasFields[0] |= uint64(0x00000002) + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LatestBlockHeight", wireType) + } + m.LatestBlockHeight = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + m.LatestBlockHeight |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + hasFields[0] |= uint64(0x00000004) + case 5: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field LatestBlocktime", wireType) + } + m.LatestBlocktime = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + m.LatestBlocktime |= (int64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + hasFields[0] |= uint64(0x00000008) + default: + iNdEx = preIndex + skippy, err := skipTest(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + if hasFields[0]&uint64(0x00000001) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("pubKey") + } + if hasFields[0]&uint64(0x00000002) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("latestBlockHash") + } + if hasFields[0]&uint64(0x00000004) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("latestBlockHeight") + } + if hasFields[0]&uint64(0x00000008) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("latestBlocktime") + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *NodeInfo) Unmarshal(data []byte) error { + var hasFields [1]uint64 + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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: NodeInfo: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: NodeInfo: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field PubKey", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.PubKey == nil { + m.PubKey = &PubKey{} + } + if err := m.PubKey.Unmarshal(data[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + hasFields[0] |= uint64(0x00000001) + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Moniker", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Moniker = string(data[iNdEx:postIndex]) + iNdEx = postIndex + hasFields[0] |= uint64(0x00000002) + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Network", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Network = string(data[iNdEx:postIndex]) + iNdEx = postIndex + hasFields[0] |= uint64(0x00000004) + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field RemoteAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.RemoteAddr = string(data[iNdEx:postIndex]) + iNdEx = postIndex + hasFields[0] |= uint64(0x00000008) + case 5: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field ListenAddr", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.ListenAddr = string(data[iNdEx:postIndex]) + iNdEx = postIndex + hasFields[0] |= uint64(0x00000010) + case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Version", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Version = string(data[iNdEx:postIndex]) + iNdEx = postIndex + hasFields[0] |= uint64(0x00000020) + case 7: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Other", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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 ErrInvalidLengthTest + } + postIndex := iNdEx + intStringLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Other = append(m.Other, string(data[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + if hasFields[0]&uint64(0x00000001) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("pubKey") + } + if hasFields[0]&uint64(0x00000002) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("moniker") + } + if hasFields[0]&uint64(0x00000004) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("network") + } + if hasFields[0]&uint64(0x00000008) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("remoteAddr") + } + if hasFields[0]&uint64(0x00000010) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("listenAddr") + } + if hasFields[0]&uint64(0x00000020) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("version") + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PubKey) 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 ErrIntOverflowTest + } + 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: PubKey: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PubKey: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Ed25519", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + msglen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + msglen + if postIndex > l { + return io.ErrUnexpectedEOF + } + if m.Ed25519 == nil { + m.Ed25519 = &PubKeyEd25519{} + } + if err := m.Ed25519.Unmarshal(data[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipTest(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *PubKeyEd25519) Unmarshal(data []byte) error { + var hasFields [1]uint64 + l := len(data) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + 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: PubKeyEd25519: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: PubKeyEd25519: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Bytes", wireType) + } + var byteLen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowTest + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := data[iNdEx] + iNdEx++ + byteLen |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if byteLen < 0 { + return ErrInvalidLengthTest + } + postIndex := iNdEx + byteLen + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Bytes = append([]byte{}, data[iNdEx:postIndex]...) + iNdEx = postIndex + hasFields[0] |= uint64(0x00000001) + default: + iNdEx = preIndex + skippy, err := skipTest(data[iNdEx:]) + if err != nil { + return err + } + if skippy < 0 { + return ErrInvalidLengthTest + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + if hasFields[0]&uint64(0x00000001) == 0 { + return github_com_gogo_protobuf_proto.NewRequiredNotSetError("bytes") + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipTest(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, ErrIntOverflowTest + } + 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, ErrIntOverflowTest + } + 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, ErrIntOverflowTest + } + 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, ErrInvalidLengthTest + } + return iNdEx, nil + case 3: + for { + var innerWire uint64 + var start int = iNdEx + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowTest + } + 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 := skipTest(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 ( + ErrInvalidLengthTest = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowTest = fmt.Errorf("proto: integer overflow") +) diff --git a/benchmarks/proto/test.proto b/benchmarks/proto/test.proto new file mode 100644 index 000000000..d1a1c94d7 --- /dev/null +++ b/benchmarks/proto/test.proto @@ -0,0 +1,25 @@ +message ResultStatus { + optional NodeInfo nodeInfo = 1; + required PubKey pubKey = 2; + required bytes latestBlockHash = 3; + required int64 latestBlockHeight = 4; + required int64 latestBlocktime = 5; +} + +message NodeInfo { + required PubKey pubKey = 1; + required string moniker = 2; + required string network = 3; + required string remoteAddr = 4; + required string listenAddr = 5; + required string version = 6; + repeated string other = 7; +} + +message PubKey { + optional PubKeyEd25519 ed25519 = 1; +} + +message PubKeyEd25519 { + required bytes bytes = 1; +} diff --git a/benchmarks/wire_test.go b/benchmarks/wire_test.go deleted file mode 100644 index 7da8a7f71..000000000 --- a/benchmarks/wire_test.go +++ /dev/null @@ -1,60 +0,0 @@ -package benchmarks - -import ( - "testing" - - "github.com/tendermint/go-crypto" - "github.com/tendermint/go-p2p" - "github.com/tendermint/go-wire" - ctypes "github.com/tendermint/tendermint/rpc/core/types" -) - -func BenchmarkEncodeStatus(b *testing.B) { - b.StopTimer() - pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) - status := &ctypes.ResultStatus{ - NodeInfo: &p2p.NodeInfo{ - PubKey: pubKey, - Moniker: "SOMENAME", - Network: "SOMENAME", - RemoteAddr: "SOMEADDR", - ListenAddr: "SOMEADDR", - Version: "SOMEVER", - Other: []string{"SOMESTRING", "OTHERSTRING"}, - }, - PubKey: pubKey, - LatestBlockHash: []byte("SOMEBYTES"), - LatestBlockHeight: 123, - LatestBlockTime: 1234, - } - b.StartTimer() - - counter := 0 - for i := 0; i < b.N; i++ { - jsonBytes := wire.JSONBytes(status) - counter += len(jsonBytes) - } - -} - -func BenchmarkEncodeNodeInfo(b *testing.B) { - b.StopTimer() - pubKey := crypto.GenPrivKeyEd25519().PubKey().(crypto.PubKeyEd25519) - nodeInfo := &p2p.NodeInfo{ - PubKey: pubKey, - Moniker: "SOMENAME", - Network: "SOMENAME", - RemoteAddr: "SOMEADDR", - ListenAddr: "SOMEADDR", - Version: "SOMEVER", - Other: []string{"SOMESTRING", "OTHERSTRING"}, - } - b.StartTimer() - - counter := 0 - for i := 0; i < b.N; i++ { - jsonBytes := wire.JSONBytes(nodeInfo) - counter += len(jsonBytes) - } - -}