aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/message.go
diff options
context:
space:
mode:
authorFelix Lange <fjl@twurst.com>2014-11-25 19:25:31 +0800
committerFelix Lange <fjl@twurst.com>2014-11-25 19:25:31 +0800
commit6049fcd52ab10362721a352cfd7a93a01c3ffa97 (patch)
tree0ebfbe3148639348d1777d93d738a055768158d8 /p2p/message.go
parentc1fca72552386868d28ce7541691e53e55673549 (diff)
downloadgo-tangerine-6049fcd52ab10362721a352cfd7a93a01c3ffa97.tar
go-tangerine-6049fcd52ab10362721a352cfd7a93a01c3ffa97.tar.gz
go-tangerine-6049fcd52ab10362721a352cfd7a93a01c3ffa97.tar.bz2
go-tangerine-6049fcd52ab10362721a352cfd7a93a01c3ffa97.tar.lz
go-tangerine-6049fcd52ab10362721a352cfd7a93a01c3ffa97.tar.xz
go-tangerine-6049fcd52ab10362721a352cfd7a93a01c3ffa97.tar.zst
go-tangerine-6049fcd52ab10362721a352cfd7a93a01c3ffa97.zip
p2p: use package rlp for baseProtocol
Diffstat (limited to 'p2p/message.go')
-rw-r--r--p2p/message.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/p2p/message.go b/p2p/message.go
index ade39d25a..845c832f0 100644
--- a/p2p/message.go
+++ b/p2p/message.go
@@ -41,14 +41,22 @@ func encodePayload(params ...interface{}) []byte {
return buf.Bytes()
}
-// Data returns the decoded RLP payload items in a message.
-func (msg Msg) Data() (*ethutil.Value, error) {
- s := rlp.NewListStream(msg.Payload, uint64(msg.Size))
+// Value returns the decoded RLP payload items in a message.
+func (msg Msg) Value() (*ethutil.Value, error) {
var v []interface{}
- err := s.Decode(&v)
+ err := msg.Decode(&v)
return ethutil.NewValue(v), err
}
+// Decode parse the RLP content of a message into
+// the given value, which must be a pointer.
+//
+// For the decoding rules, please see package rlp.
+func (msg Msg) Decode(val interface{}) error {
+ s := rlp.NewListStream(msg.Payload, uint64(msg.Size))
+ return s.Decode(val)
+}
+
// Discard reads any remaining payload data into a black hole.
func (msg Msg) Discard() error {
_, err := io.Copy(ioutil.Discard, msg.Payload)
@@ -91,7 +99,7 @@ func MsgLoop(r MsgReader, maxsize uint32, f func(code uint64, data *ethutil.Valu
if msg.Size > maxsize {
return newPeerError(errInvalidMsg, "size %d exceeds maximum size of %d", msg.Size, maxsize)
}
- value, err := msg.Data()
+ value, err := msg.Value()
if err != nil {
return err
}