Commit ed584b1e authored by Brian Tiger Chow's avatar Brian Tiger Chow

refactor(bitswap) mv proto PBMessage -> Message

parent ae109ad1
...@@ -9,7 +9,7 @@ It is generated from these files: ...@@ -9,7 +9,7 @@ It is generated from these files:
message.proto message.proto
It has these top-level messages: It has these top-level messages:
PBMessage Message
*/ */
package bitswap_message_pb package bitswap_message_pb
...@@ -20,24 +20,24 @@ import math "math" ...@@ -20,24 +20,24 @@ import math "math"
var _ = proto.Marshal var _ = proto.Marshal
var _ = math.Inf var _ = math.Inf
type PBMessage struct { type Message struct {
Wantlist []string `protobuf:"bytes,1,rep,name=wantlist" json:"wantlist,omitempty"` Wantlist []string `protobuf:"bytes,1,rep,name=wantlist" json:"wantlist,omitempty"`
Blocks [][]byte `protobuf:"bytes,2,rep,name=blocks" json:"blocks,omitempty"` Blocks [][]byte `protobuf:"bytes,2,rep,name=blocks" json:"blocks,omitempty"`
XXX_unrecognized []byte `json:"-"` XXX_unrecognized []byte `json:"-"`
} }
func (m *PBMessage) Reset() { *m = PBMessage{} } func (m *Message) Reset() { *m = Message{} }
func (m *PBMessage) String() string { return proto.CompactTextString(m) } func (m *Message) String() string { return proto.CompactTextString(m) }
func (*PBMessage) ProtoMessage() {} func (*Message) ProtoMessage() {}
func (m *PBMessage) GetWantlist() []string { func (m *Message) GetWantlist() []string {
if m != nil { if m != nil {
return m.Wantlist return m.Wantlist
} }
return nil return nil
} }
func (m *PBMessage) GetBlocks() [][]byte { func (m *Message) GetBlocks() [][]byte {
if m != nil { if m != nil {
return m.Blocks return m.Blocks
} }
......
package bitswap.message.pb; package bitswap.message.pb;
message PBMessage { message Message {
repeated string wantlist = 1; repeated string wantlist = 1;
repeated bytes blocks = 2; repeated bytes blocks = 2;
} }
...@@ -22,7 +22,7 @@ type BitSwapMessage interface { ...@@ -22,7 +22,7 @@ type BitSwapMessage interface {
} }
type Exportable interface { type Exportable interface {
ToProto() *pb.PBMessage ToProto() *pb.Message
ToNet(p peer.Peer) (nm.NetMessage, error) ToNet(p peer.Peer) (nm.NetMessage, error)
} }
...@@ -36,7 +36,7 @@ func New() *message { ...@@ -36,7 +36,7 @@ func New() *message {
return new(message) return new(message)
} }
func newMessageFromProto(pbm pb.PBMessage) BitSwapMessage { func newMessageFromProto(pbm pb.Message) BitSwapMessage {
m := New() m := New()
for _, s := range pbm.GetWantlist() { for _, s := range pbm.GetWantlist() {
m.AppendWanted(u.Key(s)) m.AppendWanted(u.Key(s))
...@@ -67,7 +67,7 @@ func (m *message) AppendBlock(b blocks.Block) { ...@@ -67,7 +67,7 @@ func (m *message) AppendBlock(b blocks.Block) {
} }
func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) { func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) {
pb := new(pb.PBMessage) pb := new(pb.Message)
if err := proto.Unmarshal(nmsg.Data(), pb); err != nil { if err := proto.Unmarshal(nmsg.Data(), pb); err != nil {
return nil, err return nil, err
} }
...@@ -75,8 +75,8 @@ func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) { ...@@ -75,8 +75,8 @@ func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) {
return m, nil return m, nil
} }
func (m *message) ToProto() *pb.PBMessage { func (m *message) ToProto() *pb.Message {
pb := new(pb.PBMessage) pb := new(pb.Message)
for _, k := range m.Wantlist() { for _, k := range m.Wantlist() {
pb.Wantlist = append(pb.Wantlist, string(k)) pb.Wantlist = append(pb.Wantlist, string(k))
} }
......
...@@ -22,7 +22,7 @@ func TestAppendWanted(t *testing.T) { ...@@ -22,7 +22,7 @@ func TestAppendWanted(t *testing.T) {
func TestNewMessageFromProto(t *testing.T) { func TestNewMessageFromProto(t *testing.T) {
const str = "a_key" const str = "a_key"
protoMessage := new(pb.PBMessage) protoMessage := new(pb.Message)
protoMessage.Wantlist = []string{string(str)} protoMessage.Wantlist = []string{string(str)}
if !contains(protoMessage.Wantlist, str) { if !contains(protoMessage.Wantlist, str) {
t.Fail() t.Fail()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment