From 3b48a35f961e3e221ec04ba080096aadc9c5c4c8 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 4 Apr 2017 02:06:57 +0200 Subject: [PATCH] p2p/discover, p2p/discv5: add marshaling methods to Node --- p2p/discover/node.go | 14 ++++++++++++++ p2p/discv5/node.go | 14 ++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/p2p/discover/node.go b/p2p/discover/node.go index 6a7ab814e1..d9cbd9448e 100644 --- a/p2p/discover/node.go +++ b/p2p/discover/node.go @@ -207,6 +207,20 @@ func MustParseNode(rawurl string) *Node { return n } +// MarshalText implements encoding.TextMarshaler. +func (n *Node) MarshalText() ([]byte, error) { + return []byte(n.String()), nil +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (n *Node) UnmarshalText(text []byte) error { + dec, err := ParseNode(string(text)) + if err == nil { + *n = *dec + } + return err +} + // NodeID is a unique identifier for each node. // The node identifier is a marshaled elliptic curve public key. type NodeID [NodeIDBits / 8]byte diff --git a/p2p/discv5/node.go b/p2p/discv5/node.go index c99b4da145..2db7a508f0 100644 --- a/p2p/discv5/node.go +++ b/p2p/discv5/node.go @@ -215,6 +215,20 @@ func MustParseNode(rawurl string) *Node { return n } +// MarshalText implements encoding.TextMarshaler. +func (n *Node) MarshalText() ([]byte, error) { + return []byte(n.String()), nil +} + +// UnmarshalText implements encoding.TextUnmarshaler. +func (n *Node) UnmarshalText(text []byte) error { + dec, err := ParseNode(string(text)) + if err == nil { + *n = *dec + } + return err +} + // type nodeQueue []*Node // // // pushNew adds n to the end if it is not present.