Skip to content
This repository has been archived by the owner on Feb 1, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from ipfs/feat/protobuf
Browse files Browse the repository at this point in the history
update gogo protobuf
  • Loading branch information
Stebalien authored Aug 9, 2018
2 parents 3cef6b5 + ec9a109 commit 0f64cfa
Show file tree
Hide file tree
Showing 8 changed files with 1,067 additions and 72 deletions.
2 changes: 1 addition & 1 deletion .gx/lastpubver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.4: QmaYxvpkdEd5anuSzWiivJdeZV1W1NYW52xJQB1khSqH1b
1.0.5: QmerEhJuCXvrZoAqaxXHNbjtk6UgbGTSiAe4J3VGzgx61E
17 changes: 8 additions & 9 deletions message/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
blocks "github.com/ipfs/go-block-format"

ggio "github.com/gogo/protobuf/io"
proto "github.com/gogo/protobuf/proto"
cid "github.com/ipfs/go-cid"
inet "github.com/libp2p/go-libp2p-net"
)
Expand Down Expand Up @@ -185,12 +184,12 @@ func (m *impl) ToProtoV0() *pb.Message {
pbm.Wantlist.Entries = make([]*pb.Message_Wantlist_Entry, 0, len(m.wantlist))
for _, e := range m.wantlist {
pbm.Wantlist.Entries = append(pbm.Wantlist.Entries, &pb.Message_Wantlist_Entry{
Block: proto.String(e.Cid.KeyString()),
Priority: proto.Int32(int32(e.Priority)),
Cancel: proto.Bool(e.Cancel),
Block: e.Cid.Bytes(),
Priority: int32(e.Priority),
Cancel: e.Cancel,
})
}
pbm.Wantlist.Full = proto.Bool(m.full)
pbm.Wantlist.Full = m.full

blocks := m.Blocks()
pbm.Blocks = make([][]byte, 0, len(blocks))
Expand All @@ -206,12 +205,12 @@ func (m *impl) ToProtoV1() *pb.Message {
pbm.Wantlist.Entries = make([]*pb.Message_Wantlist_Entry, 0, len(m.wantlist))
for _, e := range m.wantlist {
pbm.Wantlist.Entries = append(pbm.Wantlist.Entries, &pb.Message_Wantlist_Entry{
Block: proto.String(e.Cid.KeyString()),
Priority: proto.Int32(int32(e.Priority)),
Cancel: proto.Bool(e.Cancel),
Block: e.Cid.Bytes(),
Priority: int32(e.Priority),
Cancel: e.Cancel,
})
}
pbm.Wantlist.Full = proto.Bool(m.full)
pbm.Wantlist.Full = m.full

blocks := m.Blocks()
pbm.Payload = make([]*pb.Message_Block, 0, len(blocks))
Expand Down
5 changes: 2 additions & 3 deletions message/message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (

pb "github.com/ipfs/go-bitswap/message/pb"

proto "github.com/gogo/protobuf/proto"
blocks "github.com/ipfs/go-block-format"
cid "github.com/ipfs/go-cid"
u "github.com/ipfs/go-ipfs-util"
Expand All @@ -31,7 +30,7 @@ func TestNewMessageFromProto(t *testing.T) {
protoMessage := new(pb.Message)
protoMessage.Wantlist = new(pb.Message_Wantlist)
protoMessage.Wantlist.Entries = []*pb.Message_Wantlist_Entry{
{Block: proto.String(str.KeyString())},
{Block: str.Bytes()},
}
if !wantlistContains(protoMessage.Wantlist, str) {
t.Fail()
Expand Down Expand Up @@ -166,7 +165,7 @@ func TestToAndFromNetMessage(t *testing.T) {

func wantlistContains(wantlist *pb.Message_Wantlist, c *cid.Cid) bool {
for _, e := range wantlist.GetEntries() {
if e.GetBlock() == c.KeyString() {
if bytes.Equal(e.GetBlock(), c.Bytes()) {
return true
}
}
Expand Down
13 changes: 8 additions & 5 deletions message/pb/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# TODO(brian): add proto tasks
all: message.pb.go
PB = $(wildcard *.proto)
GO = $(PB:.proto=.pb.go)

message.pb.go: message.proto
protoc --gogo_out=. --proto_path=../../../../../:/usr/local/opt/protobuf/include:. $<
all: $(GO)

%.pb.go: %.proto
protoc --proto_path=$(GOPATH)/src:. --gogofast_out=. $<

clean:
rm message.pb.go
rm -f *.pb.go
rm -f *.go
8 changes: 0 additions & 8 deletions message/pb/Rules.mk

This file was deleted.

Loading

0 comments on commit 0f64cfa

Please sign in to comment.