Documentation
¶
Index ¶
- Constants
- Variables
- func AllocateBytes(size int) []byte
- func Int8(data []byte) (int8, error)
- func Int8bytes(data int8) []byte
- func Int16(data []byte) (int16, error)
- func Int16bytes(data int16) []byte
- func Int32(data []byte) (int32, error)
- func Int32bytes(data int32) []byte
- func Int64(data []byte) (int64, error)
- func Int64bytes(data int64) []byte
- func LoadBinary(filename string, dict BufferUnmarshaler) error
- func ReadUint64FromBufferUsingBits(target *uint64, buffer *Buffer, usingBits BitsPerIndex) error
- func SaveBinary(filename string, dict encoding.BinaryMarshaler) error
- func String(data []byte) (string, error)
- func StringBytes(s string) []byte
- func Uint8(data []byte) (uint8, error)
- func Uint8bytes(data uint8) []byte
- func Uint16(data []byte) (uint16, error)
- func Uint16bytes(data uint16) []byte
- func Uint32(data []byte) (uint32, error)
- func Uint32bytes(data uint32) []byte
- func Uint64(data []byte) (uint64, error)
- func Uint64bytes(data uint64) []byte
- func WriteUint64ToBufferUsingBits(value uint64, buffer *Buffer, usingBits BitsPerIndex) (int, error)
- type BinaryReader
- func (r BinaryReader) Close() error
- func (r BinaryReader) Read(p []byte) (n int, err error)
- func (r BinaryReader) ReadBytes(stop byte) ([]byte, error)
- func (r BinaryReader) ReadBytesCount(amount int) ([]byte, error)
- func (r BinaryReader) ReadHex(amount int) (string, error)
- func (r BinaryReader) ReadInt() (int, error)
- func (r BinaryReader) ReadInt8() (int8, error)
- func (r BinaryReader) ReadInt16() (int16, error)
- func (r BinaryReader) ReadInt32() (int32, error)
- func (r BinaryReader) ReadInt64() (int64, error)
- func (r BinaryReader) ReadObject(target interface{}) error
- func (r BinaryReader) ReadStringZ() (string, error)
- func (r BinaryReader) ReadUint() (uint, error)
- func (r BinaryReader) ReadUint8() (uint8, error)
- func (r BinaryReader) ReadUint16() (uint16, error)
- func (r BinaryReader) ReadUint32() (uint32, error)
- func (r BinaryReader) ReadUint64() (uint64, error)
- type BinaryReaderFrom
- type BinaryWriter
- func (w BinaryWriter) Close() error
- func (w BinaryWriter) Write(p []byte) (n int, err error)
- func (w BinaryWriter) WriteBytes(data []byte) error
- func (w BinaryWriter) WriteHex(hexString string) error
- func (w BinaryWriter) WriteInt(data int) error
- func (w BinaryWriter) WriteInt8(data int8) error
- func (w BinaryWriter) WriteInt16(data int16) error
- func (w BinaryWriter) WriteInt32(data int32) error
- func (w BinaryWriter) WriteInt64(data int64) error
- func (w BinaryWriter) WriteObject(data interface{}) error
- func (w BinaryWriter) WriteStringZ(data string) error
- func (w BinaryWriter) WriteUint(data uint) error
- func (w BinaryWriter) WriteUint8(data uint8) error
- func (w BinaryWriter) WriteUint16(data uint16) error
- func (w BinaryWriter) WriteUint32(data uint32) error
- func (w BinaryWriter) WriteUint64(data uint64) error
- type BinaryWriterTo
- type BitsPerIndex
- type Buffer
- func (x *Buffer) Bytes() []byte
- func (x *Buffer) Hex() string
- func (x *Buffer) Len() int
- func (x *Buffer) LoadFromFilePath(filePath string) (int, error)
- func (x *Buffer) MarshalBinary() (data []byte, err error)
- func (x *Buffer) ReadBytes(target *[]byte, numBytes int) error
- func (x *Buffer) ReadHex(target *string, numBytes int) error
- func (x *Buffer) ReadInt8(target *int8) error
- func (x *Buffer) ReadInt16(target *int16) error
- func (x *Buffer) ReadInt32(target *int32) error
- func (x *Buffer) ReadInt64(target *int64) error
- func (x *Buffer) ReadObject(data BufferUnmarshaler) error
- func (x *Buffer) ReadObjectBytes(data encoding.BinaryUnmarshaler, bytes int) error
- func (x *Buffer) ReadString(target *string) error
- func (x *Buffer) ReadUint8(target *uint8) error
- func (x *Buffer) ReadUint16(target *uint16) error
- func (x *Buffer) ReadUint32(target *uint32) error
- func (x *Buffer) ReadUint64(target *uint64) error
- func (x *Buffer) SaveIntoFilePath(filePath string) (int, error)
- func (x *Buffer) UnmarshalBinary(data []byte) error
- func (x *Buffer) WriteBytes(data []byte) (int, error)
- func (x *Buffer) WriteHex(hexString string) (int, error)
- func (x *Buffer) WriteInt8(data int8) (int, error)
- func (x *Buffer) WriteInt16(data int16) (int, error)
- func (x *Buffer) WriteInt32(data int32) (int, error)
- func (x *Buffer) WriteInt64(data int64) (int, error)
- func (x *Buffer) WriteObject(data encoding.BinaryMarshaler) (int, error)
- func (x *Buffer) WriteString(data string) (int, error)
- func (x *Buffer) WriteUint8(data uint8) (int, error)
- func (x *Buffer) WriteUint16(data uint16) (int, error)
- func (x *Buffer) WriteUint32(data uint32) (int, error)
- func (x *Buffer) WriteUint64(data uint64) (int, error)
- type BufferUnmarshaler
Constants ¶
const ( Int64size = 8 // int64 size in bytes Uint64size = 8 // uint64 size in bytes Int32size = 4 // int32 size in bytes Uint32size = 4 // uint32 size in bytes Int16size = 2 // int16 size in bytes Uint16size = 2 // uint16 size in bytes Int8size = 1 // int8 size in bytes Uint8size = 1 // uint8 size in bytes )
Some useful constants.
const ( // Use8bit defines size ID for list indexes having no more than 256 values. Use8bit BitsPerIndex = iota // uint8 // Use16bit defines size ID for list indexes having no more than 65536 values. Use16bit // uint16 // Use32bit defines size ID for list indexes having no more than 4294967296 values. Use32bit // uint32 // Use64bit defines size ID for list indexes having no more than 1,8 x 10**19 values. Use64bit // uint64 // BytesInUint8 defines bytes amount required to store uint16 values. BytesInUint8 = 1 // BytesInUint16 defines bytes amount required to store uint16 values. BytesInUint16 = 2 // BytesInUint32 defines bytes amount required to store uint32 values. BytesInUint32 = 4 // BytesInUint64 defines bytes amount required to store uint32 values. BytesInUint64 = 8 // UsingUint8Indexes defines byte value to store as using uint8 indicator. UsingUint8Indexes = uint8(BytesInUint8 * bitsPerByte) // uint8 // UsingUint16Indexes defines byte value to store as using uint16 indicator. UsingUint16Indexes = uint8(BytesInUint16 * bitsPerByte) // uint16 // UsingUint32Indexes defines byte value to store as using uint32 indicator. UsingUint32Indexes = uint8(BytesInUint32 * bitsPerByte) // uint32 // UsingUint64Indexes defines byte value to store as using uint64 indicator. UsingUint64Indexes = uint8(BytesInUint64 * bitsPerByte) // uint64 )
Variables ¶
var ( // ErrExpected1 returned if expected exactly 1 byte. ErrExpected1 = errors.New("expected 1 byte") // ErrExpected2 returned if expected exactly 2 bytes. ErrExpected2 = errors.New("expected 2 bytes") // ErrExpected4 returned if expected exactly 4 bytes. ErrExpected4 = errors.New("expected 4 bytes") // ErrExpected8 returned if expected exactly 8 bytes. ErrExpected8 = errors.New("expected 8 bytes") // ErrMinimum1 returned if expected at least 1 byte. ErrMinimum1 = errors.New("at least 1 byte required") // ErrRequired0T returned if expected 0-byte termination. ErrRequired0T = errors.New("required 0-terminated string") // ErrSizing returned if sizing unexpected. ErrSizing = errors.New("unexpected sizing") // ErrNegativeLen returned if negative length. ErrNegativeLen = errors.New("negative length") // ErrOverflowBy returned if value overflows type. ErrOverflowBy = errors.New("type overflow") // ErrBuffer returned if general buffer error. ErrBuffer = errors.New("buffer") // ErrDecodeTo returned if decode error. ErrDecodeTo = errors.New("decode") // ErrMissedData returned if some bytes missed. ErrMissedData = errors.New("insufficient bytes") // ErrExtraData returned if extra bytes after decoding means error. ErrExtraData = errors.New("extra bytes") // ErrRead returned if general read error. ErrRead = errors.New("read") // ErrWrite returned if general write error. ErrWrite = errors.New("write") // ErrClose returned if general close error. ErrClose = errors.New("close") )
Some predefined errors used during processing.
Functions ¶
func AllocateBytes ¶
AllocateBytes creates a byte slice of required size.
func Int8 ¶
Int8 translates next byte from buffer into int8 value. Returns error if insufficient bytes in buffer.
func Int16 ¶
Int16 translates next 2 bytes from buffer into int16 value using big-endian bytes order. Returns error if insufficient bytes in buffer.
func Int16bytes ¶
Int16bytes adds int16 data to buffer using big-endian bytes order.
func Int32 ¶
Int32 translates next 4 bytes from buffer into int32 value using big-endian bytes order. Returns error if insufficient bytes in buffer.
func Int32bytes ¶
Int32bytes adds int32 data to buffer using big-endian bytes order.
func Int64 ¶
Int64 translates next 8 bytes from buffer into int64 value using big-endian bytes order. Returns error if insufficient bytes in buffer.
func Int64bytes ¶
Int64bytes adds uint64 data to buffer using big-endian bytes order.
func LoadBinary ¶
func LoadBinary(filename string, dict BufferUnmarshaler) error
LoadBinary adds binary data from specified file into target BufferUnmarshaler implementing object Returns error if any file path resolution problem or file data empty or some binary data was not decoded.
func ReadUint64FromBufferUsingBits ¶ added in v0.2.2
func ReadUint64FromBufferUsingBits(target *uint64, buffer *Buffer, usingBits BitsPerIndex) error
ReadUint64FromBufferUsingBits reads value of requested bits wide from buffer into target uint64 pointer. Error will not not nil if unexpected bit width specified or read from buffer failed.
func SaveBinary ¶
func SaveBinary(filename string, dict encoding.BinaryMarshaler) error
SaveBinary saves binary data of encoding.BinaryMarshaler implementing object into specified file.
func String ¶
String reads a zero-terminated string from []byte sequence Returns error if last byte is not 0.
func StringBytes ¶
StringBytes makes a zero-terminated string []byte sequence.
func Uint8 ¶
Uint8 translates next byte from buffer into uint8 value. Returns error if insufficient bytes in buffer.
func Uint16 ¶
Uint16 translates next 2 bytes from buffer into uint16 value using big-endian bytes order. Returns error if insufficient bytes in buffer.
func Uint16bytes ¶
Uint16bytes adds uint16 data to buffer using big-endian bytes order.
func Uint32 ¶
Uint32 translates next 4 bytes from buffer into uint32 value using big-endian bytes order. Returns error if insufficient bytes in buffer.
func Uint32bytes ¶
Uint32bytes adds uint32 data to buffer using big-endian bytes order.
func Uint64 ¶
Uint64 translates next 8 bytes from buffer into uint64 value using big-endian bytes order. Returns error if insufficient bytes in buffer.
func Uint64bytes ¶
Uint64bytes adds uint64 data to buffer using big-endian bytes order.
func WriteUint64ToBufferUsingBits ¶ added in v0.2.2
func WriteUint64ToBufferUsingBits(value uint64, buffer *Buffer, usingBits BitsPerIndex) (int, error)
WriteUint64ToBufferUsingBits writes uint64 value into buffer using only required bits. Returns written bytes count and error if any. Error not nil if value exceeds requested bits width max value.
Types ¶
type BinaryReader ¶ added in v0.2.5
type BinaryReader struct {
// contains filtered or unexported fields
}
BinaryWriter implements binary writing for various data types into file writer.
func NewBinaryReader ¶ added in v0.2.5
func NewBinaryReader(source io.Reader) *BinaryReader
NewBinaryReader wraps existing io.Reader into BinaryReader.
func OpenFile ¶ added in v0.2.5
func OpenFile(filePath string) (*BinaryReader, error)
OpenFile opens specified file path and returns BinaryReader wrapping it. Target filePath must exists and readable before opening.
func (BinaryReader) Close ¶ added in v0.2.5
func (r BinaryReader) Close() error
Close closes underlying reader. Implements io.Closer. Returns error if underlying reader not implements io.Closer.
func (BinaryReader) Read ¶ added in v0.2.5
func (r BinaryReader) Read(p []byte) (n int, err error)
Read reads up to to len(p) bytes into p. It returns the number of bytes read (0 <= n <= len(p)) and any error encountered, just calling underlying io.Reader Read method. Implements io.Reader itself.
func (BinaryReader) ReadBytes ¶ added in v0.2.5
func (r BinaryReader) ReadBytes(stop byte) ([]byte, error)
ReadBytes reads bytes sequence until the first occurrence of stop byte in the input. Returns a bytes slice containing the data up to and including the delimiter. If ReadBytes encounters an error before finding a delimiter, it returns the data read before the error and the error itself (often io.EOF).
func (BinaryReader) ReadBytesCount ¶ added in v0.2.5
func (r BinaryReader) ReadBytesCount(amount int) ([]byte, error)
ReadBytesCount reads exactly specified amount of bytes. Returns read bytes or error if insufficient bytes count ready to read or any underlying buffer error encountered.
func (BinaryReader) ReadHex ¶ added in v0.2.5
func (r BinaryReader) ReadHex(amount int) (string, error)
ReadHex reads exactly specified amount of bytes and return hex representation string for received bytes. Returns underlying reader errors encountered.
func (BinaryReader) ReadInt ¶ added in v0.2.5
func (r BinaryReader) ReadInt() (int, error)
ReadInt reads int value from underlying reader. Returns int value and any error encountered.
func (BinaryReader) ReadInt8 ¶ added in v0.2.5
func (r BinaryReader) ReadInt8() (int8, error)
ReadUint8 reads int8 value from underlying reader. Returns int8 value and any error encountered.
func (BinaryReader) ReadInt16 ¶ added in v0.2.5
func (r BinaryReader) ReadInt16() (int16, error)
ReadUint16 reads int16 value from underlying reader. Returns int16 value and any error encountered.
func (BinaryReader) ReadInt32 ¶ added in v0.2.5
func (r BinaryReader) ReadInt32() (int32, error)
ReadUint32 reads int32 value from underlying reader. Returns int32 value and any error encountered.
func (BinaryReader) ReadInt64 ¶ added in v0.2.5
func (r BinaryReader) ReadInt64() (int64, error)
ReadUint64 reads int64 value from underlying reader. Returns int64 value and any error encountered.
func (BinaryReader) ReadObject ¶ added in v0.2.5
func (r BinaryReader) ReadObject(target interface{}) error
WriteObject add encoding.BinaryMarshaler binary data into buffer. Returns written bytes count and possible error.
func (BinaryReader) ReadStringZ ¶ added in v0.2.5
func (r BinaryReader) ReadStringZ() (string, error)
ReadStringZ reads zero-terminated string from underlying reader.
func (BinaryReader) ReadUint ¶ added in v0.2.5
func (r BinaryReader) ReadUint() (uint, error)
ReadUint reads uint value from underlying reader. Returns uint value and any error encountered.
func (BinaryReader) ReadUint8 ¶ added in v0.2.5
func (r BinaryReader) ReadUint8() (uint8, error)
ReadUint8 reads uint8 value from underlying reader. Returns uint8 value and any error encountered.
func (BinaryReader) ReadUint16 ¶ added in v0.2.5
func (r BinaryReader) ReadUint16() (uint16, error)
ReadUint16 reads uint16 value from underlying reader. Returns uint16 value and any error encountered.
func (BinaryReader) ReadUint32 ¶ added in v0.2.5
func (r BinaryReader) ReadUint32() (uint32, error)
ReadUint32 reads uint32 value from underlying reader. Returns uint32 value and any error encountered.
func (BinaryReader) ReadUint64 ¶ added in v0.2.5
func (r BinaryReader) ReadUint64() (uint64, error)
ReadUint64 reads uint64 value from underlying reader. Returns uint64 value and any error encountered.
type BinaryReaderFrom ¶ added in v0.2.5
type BinaryReaderFrom interface {
BinaryReadFrom(BinaryReader) (n int64, err error)
}
BinaryReaderFrom is the interface that wraps the BinaryReadFrom method.
BinaryReadFrom reads implementation data from binary until its data restored or any error encountered. The return value n is the number of bytes taken from reader. Any error except io.EOF encountered during the read is also returned.
type BinaryWriter ¶ added in v0.2.5
type BinaryWriter struct {
// contains filtered or unexported fields
}
BinaryWriter implements binary writing for various data types into file writer.
func CreateFile ¶ added in v0.2.5
func CreateFile(filePath string) (*BinaryWriter, error)
CreateFile creates file and wrap file writer into BinaryWriter. Target file will created.
func NewBinaryWriter ¶ added in v0.2.5
func NewBinaryWriter(writer io.Writer) *BinaryWriter
NewBinaryWriter wraps existing io.Writer into BinaryWriter.
func (BinaryWriter) Close ¶ added in v0.2.5
func (w BinaryWriter) Close() error
Close closes underlying writer. Implements io.Closer. Returns error if underlying writer is not implements io.Closer.
func (BinaryWriter) Write ¶ added in v0.2.5
func (w BinaryWriter) Write(p []byte) (n int, err error)
Write simply writes into underlying writer. Implements io.Writer.
func (BinaryWriter) WriteBytes ¶ added in v0.2.5
func (w BinaryWriter) WriteBytes(data []byte) error
WriteStringZ writes byte string into underlying writer.
func (BinaryWriter) WriteHex ¶ added in v0.2.5
func (w BinaryWriter) WriteHex(hexString string) error
WriteHex adds byte string defined by hex string into writer.
func (BinaryWriter) WriteInt ¶ added in v0.2.5
func (w BinaryWriter) WriteInt(data int) error
WriteInt int value into writer as bytes.
func (BinaryWriter) WriteInt8 ¶ added in v0.2.5
func (w BinaryWriter) WriteInt8(data int8) error
WriteInt8 writes int8 value into writer as byte.
func (BinaryWriter) WriteInt16 ¶ added in v0.2.5
func (w BinaryWriter) WriteInt16(data int16) error
WriteInt16 writes int16 value into writer as bytes.
func (BinaryWriter) WriteInt32 ¶ added in v0.2.5
func (w BinaryWriter) WriteInt32(data int32) error
WriteInt32writes int32 value into writer as bytes.
func (BinaryWriter) WriteInt64 ¶ added in v0.2.5
func (w BinaryWriter) WriteInt64(data int64) error
WriteInt64writes int64 value into writer as bytes.
func (BinaryWriter) WriteObject ¶ added in v0.2.5
func (w BinaryWriter) WriteObject(data interface{}) error
WriteObject add encoding.BinaryMarshaler binary data into buffer. Returns written bytes count and possible error.
func (BinaryWriter) WriteStringZ ¶ added in v0.2.5
func (w BinaryWriter) WriteStringZ(data string) error
WriteStringZ writes string bytes into underlying writer as Zero-terminated string.
func (BinaryWriter) WriteUint ¶ added in v0.2.5
func (w BinaryWriter) WriteUint(data uint) error
WriteInt uint value into writer as bytes.
func (BinaryWriter) WriteUint8 ¶ added in v0.2.5
func (w BinaryWriter) WriteUint8(data uint8) error
WriteUint16 writes uint8 value into writer as bytes.
func (BinaryWriter) WriteUint16 ¶ added in v0.2.5
func (w BinaryWriter) WriteUint16(data uint16) error
WriteUint16 writes uint16 value into writer as bytes.
func (BinaryWriter) WriteUint32 ¶ added in v0.2.5
func (w BinaryWriter) WriteUint32(data uint32) error
WriteUint32 writes uint16 value into writer as bytes.
func (BinaryWriter) WriteUint64 ¶ added in v0.2.5
func (w BinaryWriter) WriteUint64(data uint64) error
WriteUint32 writes uint16 value into writer as bytes.
type BinaryWriterTo ¶ added in v0.2.5
type BinaryWriterTo interface {
BinaryWriteTo(BinaryWriter) (n int64, err error)
}
BinaryWriterTo is the interface that wraps the BinaryWriteTo method.
BinaryWriteTo writes implementors data into writer until marshalled or any error occurs. The return value n is the number of bytes written. Any error encountered during the write is also returned.
type BitsPerIndex ¶
type BitsPerIndex int
BitsPerIndex defines index values size ID for numbered lists. Allows to detect and use minimal required standard type for list indexes when marshalling & unmarshalling. Only uint8 (byte), uint16 (2 bytes), uint32 (4 bytes) and uint64 (8 bytes) supported.
func CalculateUseBitsPerIndex ¶
func CalculateUseBitsPerIndex(sliceLen int, reserveNil bool) (BitsPerIndex, error)
CalculateUseBitsPerIndex returns required index value size for requested slice length. If reserve not set, calculates size using all possible values. If reserve is true, calculates size using size bounds reserving 1 value for store nil as max possible value of this size or store nil as 0 to use 1-based index.
func (BitsPerIndex) MarshalBinary ¶
func (b BitsPerIndex) MarshalBinary() (data []byte, err error)
MarshalBinary makes a byte representation of known type BitsPerIndex int constant. Returns 1 byte with 8, 16, 32 or 64 value or error if unknown BitsPerIndex marshalled.
func (*BitsPerIndex) UnmarshalBinary ¶
func (b *BitsPerIndex) UnmarshalBinary(data []byte) error
UnmarshalBinary restores BitsPerIndex value from byte sequence. Requires exactly 1 byte with predefined values 8, 16, 32 or 64. Returns error if unexpected value supplied or data length not equals 1.
func (*BitsPerIndex) UnmarshalFromBuffer ¶ added in v0.2.3
func (b *BitsPerIndex) UnmarshalFromBuffer(buffer *Buffer) error
UnmarshalFromBuffer takes byte value from buffer and translates it into correct BitsPerIndex constant. Implements BufferUnmarshaler.
type Buffer ¶
type Buffer struct {
// contains filtered or unexported fields
}
Buffer type implements wrapper to easy marshalling & unmarshalling binary data into byte strings. Defines some method to get info about stored data and marshaling/unmarshalling helpers.
func NewBuffer ¶
NewBuffer is a default constructor to create Buffer. It requires data argument to init underlying data. To make new empty buffer use:
buffer := binaries.NewBuffer([]byte{})
To make new buffer with predefined data of []byte use:
buffer := binaries.NewBuffer(data)
func NewEmptyBuffer ¶
func NewEmptyBuffer() *Buffer
NewEmptyBuffer is a shorthand to create new empty Buffer with binaries.NewBuffer([]byte{}).
func (*Buffer) Hex ¶ added in v0.2.2
Hex returns current buffer data as hexadecimal string. Does not changes buffer content. Returns nil or possible error.
func (*Buffer) LoadFromFilePath ¶
LoadFromFilePath loads additional bytes from file. Bytes will appended to the end of current data. NOTE: If buffer is not empty, it will not overwritten but extended with file data.
func (*Buffer) MarshalBinary ¶
MarshalBinary implementing binary.BinaryMarshaler for Buffer. Simply returns copy of underlying data with always nil error.
func (*Buffer) ReadBytes ¶
ReadBytes takes required amount of bytes from buffer into target byte slice pointer. Returns nil or possible error.
func (*Buffer) ReadHex ¶ added in v0.2.2
ReadHex takes requested amount bytes and places result into hexadecimal string pointer. Returns nil or possible error.
func (*Buffer) ReadInt8 ¶
ReadInt8 translates next byte from buffer into int8 value and place it into target pointer. Returns nil or error.
func (*Buffer) ReadInt16 ¶
ReadInt16 translates next 2 bytes from buffer into int16 value and place it into target pointer. It uses big-endian byte order. Returns nil or error.
func (*Buffer) ReadInt32 ¶
ReadInt32 translates next 4 bytes from buffer into int32 value and place it into target pointer. It uses big-endian byte order. Returns nil or error.
func (*Buffer) ReadInt64 ¶
ReadInt64 translates next 4 bytes from buffer into int64 value and place it into target pointer. It uses big-endian byte order. Returns nil or error.
func (*Buffer) ReadObject ¶
func (x *Buffer) ReadObject(data BufferUnmarshaler) error
ReadObject allows BufferUnmarshaler instances to take its bytes themselves. Returns nil or possible error.
func (*Buffer) ReadObjectBytes ¶
func (x *Buffer) ReadObjectBytes(data encoding.BinaryUnmarshaler, bytes int) error
ReadObjectBytes provides expected bytes count into encoding.BinaryUnmarshaler implementations UnmarshalBinary method. It uses same interface as another read methods in buffer. Returns nil or possible error.
func (*Buffer) ReadString ¶
ReadString reads zero-terminated string from buffer.
func (*Buffer) ReadUint8 ¶
ReadUint8 translates next byte from buffer into uint8 value and place it into target pointer. Returns nil or error.
func (*Buffer) ReadUint16 ¶
ReadUint16 translates next 2 bytes from buffer into uint16 value and place it into target pointer. It uses big-endian byte order. Returns nil or error.
func (*Buffer) ReadUint32 ¶
ReadUint32 translates next 4 bytes from buffer into uint32 value and place it into target pointer. It uses big-endian byte order. Returns nil or error.
func (*Buffer) ReadUint64 ¶
ReadUint64 translates next 4 bytes from buffer into uint64 value and place it into target pointer. It uses big-endian byte order. Returns nil or error.
func (*Buffer) SaveIntoFilePath ¶
SaveIntoFilePath unloads buffer data into binary file. Target file will be created even if buffer is empty.
func (*Buffer) UnmarshalBinary ¶
UnmarshalBinary implements binary.BinaryUnmarshaler. Silently replaces underlying data with new data.
func (*Buffer) WriteBytes ¶
WriteBytes adds data from byte slice into buffer. Returns written bytes count and nil or possible error.
func (*Buffer) WriteHex ¶ added in v0.2.2
WriteHex adds data defined by hex string into buffer. Returns written bytes count and nil or possible error.
func (*Buffer) WriteInt8 ¶
WriteInt8 writes int8 value into buffer as byte. Returns written bytes count and possible error.
func (*Buffer) WriteInt16 ¶
WriteInt16 writes int16 value into buffer using big-endian bytes order. Returns written bytes count and possible error.
func (*Buffer) WriteInt32 ¶
WriteInt32 writes int32 value into buffer using big-endian bytes order. Returns written bytes count and possible error.
func (*Buffer) WriteInt64 ¶
WriteInt64 writes int64 value into buffer using big-endian bytes order. Returns written bytes count and possible error.
func (*Buffer) WriteObject ¶
func (x *Buffer) WriteObject(data encoding.BinaryMarshaler) (int, error)
WriteObject add encoding.BinaryMarshaler binary data into buffer. Returns written bytes count and possible error.
func (*Buffer) WriteString ¶
WriteString adds binary representation of string as zero-terminated string.
func (*Buffer) WriteUint8 ¶
WriteUint8 writes uint8 value into buffer as byte. Returns written bytes count and possible error.
func (*Buffer) WriteUint16 ¶
WriteUint16 writes uint16 value into buffer using big-endian bytes order. Returns written bytes count and possible error.
func (*Buffer) WriteUint32 ¶
WriteUint32 writes uint32 value into buffer using big-endian bytes order. Returns written bytes count and possible error.
type BufferUnmarshaler ¶
BufferUnmarshaler defines interface to objects able to unmarshal itself from binary buffer. Such objects should read only own bytes from buffer leaving extra bytes intact for others.