aboutsummaryrefslogtreecommitdiffstats
path: root/p2p/message.go
diff options
context:
space:
mode:
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
}