예제 #1
0
// Read a (length prefixed) byteslice then decode the object using the codec
func decodeByteSlice(codec binary.Codec, r io.Reader, n *int64, err *error) interface{} {
	bytez := binary.ReadByteSlice(r, n, err)
	if *err != nil {
		return nil
	}
	n_ := new(int64)
	return codec.Decode(bytes.NewBuffer(bytez), n_, err)
}
예제 #2
0
// NOTE: The hash is not saved or set.  The caller should set the hash afterwards.
// (Presumably the caller already has the hash)
func ReadIAVLNode(t *IAVLTree, r io.Reader, n *int64, err *error) *IAVLNode {
	node := &IAVLNode{}

	// node header
	node.height = binary.ReadInt8(r, n, err)
	node.size = binary.ReadVarint(r, n, err)
	node.key = decodeByteSlice(t.keyCodec, r, n, err)

	if node.height == 0 {
		// value
		node.value = decodeByteSlice(t.valueCodec, r, n, err)
	} else {
		// children
		node.leftHash = binary.ReadByteSlice(r, n, err)
		node.rightHash = binary.ReadByteSlice(r, n, err)
	}
	if *err != nil {
		panic(*err)
	}
	return node
}