mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 07:06:42 +00:00
p2p/discover, p2p/discv5: add marshaling methods to Node
This commit is contained in:
parent
a7b9e484d0
commit
3b48a35f96
2 changed files with 28 additions and 0 deletions
|
|
@ -207,6 +207,20 @@ func MustParseNode(rawurl string) *Node {
|
||||||
return n
|
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.
|
// NodeID is a unique identifier for each node.
|
||||||
// The node identifier is a marshaled elliptic curve public key.
|
// The node identifier is a marshaled elliptic curve public key.
|
||||||
type NodeID [NodeIDBits / 8]byte
|
type NodeID [NodeIDBits / 8]byte
|
||||||
|
|
|
||||||
|
|
@ -215,6 +215,20 @@ func MustParseNode(rawurl string) *Node {
|
||||||
return n
|
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
|
// type nodeQueue []*Node
|
||||||
//
|
//
|
||||||
// // pushNew adds n to the end if it is not present.
|
// // pushNew adds n to the end if it is not present.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue