Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetVarSize ¶
func GetVarSize(value interface{}) int
GetVarSize returns the number of bytes in a serialized variable. It supports ints/uints (estimating them using variable-length encoding that is used in NEO), strings, pointers to Serializable structures, slices and arrays of ints/uints or Serializable structures. It's similar to GetVarSize<T>(this T[] value) used in C#, but differs in that it also supports things like Uint160 or Uint256.
Types ¶
type BinReader ¶
type BinReader struct { Err error // contains filtered or unexported fields }
BinReader is a convenient wrapper around a io.Reader and err object Used to simplify error handling when reading into a struct with many fields
func NewBinReaderFromBuf ¶
NewBinReaderFromBuf makes a BinReader from byte buffer.
func NewBinReaderFromIO ¶
NewBinReaderFromIO makes a BinReader from io.Reader.
func (*BinReader) ReadBE ¶
func (r *BinReader) ReadBE(v interface{})
ReadBE reads from the underlying io.Reader into the interface v in big-endian format
func (*BinReader) ReadBytes ¶
ReadBytes reads the next set of bytes from the underlying reader. ReadVarUInt() is used to determine how large that slice is
func (*BinReader) ReadLE ¶
func (r *BinReader) ReadLE(v interface{})
ReadLE reads from the underlying io.Reader into the interface v in little-endian format
func (*BinReader) ReadString ¶
ReadString calls ReadBytes and casts the results as a string
func (*BinReader) ReadVarUint ¶
ReadVarUint reads a variable-length-encoded integer from the underlying reader
type BinWriter ¶
type BinWriter struct { Err error // contains filtered or unexported fields }
BinWriter is a convenient wrapper around a io.Writer and err object Used to simplify error handling when writing into a io.Writer from a struct with many fields
func NewBinWriterFromIO ¶
NewBinWriterFromIO makes a BinWriter from io.Writer.
func (*BinWriter) WriteBE ¶
func (w *BinWriter) WriteBE(v interface{})
WriteBE writes into the underlying io.Writer from an object v in big-endian format
func (*BinWriter) WriteBytes ¶
WriteBytes writes a variable length byte array into the underlying io.Writer
func (*BinWriter) WriteLE ¶
func (w *BinWriter) WriteLE(v interface{})
WriteLE writes into the underlying io.Writer from an object v in little-endian format
func (*BinWriter) WriteString ¶
WriteString writes a variable length string into the underlying io.Writer
func (*BinWriter) WriteVarUint ¶
WriteVarUint writes a uint64 into the underlying writer using variable-length encoding
type BufBinWriter ¶
type BufBinWriter struct { *BinWriter // contains filtered or unexported fields }
BufBinWriter is an additional layer on top of BinWriter that automatically creates buffer to write into that you can get after all writes via Bytes().
func NewBufBinWriter ¶
func NewBufBinWriter() *BufBinWriter
NewBufBinWriter makes a BufBinWriter with an empty byte buffer.
func (*BufBinWriter) Bytes ¶
func (bw *BufBinWriter) Bytes() []byte
Bytes returns resulting buffer and makes future writes return an error.
func (*BufBinWriter) Reset ¶
func (bw *BufBinWriter) Reset()
Reset resets the state of the buffer, making it usable again. It can make buffer usage somewhat more efficient, because you don't need to create it again, but beware that the buffer is gonna be the same as the one returned by Bytes(), so if you need that data after Reset() you have to copy it yourself.
type Serializable ¶
Serializable defines the binary encoding/decoding interface. Errors are returned via BinReader/BinWriter Err field. These functions must have safe behavior when passed BinReader/BinWriter with Err already set. Invocations to these functions tend to be nested, with this mechanism only the top-level caller should handle the error once and all the other code should just not panic in presence of error.