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
ed584b1e
Commit
ed584b1e
authored
Oct 22, 2014
by
Brian Tiger Chow
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(bitswap) mv proto PBMessage -> Message
parent
ae109ad1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
14 additions
and
14 deletions
+14
-14
message/internal/pb/message.pb.go
message/internal/pb/message.pb.go
+7
-7
message/internal/pb/message.proto
message/internal/pb/message.proto
+1
-1
message/message.go
message/message.go
+5
-5
message/message_test.go
message/message_test.go
+1
-1
No files found.
message/internal/pb/message.pb.go
View file @
ed584b1e
...
...
@@ -9,7 +9,7 @@ It is generated from these files:
message.proto
It has these top-level messages:
PB
Message
Message
*/
package
bitswap_message_pb
...
...
@@ -20,24 +20,24 @@ import math "math"
var
_
=
proto
.
Marshal
var
_
=
math
.
Inf
type
PB
Message
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
*
PB
Message
)
Reset
()
{
*
m
=
PB
Message
{}
}
func
(
m
*
PB
Message
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
PB
Message
)
ProtoMessage
()
{}
func
(
m
*
Message
)
Reset
()
{
*
m
=
Message
{}
}
func
(
m
*
Message
)
String
()
string
{
return
proto
.
CompactTextString
(
m
)
}
func
(
*
Message
)
ProtoMessage
()
{}
func
(
m
*
PB
Message
)
GetWantlist
()
[]
string
{
func
(
m
*
Message
)
GetWantlist
()
[]
string
{
if
m
!=
nil
{
return
m
.
Wantlist
}
return
nil
}
func
(
m
*
PB
Message
)
GetBlocks
()
[][]
byte
{
func
(
m
*
Message
)
GetBlocks
()
[][]
byte
{
if
m
!=
nil
{
return
m
.
Blocks
}
...
...
message/internal/pb/message.proto
View file @
ed584b1e
package
bitswap
.
message.pb
;
message
PB
Message
{
message
Message
{
repeated
string
wantlist
=
1
;
repeated
bytes
blocks
=
2
;
}
message/message.go
View file @
ed584b1e
...
...
@@ -22,7 +22,7 @@ type BitSwapMessage interface {
}
type
Exportable
interface
{
ToProto
()
*
pb
.
PB
Message
ToProto
()
*
pb
.
Message
ToNet
(
p
peer
.
Peer
)
(
nm
.
NetMessage
,
error
)
}
...
...
@@ -36,7 +36,7 @@ func New() *message {
return
new
(
message
)
}
func
newMessageFromProto
(
pbm
pb
.
PB
Message
)
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
.
PB
Message
)
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
.
PB
Message
{
pb
:=
new
(
pb
.
PB
Message
)
func
(
m
*
message
)
ToProto
()
*
pb
.
Message
{
pb
:=
new
(
pb
.
Message
)
for
_
,
k
:=
range
m
.
Wantlist
()
{
pb
.
Wantlist
=
append
(
pb
.
Wantlist
,
string
(
k
))
}
...
...
message/message_test.go
View file @
ed584b1e
...
...
@@ -22,7 +22,7 @@ func TestAppendWanted(t *testing.T) {
func
TestNewMessageFromProto
(
t
*
testing
.
T
)
{
const
str
=
"a_key"
protoMessage
:=
new
(
pb
.
PB
Message
)
protoMessage
:=
new
(
pb
.
Message
)
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