Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-bitswap
Commits
a4985810
Commit
a4985810
authored
Oct 22, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(exchange/bitswap) move proto to internal pb package
parent
43ecec85
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
11 additions
and
9 deletions
+11
-9
message/internal/pb/Makefile
message/internal/pb/Makefile
+0
-0
message/internal/pb/message.pb.go
message/internal/pb/message.pb.go
+1
-1
message/internal/pb/message.proto
message/internal/pb/message.proto
+1
-1
message/message.go
message/message.go
+6
-5
message/message_test.go
message/message_test.go
+3
-2
No files found.
message/Makefile
→
message/
internal/pb/
Makefile
View file @
a4985810
File moved
message/message.pb.go
→
message/
internal/pb/
message.pb.go
View file @
a4985810
...
...
@@ -11,7 +11,7 @@ It is generated from these files:
It has these top-level messages:
PBMessage
*/
package
message
package
pb
import
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
import
math
"math"
...
...
message/message.proto
→
message/
internal/pb/
message.proto
View file @
a4985810
package
message
;
package
pb
;
message
PBMessage
{
repeated
string
wantlist
=
1
;
...
...
message/message.go
View file @
a4985810
...
...
@@ -3,6 +3,7 @@ package message
import
(
proto
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/goprotobuf/proto"
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"
nm
"github.com/jbenet/go-ipfs/net/message"
peer
"github.com/jbenet/go-ipfs/peer"
...
...
@@ -18,7 +19,7 @@ type BitSwapMessage interface {
}
type
Exportable
interface
{
ToProto
()
*
PBMessage
ToProto
()
*
pb
.
PBMessage
ToNet
(
p
peer
.
Peer
)
(
nm
.
NetMessage
,
error
)
}
...
...
@@ -32,7 +33,7 @@ func New() *message {
return
new
(
message
)
}
func
newMessageFromProto
(
pbm
PBMessage
)
BitSwapMessage
{
func
newMessageFromProto
(
pbm
pb
.
PBMessage
)
BitSwapMessage
{
m
:=
New
()
for
_
,
s
:=
range
pbm
.
GetWantlist
()
{
m
.
AppendWanted
(
u
.
Key
(
s
))
...
...
@@ -63,7 +64,7 @@ func (m *message) AppendBlock(b blocks.Block) {
}
func
FromNet
(
nmsg
netmsg
.
NetMessage
)
(
BitSwapMessage
,
error
)
{
pb
:=
new
(
PBMessage
)
pb
:=
new
(
pb
.
PBMessage
)
if
err
:=
proto
.
Unmarshal
(
nmsg
.
Data
(),
pb
);
err
!=
nil
{
return
nil
,
err
}
...
...
@@ -71,8 +72,8 @@ func FromNet(nmsg netmsg.NetMessage) (BitSwapMessage, error) {
return
m
,
nil
}
func
(
m
*
message
)
ToProto
()
*
PBMessage
{
pb
:=
new
(
PBMessage
)
func
(
m
*
message
)
ToProto
()
*
pb
.
PBMessage
{
pb
:=
new
(
pb
.
PBMessage
)
for
_
,
k
:=
range
m
.
Wantlist
()
{
pb
.
Wantlist
=
append
(
pb
.
Wantlist
,
string
(
k
))
}
...
...
message/message_test.go
View file @
a4985810
...
...
@@ -4,7 +4,8 @@ import (
"bytes"
"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"
u
"github.com/jbenet/go-ipfs/util"
)
...
...
@@ -21,7 +22,7 @@ func TestAppendWanted(t *testing.T) {
func
TestNewMessageFromProto
(
t
*
testing
.
T
)
{
const
str
=
"a_key"
protoMessage
:=
new
(
PBMessage
)
protoMessage
:=
new
(
pb
.
PBMessage
)
protoMessage
.
Wantlist
=
[]
string
{
string
(
str
)}
if
!
contains
(
protoMessage
.
Wantlist
,
str
)
{
t
.
Fail
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment