Documentation ¶
Index ¶
- Constants
- Variables
- func AllocateBytes(size int) []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 Int8(data []byte) (int8, error)
- func Int8bytes(data int8) []byte
- func Rune(data []byte) (rune, error)
- func RuneBytes(char rune) []byte
- func String(data []byte) (string, error)
- func StringBytes(s string) []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 Uint8(data []byte) (uint8, error)
- func Uint8bytes(data uint8) []byte
- type BinaryReader
- func (r *BinaryReader) BytesTaken() (bytesTaken int)
- func (r *BinaryReader) Close() error
- func (r *BinaryReader) Read(p []byte) (n int, err error)
- func (r *BinaryReader) ReadBytes(stop byte) (dataTaken []byte, err error)
- func (r *BinaryReader) ReadBytesCount(amount int) (buffer []byte, err error)
- func (r *BinaryReader) ReadHex(amount int) (hexString string, err error)
- func (r *BinaryReader) ReadInt() (int, error)
- func (r *BinaryReader) ReadInt16() (res int16, err error)
- func (r *BinaryReader) ReadInt32() (res int32, err error)
- func (r *BinaryReader) ReadInt64() (res int64, err error)
- func (r *BinaryReader) ReadInt8() (res int8, err error)
- func (r *BinaryReader) ReadObject(target interface{}) error
- func (r *BinaryReader) ReadRune() (res rune, err error)
- func (r *BinaryReader) ReadStringZ() (line string, err error)
- func (r *BinaryReader) ReadUint() (uint, error)
- func (r *BinaryReader) ReadUint16() (res uint16, err error)
- func (r *BinaryReader) ReadUint32() (res uint32, err error)
- func (r *BinaryReader) ReadUint64() (res uint64, err error)
- func (r *BinaryReader) ReadUint8() (res uint8, err error)
- func (r *BinaryReader) ResetBytesTaken()
- type BinaryReaderFrom
- type BinaryWriter
- func (w *BinaryWriter) BytesWritten() (res int)
- func (w BinaryWriter) Close() error
- func (w *BinaryWriter) ResetBytesWritten()
- func (w *BinaryWriter) Write(p []byte) (bytesWritten 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) WriteInt16(data int16) error
- func (w *BinaryWriter) WriteInt32(data int32) error
- func (w *BinaryWriter) WriteInt64(data int64) error
- func (w *BinaryWriter) WriteInt8(data int8) error
- func (w *BinaryWriter) WriteObject(data interface{}) (err error)
- func (w *BinaryWriter) WriteRune(char rune) error
- func (w *BinaryWriter) WriteStringZ(data string) error
- func (w *BinaryWriter) WriteUint(data uint) (err error)
- func (w *BinaryWriter) WriteUint16(data uint16) error
- func (w *BinaryWriter) WriteUint32(data uint32) error
- func (w *BinaryWriter) WriteUint64(data uint64) error
- func (w *BinaryWriter) WriteUint8(data uint8) error
- type BinaryWriterTo
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 RuneSize = 4 // rune 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.
Variables ¶
var ( // Error indicates any binutils errors. Error = errors.New("binutils") // ErrNilPointer indicates nil pointer received when required valid pointer of specified type. ErrNilPointer = fmt.Errorf("%w: nill pointer", Error) // ErrExpected1 returned if expected exactly 1 byte. ErrExpected1 = fmt.Errorf("%w: expected 1 byte", Error) // ErrExpected2 returned if expected exactly 2 bytes. ErrExpected2 = fmt.Errorf("%w: expected 2 bytes", Error) // ErrExpected4 returned if expected exactly 4 bytes. ErrExpected4 = fmt.Errorf("%w: expected 4 bytes", Error) // ErrExpected8 returned if expected exactly 8 bytes. ErrExpected8 = fmt.Errorf("%w: expected 8 bytes", Error) // ErrMinimum1 returned if expected at least 1 byte. ErrMinimum1 = fmt.Errorf("%w: at least 1 byte required", Error) // ErrRequired0T returned if expected 0-byte termination. ErrRequired0T = fmt.Errorf("%w: required 0-terminated string", Error) // ErrDecodeTo returned if decode error. ErrDecodeTo = fmt.Errorf("%w: decode", Error) // ErrRead returned if general read error. ErrRead = fmt.Errorf("%w: read", Error) // ErrClose returned if general close error. ErrClose = fmt.Errorf("%w: close", Error) )
Some predefined errors used during processing.
Functions ¶
func AllocateBytes ¶
AllocateBytes creates a byte slice of required size.
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 Int8 ¶
Int8 translates next byte from buffer into int8 value. Returns error if insufficient bytes in buffer.
func Rune ¶ added in v0.3.0
Rune translates specified 4 bytes into rune value using big-endian bytes order. Returns error if insufficient bytes supplied.
func RuneBytes ¶ added in v0.3.0
RuneBytes returns rune bytes representation using big-endian bytes order.
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 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.
Types ¶
type BinaryReader ¶ added in v0.2.5
type BinaryReader struct {
// contains filtered or unexported fields
}
BinaryReader 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 be present and readable before opening.
func (*BinaryReader) BytesTaken ¶ added in v0.5.0
func (r *BinaryReader) BytesTaken() (bytesTaken int)
BytesTaken returns bytesTaken counter since last ResetBytesTaken invoke or created if never ResetBytesTaken called.
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 len(p) bytes into p. It returns the number of bytes taken (0 <= n <= len(p)) and any error encountered, just calling underlying io.Reader Read method. Note it extends internal taken bytes counter to taken bytes value. Implements io.Reader itself.
func (*BinaryReader) ReadBytes ¶ added in v0.2.5
func (r *BinaryReader) ReadBytes(stop byte) (dataTaken []byte, err 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) (buffer []byte, err error)
ReadBytesCount reads exactly specified amount of bytes. Returns read bytes or error if insufficient bytes count ready to read or any underlying reader error encountered.
func (*BinaryReader) ReadHex ¶ added in v0.2.5
func (r *BinaryReader) ReadHex(amount int) (hexString string, err 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) ReadInt16 ¶ added in v0.2.5
func (r *BinaryReader) ReadInt16() (res int16, err error)
ReadInt16 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() (res int32, err error)
ReadInt32 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() (res int64, err error)
ReadInt64 reads int64 value from underlying reader. Returns int64 value and any error encountered.
func (*BinaryReader) ReadInt8 ¶ added in v0.2.5
func (r *BinaryReader) ReadInt8() (res int8, err error)
ReadInt8 reads int8 value from underlying reader. Returns int8 value and any error encountered.
func (*BinaryReader) ReadObject ¶ added in v0.2.5
func (r *BinaryReader) ReadObject(target interface{}) error
ReadObject reads object data from underlying io.Reader. Returns written bytes count and possible error.
func (*BinaryReader) ReadRune ¶ added in v0.3.0
func (r *BinaryReader) ReadRune() (res rune, err error)
ReadRune reads rune value from underlying io.Reader. Returns rune value and any error encountered.
func (*BinaryReader) ReadStringZ ¶ added in v0.2.5
func (r *BinaryReader) ReadStringZ() (line string, err 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) ReadUint16 ¶ added in v0.2.5
func (r *BinaryReader) ReadUint16() (res uint16, err 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() (res uint32, err 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() (res uint64, err error)
ReadUint64 reads uint64 value from underlying reader. Returns uint64 value and any error encountered.
func (*BinaryReader) ReadUint8 ¶ added in v0.2.5
func (r *BinaryReader) ReadUint8() (res uint8, err error)
ReadUint8 reads uint8 value from underlying reader. Returns uint8 value and any error encountered.
func (*BinaryReader) ResetBytesTaken ¶ added in v0.5.0
func (r *BinaryReader) ResetBytesTaken()
ResetBytesTaken zeroes internal bytes taken counter.
type BinaryReaderFrom ¶ added in v0.2.5
type BinaryReaderFrom interface {
BinaryReadFrom(*BinaryReader) error
}
BinaryReaderFrom interface wraps the BinaryReadFrom method. Implementation method BinaryReadFrom reads implementors data from BinaryReader until its data restored or any error encountered. Returns any error encountered during reading if happened or nil.
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 be created.
func NewBinaryWriter ¶ added in v0.2.5
func NewBinaryWriter(writer io.Writer) *BinaryWriter
NewBinaryWriter wraps existing io.Writer instance into BinaryWriter.
func (*BinaryWriter) BytesWritten ¶ added in v0.3.0
func (w *BinaryWriter) BytesWritten() (res int)
BytesWritten returns written bytes counter value. Note counter can be reset to 0 using ResetBytesWritten.
func (BinaryWriter) Close ¶ added in v0.2.5
func (w BinaryWriter) Close() error
Close closes underlying writer if it implements io.Closer. Returns error if underlying writer is not implements io.Closer.
func (*BinaryWriter) ResetBytesWritten ¶ added in v0.3.0
func (w *BinaryWriter) ResetBytesWritten()
ResetBytesWritten sets written bytes counter to zero.
func (*BinaryWriter) Write ¶ added in v0.2.5
func (w *BinaryWriter) Write(p []byte) (bytesWritten int, err error)
Write simply writes into underlying writer. Note it extends internal written bytes counter to written bytes value. Implements io.Writer.
func (*BinaryWriter) WriteBytes ¶ added in v0.2.5
func (w *BinaryWriter) WriteBytes(data []byte) error
WriteBytes writes byte string into underlying writer. Returns error if written bytes count mismatch specified byte string length or any underlying error if occurs.
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) 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
WriteInt32 writes int32 value into writer as bytes.
func (*BinaryWriter) WriteInt64 ¶ added in v0.2.5
func (w *BinaryWriter) WriteInt64(data int64) error
WriteInt64 writes int64 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) WriteObject ¶ added in v0.2.5
func (w *BinaryWriter) WriteObject(data interface{}) (err error)
WriteObject writes object data into underlying writer. User specified data types data must be one of io.WriterTo, BinaryWriterTo, BinaryUint8, BinaryUint16, BinaryUint32, BinaryUint64, BinaryInt8, BinaryInt16, BinaryInt32, BinaryInt64 or BinaryRune interface implementation. Basic Int[8-64], Uint[8-64] or pointers to it are simply generates bigEndian bytes.
If multiple interfaces implemented first of described order will be used. Use required method directly to fully determined behaviour. Returns error if caused internally. To get written bytes counter use BytesWritten result.
func (*BinaryWriter) WriteRune ¶ added in v0.3.0
func (w *BinaryWriter) WriteRune(char rune) error
WriteRune writes rune value into writer as uint32 bytes.
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) (err error)
WriteUint uint 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
WriteUint64 writes uint64 value into writer as bytes.
func (*BinaryWriter) WriteUint8 ¶ added in v0.2.5
func (w *BinaryWriter) WriteUint8(data uint8) error
WriteUint8 writes uint8 value into writer as bytes.
type BinaryWriterTo ¶ added in v0.2.5
type BinaryWriterTo interface {
BinaryWriteTo(*BinaryWriter) error
}
BinaryWriterTo interface wraps the BinaryWriteTo method. Implementation method BinaryWriteTo writes implementors data into BinaryWriter until all marshalled or any error occurs. Returns any error encountered during writing if happened or nil.