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

refactor(exchange/bitswap) move proto to internal pb package

parent 43ecec85
...@@ -11,7 +11,7 @@ It is generated from these files: ...@@ -11,7 +11,7 @@ It is generated from these files:
It has these top-level messages: It has these top-level messages:
PBMessage PBMessage
*/ */
package message package pb
import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto" import proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
import math "math" import math "math"
......
package message; package pb;
message PBMessage { message PBMessage {
repeated string wantlist = 1; repeated string wantlist = 1;
......
...@@ -3,6 +3,7 @@ package message ...@@ -3,6 +3,7 @@ package message
import ( import (
proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto" proto "github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
blocks "github.com/jbenet/go-ipfs/blocks" blocks "github.com/jbenet/go-ipfs/blocks"
pb "github.com/jbenet/go-ipfs/exchange/bitswap/message/internal/pb"
netmsg "github.com/jbenet/go-ipfs/net/message" netmsg "github.com/jbenet/go-ipfs/net/message"
nm "github.com/jbenet/go-ipfs/net/message" nm "github.com/jbenet/go-ipfs/net/message"
peer "github.com/jbenet/go-ipfs/peer" peer "github.com/jbenet/go-ipfs/peer"
...@@ -18,7 +19,7 @@ type BitSwapMessage interface { ...@@ -18,7 +19,7 @@ type BitSwapMessage interface {
} }
type Exportable interface { type Exportable interface {
ToProto() *PBMessage ToProto() *pb.PBMessage
ToNet(p peer.Peer) (nm.NetMessage, error) ToNet(p peer.Peer) (nm.NetMessage, error)
} }
...@@ -32,7 +33,7 @@ func New() *message { ...@@ -32,7 +33,7 @@ func New() *message {
return new(message) return new(message)
} }
func newMessageFromProto(pbm PBMessage) BitSwapMessage { func newMessageFromProto(pbm pb.PBMessage) 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))
...@@ -63,7 +64,7 @@ func (m *message) AppendBlock(b blocks.Block) { ...@@ -63,7 +64,7 @@ func (m *message) AppendBlock(b blocks.Block) {
} }
func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) { func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) {
pb := new(PBMessage) pb := new(pb.PBMessage)
if err := proto.Unmarshal(nmsg.Data(), pb); err != nil { if err := proto.Unmarshal(nmsg.Data(), pb); err != nil {
return nil, err return nil, err
} }
...@@ -71,8 +72,8 @@ func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) { ...@@ -71,8 +72,8 @@ func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) {
return m, nil return m, nil
} }
func (m *message) ToProto() *PBMessage { func (m *message) ToProto() *pb.PBMessage {
pb := new(PBMessage) pb := new(pb.PBMessage)
for _, k := range m.Wantlist() { for _, k := range m.Wantlist() {
pb.Wantlist = append(pb.Wantlist, string(k)) pb.Wantlist = append(pb.Wantlist, string(k))
} }
......
...@@ -4,7 +4,8 @@ import ( ...@@ -4,7 +4,8 @@ import (
"bytes" "bytes"
"testing" "testing"
"github.com/jbenet/go-ipfs/blocks" blocks "github.com/jbenet/go-ipfs/blocks"
pb "github.com/jbenet/go-ipfs/exchange/bitswap/message/internal/pb"
peer "github.com/jbenet/go-ipfs/peer" peer "github.com/jbenet/go-ipfs/peer"
u "github.com/jbenet/go-ipfs/util" u "github.com/jbenet/go-ipfs/util"
) )
...@@ -21,7 +22,7 @@ func TestAppendWanted(t *testing.T) { ...@@ -21,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(PBMessage) protoMessage := new(pb.PBMessage)
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