Unverified Commit 0f64cfa8 authored by Steven Allen's avatar Steven Allen Committed by GitHub

Merge pull request #2 from ipfs/feat/protobuf

update gogo protobuf
parents 3cef6b50 ec9a1097
1.0.4: QmaYxvpkdEd5anuSzWiivJdeZV1W1NYW52xJQB1khSqH1b
1.0.5: QmerEhJuCXvrZoAqaxXHNbjtk6UgbGTSiAe4J3VGzgx61E
......@@ -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"
)
......@@ -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))
......@@ -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))
......
......@@ -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"
......@@ -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()
......@@ -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
}
}
......
# 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
include mk/header.mk
PB_$(d) = $(wildcard $(d)/*.proto)
TGTS_$(d) = $(PB_$(d):.proto=.pb.go)
#DEPS_GO += $(TGTS_$(d))
include mk/footer.mk
This diff is collapsed.
syntax = "proto3";
package bitswap.message.pb;
message Message {
......@@ -5,21 +7,21 @@ message Message {
message Wantlist {
message Entry {
optional string block = 1; // the block cid (cidV0 in bitswap 1.0.0, cidV1 in bitswap 1.1.0)
optional int32 priority = 2; // the priority (normalized). default to 1
optional bool cancel = 3; // whether this revokes an entry
}
bytes block = 1; // the block cid (cidV0 in bitswap 1.0.0, cidV1 in bitswap 1.1.0)
int32 priority = 2; // the priority (normalized). default to 1
bool cancel = 3; // whether this revokes an entry
}
repeated Entry entries = 1; // a list of wantlist entries
optional bool full = 2; // whether this is the full wantlist. default to false
repeated Entry entries = 1; // a list of wantlist entries
bool full = 2; // whether this is the full wantlist. default to false
}
message Block {
optional bytes prefix = 1; // CID prefix (cid version, multicodec and multihash prefix (type + length)
optional bytes data = 2;
bytes prefix = 1; // CID prefix (cid version, multicodec and multihash prefix (type + length)
bytes data = 2;
}
optional Wantlist wantlist = 1;
Wantlist wantlist = 1;
repeated bytes blocks = 2; // used to send Blocks in bitswap 1.0.0
repeated Block payload = 3; // used to send Blocks in bitswap 1.1.0
}
......@@ -39,7 +39,7 @@
},
{
"author": "whyrusleeping",
"hash": "QmZ4Qi3GaRbjcx28Sme5eMH7RQjGkt8wHxt2a65oLaeFEV",
"hash": "QmdxUuburamoF6zF9qjeQC4WYcWGbWuRmdLacMEsW8ioD8",
"name": "gogo-protobuf",
"version": "0.0.0"
},
......@@ -97,6 +97,6 @@
"license": "",
"name": "go-bitswap",
"releaseCmd": "git commit -a -m \"gx publish $VERSION\"",
"version": "1.0.4"
"version": "1.0.5"
}
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