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:
message.proto
It has these top-level messages:
PBMessage
Message
*/
package bitswap_message_pb
......@@ -20,24 +20,24 @@ import math "math"
var _ = proto.Marshal
var _ = math.Inf
type PBMessage struct {
type Message struct {
Wantlist []string `protobuf:"bytes,1,rep,name=wantlist" json:"wantlist,omitempty"`
Blocks [][]byte `protobuf:"bytes,2,rep,name=blocks" json:"blocks,omitempty"`
XXX_unrecognized []byte `json:"-"`
}
func (m *PBMessage) Reset() { *m = PBMessage{} }
func (m *PBMessage) String() string { return proto.CompactTextString(m) }
func (*PBMessage) ProtoMessage() {}
func (m *Message) Reset() { *m = Message{} }
func (m *Message) String() string { return proto.CompactTextString(m) }
func (*Message) ProtoMessage() {}
func (m *PBMessage) GetWantlist() []string {
func (m *Message) GetWantlist() []string {
if m != nil {
return m.Wantlist
}
return nil
}
func (m *PBMessage) GetBlocks() [][]byte {
func (m *Message) GetBlocks() [][]byte {
if m != nil {
return m.Blocks
}
......
package bitswap.message.pb;
message PBMessage {
message Message {
repeated string wantlist = 1;
repeated bytes blocks = 2;
}
......@@ -22,7 +22,7 @@ type BitSwapMessage interface {
}
type Exportable interface {
ToProto() *pb.PBMessage
ToProto() *pb.Message
ToNet(p peer.Peer) (nm.NetMessage, error)
}
......@@ -36,7 +36,7 @@ func New() *message {
return new(message)
}
func newMessageFromProto(pbm pb.PBMessage) BitSwapMessage {
func newMessageFromProto(pbm pb.Message) BitSwapMessage {
m := New()
for _, s := range pbm.GetWantlist() {
m.AppendWanted(u.Key(s))
......@@ -67,7 +67,7 @@ func (m *message) AppendBlock(b blocks.Block) {
}
func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) {
pb := new(pb.PBMessage)
pb := new(pb.Message)
if err := proto.Unmarshal(nmsg.Data(), pb); err != nil {
return nil, err
}
......@@ -75,8 +75,8 @@ func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) {
return m, nil
}
func (m *message) ToProto() *pb.PBMessage {
pb := new(pb.PBMessage)
func (m *message) ToProto() *pb.Message {
pb := new(pb.Message)
for _, k := range m.Wantlist() {
pb.Wantlist = append(pb.Wantlist, string(k))
}
......
......@@ -22,7 +22,7 @@ func TestAppendWanted(t *testing.T) {
func TestNewMessageFromProto(t *testing.T) {
const str = "a_key"
protoMessage := new(pb.PBMessage)
protoMessage := new(pb.Message)
protoMessage.Wantlist = []string{string(str)}
if !contains(protoMessage.Wantlist, str) {
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