Example #1
0
// Read a (length prefixed) byteslice then decode the object using the codec
func decodeByteSlice(codec wire.Codec, r io.Reader, n *int64, err *error) interface{} {
	bytez := wire.ReadByteSlice(r, n, err)
	if *err != nil {
		return nil
	}
	n_ := new(int64)
	return codec.Decode(bytes.NewBuffer(bytez), n_, err)
}
Example #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 = wire.ReadInt8(r, n, err)
	node.size = wire.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 = wire.ReadByteSlice(r, n, err)
		node.rightHash = wire.ReadByteSlice(r, n, err)
	}
	return node
}