Documentation ¶
Index ¶
- Constants
- type MarshalUtil
- func (util *MarshalUtil) Bytes(clone ...bool) []byte
- func (util *MarshalUtil) DoneReading() (bool, error)
- func (util *MarshalUtil) Parse(parser func(data []byte) (interface{}, int, error)) (result interface{}, err error)
- func (util *MarshalUtil) ReadBool() (bool, error)
- func (util *MarshalUtil) ReadByte() (byte, error)
- func (util *MarshalUtil) ReadBytes(length int, optionalReadOffset ...int) ([]byte, error)
- func (util *MarshalUtil) ReadFloat64() (float64, error)
- func (util *MarshalUtil) ReadInt16() (int16, error)
- func (util *MarshalUtil) ReadInt32() (int32, error)
- func (util *MarshalUtil) ReadInt64() (int64, error)
- func (util *MarshalUtil) ReadInt8() (int8, error)
- func (util *MarshalUtil) ReadOffset() int
- func (util *MarshalUtil) ReadRemainingBytes() []byte
- func (util *MarshalUtil) ReadSeek(offset int)
- func (util *MarshalUtil) ReadTime() (result time.Time, err error)
- func (util *MarshalUtil) ReadUint16() (uint16, error)
- func (util *MarshalUtil) ReadUint32() (uint32, error)
- func (util *MarshalUtil) ReadUint64() (uint64, error)
- func (util *MarshalUtil) ReadUint8() (uint8, error)
- func (util *MarshalUtil) Write(object SimpleBinaryMarshaler) *MarshalUtil
- func (util *MarshalUtil) WriteBool(b bool) *MarshalUtil
- func (util *MarshalUtil) WriteByte(b byte) *MarshalUtil
- func (util *MarshalUtil) WriteBytes(bytes []byte) *MarshalUtil
- func (util *MarshalUtil) WriteFloat64(value float64) *MarshalUtil
- func (util *MarshalUtil) WriteInt16(value int16) *MarshalUtil
- func (util *MarshalUtil) WriteInt32(value int32) *MarshalUtil
- func (util *MarshalUtil) WriteInt64(value int64) *MarshalUtil
- func (util *MarshalUtil) WriteInt8(value int8) *MarshalUtil
- func (util *MarshalUtil) WriteOffset() int
- func (util *MarshalUtil) WriteSeek(offset int)
- func (util *MarshalUtil) WriteTime(timeToWrite time.Time) *MarshalUtil
- func (util *MarshalUtil) WriteUint16(value uint16) *MarshalUtil
- func (util *MarshalUtil) WriteUint32(value uint32) *MarshalUtil
- func (util *MarshalUtil) WriteUint64(value uint64) *MarshalUtil
- func (util *MarshalUtil) WriteUint8(value uint8) *MarshalUtil
- type SimpleBinaryMarshaler
Constants ¶
const BoolSize = 1
BoolSize contains the amount of bytes of a marshaled bool value.
const Float64Size = 8
Float64Size contains the amount of bytes of a marshaled float64 value.
const Int16Size = 2
Int16Size contains the amount of bytes of a marshaled int16 value.
const Int32Size = 4
Int32Size contains the amount of bytes of a marshaled int32 value.
const Int64Size = 8
Int64Size contains the amount of bytes of a marshaled int64 value.
const Int8Size = 1
Int8Size contains the amount of bytes of a marshaled int8 value.
const TimeSize = Int64Size
TimeSize contains the amount of bytes of a marshaled Time value.
const Uint16Size = 2
Uint16Size contains the amount of bytes of a marshaled uint16 value.
const Uint32Size = 4
Uint32Size contains the amount of bytes of a marshaled uint32 value.
const Uint64Size = 8
Uint64Size contains the amount of bytes of a marshaled uint64 value.
const Uint8Size = 1
Uint8Size contains the amount of bytes of a marshaled uint8 value.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MarshalUtil ¶
type MarshalUtil struct {
// contains filtered or unexported fields
}
MarshalUtil is a utility for reading/writing from/to a byte buffer that internally manages the offsets automatically.
func New ¶
func New(args ...interface{}) *MarshalUtil
New creates a new MarshalUtil that can either be used for reading information from a slice of bytes or for writing information to a bytes buffer.
If the MarshalUtil is supposed to read information from a slice of bytes then it receives the slice as its optional parameter.
To create a MarshalUtil for writing information one can either create a fixed size buffer by providing the length of the buffer as the optional parameter or create a dynamically sized buffer by omitting the optional parameter.
func (*MarshalUtil) Bytes ¶
func (util *MarshalUtil) Bytes(clone ...bool) []byte
Bytes returns the internal buffer. If the optional clone parameter is set to true, then the buffer is cloned before being returned.
func (*MarshalUtil) DoneReading ¶
func (util *MarshalUtil) DoneReading() (bool, error)
DoneReading checks if there are any bytes left to read.
func (*MarshalUtil) Parse ¶
func (util *MarshalUtil) Parse(parser func(data []byte) (interface{}, int, error)) (result interface{}, err error)
Parse reads information from the internal buffer by handing over the unread bytes to the passed in parser function.
func (*MarshalUtil) ReadBool ¶
func (util *MarshalUtil) ReadBool() (bool, error)
ReadBool reads a bool value from the internal buffer.
func (*MarshalUtil) ReadByte ¶
func (util *MarshalUtil) ReadByte() (byte, error)
ReadByte reads a byte value from the internal buffer.
func (*MarshalUtil) ReadBytes ¶
func (util *MarshalUtil) ReadBytes(length int, optionalReadOffset ...int) ([]byte, error)
ReadBytes unmarshals the given amount of bytes from the internal read buffer and advances the read offset. If an optionalReadOffset parameter is provided, then the method does not modify the read offset but instead just returns a copy of the bytes in the provided range.
func (*MarshalUtil) ReadFloat64 ¶
func (util *MarshalUtil) ReadFloat64() (float64, error)
ReadFloat64 reads a float64 value from the internal buffer.
func (*MarshalUtil) ReadInt16 ¶
func (util *MarshalUtil) ReadInt16() (int16, error)
ReadInt16 reads an int16 value from the internal buffer.
func (*MarshalUtil) ReadInt32 ¶
func (util *MarshalUtil) ReadInt32() (int32, error)
ReadInt32 reads an int32 value from the internal buffer.
func (*MarshalUtil) ReadInt64 ¶
func (util *MarshalUtil) ReadInt64() (int64, error)
ReadInt64 reads an int64 value from the internal buffer.
func (*MarshalUtil) ReadInt8 ¶
func (util *MarshalUtil) ReadInt8() (int8, error)
ReadInt8 reads an int8 value from the internal buffer.
func (*MarshalUtil) ReadOffset ¶
func (util *MarshalUtil) ReadOffset() int
ReadOffset returns the current read offset of the internal buffer.
func (*MarshalUtil) ReadRemainingBytes ¶
func (util *MarshalUtil) ReadRemainingBytes() []byte
ReadRemainingBytes reads the remaining bytes from the internal buffer.
func (*MarshalUtil) ReadSeek ¶
func (util *MarshalUtil) ReadSeek(offset int)
ReadSeek sets the read offset of the internal buffer. If the offset is negative then it decreases the current read offset instead of setting an absolute value.
func (*MarshalUtil) ReadTime ¶
func (util *MarshalUtil) ReadTime() (result time.Time, err error)
ReadTime reads a Time value from the internal buffer.
func (*MarshalUtil) ReadUint16 ¶
func (util *MarshalUtil) ReadUint16() (uint16, error)
ReadUint16 reads an uint16 value from the internal buffer.
func (*MarshalUtil) ReadUint32 ¶
func (util *MarshalUtil) ReadUint32() (uint32, error)
ReadUint32 reads an uint32 value from the internal buffer.
func (*MarshalUtil) ReadUint64 ¶
func (util *MarshalUtil) ReadUint64() (uint64, error)
ReadUint64 reads an uint64 value from the internal buffer.
func (*MarshalUtil) ReadUint8 ¶
func (util *MarshalUtil) ReadUint8() (uint8, error)
ReadUint8 reads an uint8 value from the internal buffer.
func (*MarshalUtil) Write ¶
func (util *MarshalUtil) Write(object SimpleBinaryMarshaler) *MarshalUtil
Write marshals the given object by writing its Bytes into the underlying buffer.
func (*MarshalUtil) WriteBool ¶
func (util *MarshalUtil) WriteBool(b bool) *MarshalUtil
WriteBool writes a marshaled bool value to the internal buffer.
func (*MarshalUtil) WriteByte ¶
func (util *MarshalUtil) WriteByte(b byte) *MarshalUtil
WriteByte writes a marshaled byte value to the internal buffer.
func (*MarshalUtil) WriteBytes ¶
func (util *MarshalUtil) WriteBytes(bytes []byte) *MarshalUtil
WriteBytes appends the given bytes to the internal buffer. It returns the same MarshalUtil so calls can be chained.
func (*MarshalUtil) WriteFloat64 ¶
func (util *MarshalUtil) WriteFloat64(value float64) *MarshalUtil
WriteFloat64 writes a marshaled float64 value to the internal buffer.
func (*MarshalUtil) WriteInt16 ¶
func (util *MarshalUtil) WriteInt16(value int16) *MarshalUtil
WriteInt16 writes a marshaled int16 value to the internal buffer.
func (*MarshalUtil) WriteInt32 ¶
func (util *MarshalUtil) WriteInt32(value int32) *MarshalUtil
WriteInt32 writes a marshaled int32 value to the internal buffer.
func (*MarshalUtil) WriteInt64 ¶
func (util *MarshalUtil) WriteInt64(value int64) *MarshalUtil
WriteInt64 writes a marshaled int64 value to the internal buffer.
func (*MarshalUtil) WriteInt8 ¶
func (util *MarshalUtil) WriteInt8(value int8) *MarshalUtil
WriteInt8 writes a marshaled int8 value to the internal buffer.
func (*MarshalUtil) WriteOffset ¶
func (util *MarshalUtil) WriteOffset() int
WriteOffset returns the current write offset of the internal buffer.
func (*MarshalUtil) WriteSeek ¶
func (util *MarshalUtil) WriteSeek(offset int)
WriteSeek sets the write offset of the internal buffer. If the offset is negative then it decreases the current write offset instead of setting an absolute value.
func (*MarshalUtil) WriteTime ¶
func (util *MarshalUtil) WriteTime(timeToWrite time.Time) *MarshalUtil
WriteTime writes a marshaled Time value to the internal buffer.
func (*MarshalUtil) WriteUint16 ¶
func (util *MarshalUtil) WriteUint16(value uint16) *MarshalUtil
WriteUint16 writes a marshaled uint16 value to the internal buffer.
func (*MarshalUtil) WriteUint32 ¶
func (util *MarshalUtil) WriteUint32(value uint32) *MarshalUtil
WriteUint32 writes a marshaled uint32 value to the internal buffer.
func (*MarshalUtil) WriteUint64 ¶
func (util *MarshalUtil) WriteUint64(value uint64) *MarshalUtil
WriteUint64 writes a marshaled uint64 value to the internal buffer.
func (*MarshalUtil) WriteUint8 ¶
func (util *MarshalUtil) WriteUint8(value uint8) *MarshalUtil
WriteUint8 writes a marshaled uint8 value to the internal buffer.
type SimpleBinaryMarshaler ¶
type SimpleBinaryMarshaler interface { // Bytes returns a marshaled version of the object. Bytes() []byte }
SimpleBinaryMarshaler represents objects that have a Bytes method for marshaling. In contrast to go's built marshaler interface (encoding.BinaryMarshaler) this interface expect no errors to be returned.