io

package
v1.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2021 License: MIT Imports: 4 Imported by: 3

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsSerializable

func AsSerializable(se Serializable, data []byte) error

func ToArray

func ToArray(se Serializable) ([]byte, error)

Types

type BinaryReader

type BinaryReader struct {
	Err error
	// contains filtered or unexported fields
}

BinaryReader 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 NewBinaryReaderFromBuf

func NewBinaryReaderFromBuf(b []byte) *BinaryReader

NewBinaryReaderFromBuf makes a BinaryReader from byte buffer.

func NewBinaryReaderFromIO

func NewBinaryReaderFromIO(ior io.Reader) *BinaryReader

NewBinaryReaderFromIO makes a BinaryReader from io.Reader.

func (*BinaryReader) ReadBE

func (r *BinaryReader) ReadBE(v interface{})

ReadBE reads from the underlying io.Reader into the interface v in big-endian format.

func (*BinaryReader) ReadBytesWithGrouping

func (reader *BinaryReader) ReadBytesWithGrouping() (key []byte, err error)

ReadBytesWithGrouping ...

func (*BinaryReader) ReadLE

func (r *BinaryReader) ReadLE(v interface{})

ReadLE reads from the underlying io.Reader into the interface v in little-endian format.

func (*BinaryReader) ReadUnit64Bytes

func (r *BinaryReader) ReadUnit64Bytes() []byte

ReadUnit64Bytes reads from the underlying io.Reader into the interface v in little-endian format

func (*BinaryReader) ReadVarBytes

func (r *BinaryReader) ReadVarBytes() []byte

ReadVarBytes reads the next set of bytes from the underlying reader. ReadVarUInt() is used to determine how large that slice is

func (*BinaryReader) ReadVarString

func (r *BinaryReader) ReadVarString() string

ReadVarString calls ReadVarBytes and casts the results as a string.

func (*BinaryReader) ReadVarUint

func (r *BinaryReader) ReadVarUint() uint64

ReadVarUint reads a variable-length-encoded integer from the underlying reader.

type BinaryWriter

type BinaryWriter struct {
	Err error
	// contains filtered or unexported fields
}

BinaryWriter 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 NewBinaryWriterFromIO

func NewBinaryWriterFromIO(iow io.Writer) *BinaryWriter

NewBinaryWriterFromIO makes a BinaryWriter from io.Writer.

func (*BinaryWriter) WriteBE

func (w *BinaryWriter) WriteBE(v interface{})

WriteBE writes into the underlying io.Writer from an object v in big-endian format.

func (*BinaryWriter) WriteBytesWithGrouping

func (writer *BinaryWriter) WriteBytesWithGrouping(value []byte)

WriteBytesWithGrouping ...

func (*BinaryWriter) WriteLE

func (w *BinaryWriter) WriteLE(v interface{})

WriteLE writes into the underlying io.Writer from an object v in little-endian format.

func (*BinaryWriter) WriteVarBytes

func (w *BinaryWriter) WriteVarBytes(b []byte)

WriteVarBytes writes a variable length byte array into the underlying io.Writer.

func (*BinaryWriter) WriteVarString

func (w *BinaryWriter) WriteVarString(s string)

WriteVarString writes a variable length string into the underlying io.Writer.

func (*BinaryWriter) WriteVarUint

func (w *BinaryWriter) WriteVarUint(val uint64)

WriteVarUint writes a uint64 into the underlying writer using variable-length encoding.

type BufBinaryWriter

type BufBinaryWriter struct {
	*BinaryWriter
	// contains filtered or unexported fields
}

BufBinaryWriter is an additional layer on top of BinaryWriter that automatically creates buffer to write into that you can get after all writes via Bytes().

func NewBufBinaryWriter

func NewBufBinaryWriter() *BufBinaryWriter

NewBufBinaryWriter makes a BufBinaryWriter with an empty byte buffer.

func (*BufBinaryWriter) Bytes

func (bw *BufBinaryWriter) Bytes() []byte

Bytes returns resulting buffer and makes future writes return an error.

func (*BufBinaryWriter) Reset

func (bw *BufBinaryWriter) 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

type Serializable interface {
	Deserialize(*BinaryReader)
	Serialize(*BinaryWriter)
}

Serializable defines the binary encoding/decoding interface. Errors are returned via BinaryReader/BinaryWriter Err field. These functions must have safe behavior when passed BinaryReader/BinaryWriter 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL