Documentation ¶
Index ¶
- func BytesTest[T interface{ ... }](t *testing.T, obj1 T, fromBytes func(data []byte) (T, error)) T
- func ReadFromBytes[T IoReader](data []byte, obj T) (T, error)
- func ReadFromFunc[T any](rr *Reader, fromBytes func([]byte) (T, error)) (ret T)
- func ReadN(r io.Reader, data []byte) error
- func ReadWriteTest[T IoReadWriter](t *testing.T, obj1 T, newObj T) T
- func StringTest[T interface{ ... }](t *testing.T, obj1 T, fromString func(data string) (T, error)) T
- func WriteN(w io.Writer, data []byte) error
- func WriteToBytes(obj IoWriter) []byte
- type Buffer
- type Counter
- type IoReadWriter
- type IoReader
- type IoWriter
- type Kind
- type Must
- type PushBack
- type Reader
- func (rr *Reader) Bytes() []byte
- func (rr *Reader) CheckAvailable(nrOfBytes int) int
- func (rr *Reader) Close()
- func (rr *Reader) Must() *Reader
- func (rr *Reader) PushBack() *Writer
- func (rr *Reader) Read(obj IoReader)
- func (rr *Reader) ReadAmount16() (ret uint16)
- func (rr *Reader) ReadAmount32() (ret uint32)
- func (rr *Reader) ReadAmount64() (ret uint64)
- func (rr *Reader) ReadBool() bool
- func (rr *Reader) ReadByte() byte
- func (rr *Reader) ReadBytes() []byte
- func (rr *Reader) ReadDuration() (ret time.Duration)
- func (rr *Reader) ReadFromFunc(read func(w io.Reader) (int, error))
- func (rr *Reader) ReadGas64() (ret uint64)
- func (rr *Reader) ReadInt16() (ret int16)
- func (rr *Reader) ReadInt32() (ret int32)
- func (rr *Reader) ReadInt64() (ret int64)
- func (rr *Reader) ReadInt8() (ret int8)
- func (rr *Reader) ReadKind() Kind
- func (rr *Reader) ReadKindAndVerify(expectedKind Kind)
- func (rr *Reader) ReadN(ret []byte)
- func (rr *Reader) ReadSerialized(obj deserializable, sizes ...int)
- func (rr *Reader) ReadSize16() (size int)
- func (rr *Reader) ReadSize32() (size int)
- func (rr *Reader) ReadSizeWithLimit(limit uint32) int
- func (rr *Reader) ReadString() (ret string)
- func (rr *Reader) ReadUint16() (ret uint16)
- func (rr *Reader) ReadUint256() (ret *big.Int)
- func (rr *Reader) ReadUint32() (ret uint32)
- func (rr *Reader) ReadUint64() (ret uint64)
- func (rr *Reader) ReadUint8() (ret uint8)
- type Skipper
- type Writer
- func (ww *Writer) Bytes() []byte
- func (ww *Writer) Skip() *Reader
- func (ww *Writer) Write(obj IoWriter) *Writer
- func (ww *Writer) WriteAmount16(val uint16) *Writer
- func (ww *Writer) WriteAmount32(val uint32) *Writer
- func (ww *Writer) WriteAmount64(val uint64) *Writer
- func (ww *Writer) WriteBool(val bool) *Writer
- func (ww *Writer) WriteByte(val byte) *Writer
- func (ww *Writer) WriteBytes(data []byte) *Writer
- func (ww *Writer) WriteDuration(val time.Duration) *Writer
- func (ww *Writer) WriteFromBytes(obj interface{ ... }) *Writer
- func (ww *Writer) WriteFromFunc(write func(w io.Writer) (int, error)) *Writer
- func (ww *Writer) WriteGas64(val uint64) *Writer
- func (ww *Writer) WriteInt16(val int16) *Writer
- func (ww *Writer) WriteInt32(val int32) *Writer
- func (ww *Writer) WriteInt64(val int64) *Writer
- func (ww *Writer) WriteInt8(val int8) *Writer
- func (ww *Writer) WriteKind(msgType Kind) *Writer
- func (ww *Writer) WriteN(val []byte) *Writer
- func (ww *Writer) WriteSerialized(obj serializable, sizes ...int) *Writer
- func (ww *Writer) WriteSize16(val int) *Writer
- func (ww *Writer) WriteSize32(val int) *Writer
- func (ww *Writer) WriteSizeWithLimit(val int, limit uint32) *Writer
- func (ww *Writer) WriteString(val string) *Writer
- func (ww *Writer) WriteTokens(val uint64) *Writer
- func (ww *Writer) WriteUint16(val uint16) *Writer
- func (ww *Writer) WriteUint256(val *big.Int) *Writer
- func (ww *Writer) WriteUint32(val uint32) *Writer
- func (ww *Writer) WriteUint64(val uint64) *Writer
- func (ww *Writer) WriteUint8(val uint8) *Writer
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadFromBytes ¶
ReadFromBytes is a wrapper that uses an object's Read() function to marshal the object from data bytes. It's typically used to implement a one-line <Type>FromBytes() function and returns the expected type and error.
func ReadFromFunc ¶
ReadFromFunc allows a reader to use any <Type>FromBytes()-like function as a source. It will read the next group of bytes and pass it to the specified function and returns the correct type of object
func ReadWriteTest ¶
func ReadWriteTest[T IoReadWriter](t *testing.T, obj1 T, newObj T) T
ReadWriteTest can be used with any object that implements IoReader and IoWriter to test whether the Read() and Write() functions complement each other correctly. You pass in an object that has all fields that need serialization set, plus a new, empty object that will receive the deserialized data. The function will Write, Read, and Write again and compare the objects for equality and both serialized versions as well. It will return the deserialized object in case the user wants to perform more tests with it.
func StringTest ¶
func WriteToBytes ¶
WriteToBytes is a wrapper that uses an object's Write() function to marshal the object to data bytes. It's typically used to implement a one-line Bytes() function for the object.
Types ¶
type Buffer ¶
type Buffer []byte
Buffer implements a hyper-simple and efficient in-memory read/write stream. It will read from the start of the buffer and write to the end of the buffer.
type Counter ¶
type Counter struct {
// contains filtered or unexported fields
}
Counter implements a read/write stream that can wrap another stream. It will count the total number of bytes read/written from/to the wrapped stream.
func NewReadCounter ¶
func NewWriteCounter ¶
type IoReadWriter ¶
type Must ¶
type Must struct {
// contains filtered or unexported fields
}
Must will wrap a reader stream and will panic whenever an error occurs on that stream.
type PushBack ¶
type PushBack struct {
// contains filtered or unexported fields
}
PushBack implements a pushback wrapper for any read stream. It uses an in-memory buffer that allows you to write data back to the stream. It will read this data first, and then resume reading from the wrapped stream. The pushback Writer is only valid for this Reader until it resumes the stream. See accounts.getNFTData() and accounts.saveNFTData() for an example of how Pushback and Skipper work in conjunction.
type Reader ¶
type Reader struct { Err error // contains filtered or unexported fields }
func NewBytesReader ¶
func (*Reader) Bytes ¶
Bytes will return the remaining bytes in the Reader buffer. It is asserted that the read stream is a Buffer, and that the Reader error state is nil.
func (*Reader) CheckAvailable ¶
func (*Reader) Close ¶
func (rr *Reader) Close()
Close indicates the end of reading from the bytes buffer. If any unread bytes are remaining in the buffer an error will be returned.
func (*Reader) Must ¶
Must will wrap the reader stream in a stream that will panic whenever an error occurs.
func (*Reader) PushBack ¶
PushBack returns a pushback writer that allows you to insert data before the stream. The Reader will read this data first, and then resume reading from the stream. The pushback Writer is only valid for this Reader until it resumes the stream.
func (*Reader) ReadAmount16 ¶
ReadAmount16 reads a variable-length encoded amount.
func (*Reader) ReadAmount32 ¶
ReadAmount32 reads a variable-length encoded amount.
func (*Reader) ReadAmount64 ¶
ReadAmount64 reads a variable-length encoded amount.
func (*Reader) ReadDuration ¶
func (*Reader) ReadGas64 ¶
ReadGas64 reads a variable-length encoded amount of gas. Note that the amount was incremented before storing so that the math.MaxUint64 gas limit will wrap to zero and only takes 1 byte.
func (*Reader) ReadKindAndVerify ¶
func (*Reader) ReadSerialized ¶
ReadSerialized reads the deserializable object from the stream. If no sizes are present a 16-bit size is read from the stream. The first size indicates a different limit for the size read from the stream. The second size indicates the expected size and does not read it from the stream.
func (*Reader) ReadSize16 ¶
ReadSize16 reads a 16-bit size from the stream. We expect this size to indicate how many items we are about to read from the stream. Therefore, if we can determine that there are not at least this amount of bytes available in the stream we raise an error and return zero for the size.
func (*Reader) ReadSize32 ¶
ReadSize32 reads a 32-bit size from the stream. We expect this size to indicate how many items we are about to read from the stream. Therefore, if we can determine that there are not at least this amount of bytes available in the stream we raise an error and return zero for the size.
func (*Reader) ReadSizeWithLimit ¶
ReadSizeWithLimit reads an int size from the stream, and verifies that it does not exceed the specified limit. By limiting the size we can better detect malformed input data. The size returned will always be zero if an error occurred.
func (*Reader) ReadString ¶
func (*Reader) ReadUint16 ¶
func (*Reader) ReadUint256 ¶
func (*Reader) ReadUint32 ¶
func (*Reader) ReadUint64 ¶
type Skipper ¶
type Skipper struct {
// contains filtered or unexported fields
}
Skipper implements a skip wrapper for any writer stream. It works kind of the opposite of the PushBack wrapper. It allows you to dummy-read data from the stream and counts the bytes read. It will dummy-write these bytes first, and then resume writing to the wrapped stream The skip Reader is only valid for this Writer until it resumes the stream. See accounts.getNFTData() and accounts.saveNFTData() for an example of how Pushback and Skipper work in conjunction.
type Writer ¶
type Writer struct { Err error // contains filtered or unexported fields }
func NewBytesWriter ¶
func NewBytesWriter() *Writer
func (*Writer) Bytes ¶
Bytes will return the accumulated bytes in the Writer buffer. It is asserted that the write stream is a Buffer, and that the Writer error state is nil.
func (*Writer) WriteAmount16 ¶
WriteAmount16 writes a variable-length encoded amount.
func (*Writer) WriteAmount32 ¶
WriteAmount32 writes a variable-length encoded amount.
func (*Writer) WriteAmount64 ¶
WriteAmount64 writes a variable-length encoded amount.
func (*Writer) WriteBytes ¶
func (*Writer) WriteFromBytes ¶
func (*Writer) WriteFromFunc ¶
func (*Writer) WriteGas64 ¶
WriteGas64 writes a variable-length encoded amount of gas. Note that the amount is incremented before storing so that the math.MaxUint64 gas limit will wrap to zero and only takes 1 byte.
func (*Writer) WriteInt16 ¶
func (*Writer) WriteInt32 ¶
func (*Writer) WriteInt64 ¶
func (*Writer) WriteSerialized ¶
WriteSerialized writes the serializable object to the stream. If no sizes are present a 16-bit size is written to the stream. The first size indicates a different limit for the size written to the stream. The second size indicates the expected size and does not write it to the stream, but verifies that the serialized size is equal to the expected size..