p2p/discover, p2p/discv5: add marshaling methods to Node

This commit is contained in:
Felix Lange 2017-04-04 02:06:57 +02:00
parent a7b9e484d0
commit 3b48a35f96
2 changed files with 28 additions and 0 deletions

View file

@ -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

View file

@ -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.