예제 #1
0
// Encode object using codec, then write a (length prefixed) byteslice.
func encodeByteSlice(o interface{}, codec wire.Codec, w io.Writer, n *int64, err *error) {
	buf, n_ := new(bytes.Buffer), new(int64)
	codec.Encode(o, buf, n_, err)
	if *err != nil {
		return
	}
	wire.WriteByteSlice(buf.Bytes(), w, n, err)
}
예제 #2
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)
}