func decodeShort(buf []byte) (node, error) { kbuf, rest, err := rlp.SplitString(buf) if err != nil { return nil, err } key := compactDecode(kbuf) if key[len(key)-1] == 16 { // value node val, _, err := rlp.SplitString(rest) if err != nil { return nil, fmt.Errorf("invalid value node: %v", err) } return shortNode{key, valueNode(val)}, nil } r, _, err := decodeRef(rest) if err != nil { return nil, wrapError(err, "val") } return shortNode{key, r}, nil }
func decodeFull(buf []byte) (fullNode, error) { var n fullNode for i := 0; i < 16; i++ { cld, rest, err := decodeRef(buf) if err != nil { return n, wrapError(err, fmt.Sprintf("[%d]", i)) } n[i], buf = cld, rest } val, _, err := rlp.SplitString(buf) if err != nil { return n, err } if len(val) > 0 { n[16] = valueNode(val) } return n, nil }
func decodeFull(hash, buf, elems []byte) (fullNode, error) { n := fullNode{hash: hash} for i := 0; i < 16; i++ { cld, rest, err := decodeRef(elems) if err != nil { return n, wrapError(err, fmt.Sprintf("[%d]", i)) } n.Children[i], elems = cld, rest } val, _, err := rlp.SplitString(elems) if err != nil { return n, err } if len(val) > 0 { n.Children[16] = valueNode(val) } return n, nil }