-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaf_node.go
62 lines (53 loc) · 1.05 KB
/
leaf_node.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package PromethoniXTrie
import "io"
type LeafNode struct {
NodeDetails
Path Hash
Value Data
}
func (node *LeafNode) Type() NodeType {
return Leaf
}
func (node *LeafNode) Encode(writer io.Writer) error {
var err error
l := len(node.Path)
err = writeInt32(writer, int32(l))
if err == nil && l > 0 {
_, err = writer.Write(node.Path)
}
if err == nil {
l = len(node.Value)
err = writeInt32(writer, int32(l))
}
if err == nil && l > 0 {
_, err = writer.Write(node.Value)
}
return err
}
func (node *LeafNode) Decode(reader io.Reader) error {
length, err := readInt32(reader)
if err != nil {
return err
}
node.Path, err = readBytes(reader, length)
if err != nil {
return err
}
length, err = readInt32(reader)
if err != nil {
return err
}
node.Value, err = readBytes(reader, length)
return nil
}
func (node *LeafNode) NextRoute(Route) (Hash, Route, error) {
return nil, nil, nil
}
func AsLeaf(node Node) *LeafNode {
return node.(*LeafNode)
}
func NewLeafNode() *LeafNode {
node := new(LeafNode)
node._node = node
return node
}