binutils

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 27, 2020 License: MIT Imports: 7 Imported by: 6

Documentation

Index

Constants

View Source
const (
	Int64size  = 8 // int64 size in bytes
	Uint64size = 8 // uint64 size in bytes
	Unt32size  = 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.

View Source
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

	// UsingUint8Indexes defines byte value to store as using uint8 indicator.
	UsingUint8Indexes = uint8(8) // nolint:gomnd    // uint8
	// UsingUint16Indexes defines byte value to store as using uint16 indicator.
	UsingUint16Indexes = uint8(16) // nolint:gomnd    // uint16
	// UsingUint32Indexes defines byte value to store as using uint32 indicator.
	UsingUint32Indexes = uint8(32) // nolint:gomnd    // uint32
	// UsingUint64Indexes defines byte value to store as using uint64 indicator.
	UsingUint64Indexes = uint8(64) // nolint:gomnd    // uint64
)

Variables

This section is empty.

Functions

func AllocateBytes

func AllocateBytes(size int) []byte

AllocateBytes creates a byte slice of required size

func Int16

func Int16(data []byte) (int16, error)

Int16 translates next 2 bytes from buffer into int16 value using big-endian bytes order. Returns error if insufficient bytes in buffer

func Int16bytes

func Int16bytes(data int16) []byte

Int16bytes adds int16 data to buffer using big-endian bytes order

func Int32

func Int32(data []byte) (int32, error)

Int32 translates next 4 bytes from buffer into int32 value using big-endian bytes order. Returns error if insufficient bytes in buffer

func Int32bytes

func Int32bytes(data int32) []byte

Int32bytes adds int32 data to buffer using big-endian bytes order

func Int64

func Int64(data []byte) (int64, error)

Int64 translates next 8 bytes from buffer into int64 value using big-endian bytes order. Returns error if insufficient bytes in buffer

func Int64bytes

func Int64bytes(data int64) []byte

Int64bytes adds uint64 data to buffer using big-endian bytes order

func Int8

func Int8(data []byte) (int8, error)

Int8 translates next byte from buffer into int8 value. Returns error if insufficient bytes in buffer

func Int8bytes

func Int8bytes(data int8) []byte

Int8bytes adds int8 data to buffer

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 NewError

func NewError(format string, args ...interface{}) error

NewError is a default error constructor. Takes format and arguments to make error description using fmt.Sprintf() formatting rules.

func SaveBinary

func SaveBinary(filename string, dict encoding.BinaryMarshaler) error

SaveBinary saves binary data of encoding.BinaryMarshaler implementing object into specified file.

func String

func String(data []byte) (string, error)

String reads a zero-terminated string from []byte sequence Returns error if last byte is not 0

func StringBytes

func StringBytes(s string) []byte

StringBytes makes a zero-terminated string []byte sequence

func Uint16

func Uint16(data []byte) (uint16, error)

Uint16 translates next 2 bytes from buffer into uint16 value using big-endian bytes order. Returns error if insufficient bytes in buffer

func Uint16bytes

func Uint16bytes(data uint16) []byte

Uint16bytes adds uint16 data to buffer using big-endian bytes order

func Uint32

func Uint32(data []byte) (uint32, error)

Uint32 translates next 4 bytes from buffer into uint32 value using big-endian bytes order. Returns error if insufficient bytes in buffer

func Uint32bytes

func Uint32bytes(data uint32) []byte

Uint32bytes adds uint32 data to buffer using big-endian bytes order

func Uint64

func Uint64(data []byte) (uint64, error)

Uint64 translates next 8 bytes from buffer into uint64 value using big-endian bytes order. Returns error if insufficient bytes in buffer

func Uint64bytes

func Uint64bytes(data uint64) []byte

Uint64bytes adds uint64 data to buffer using big-endian bytes order

func Uint8

func Uint8(data []byte) (uint8, error)

Uint8 translates next byte from buffer into uint8 value. Returns error if insufficient bytes in buffer

func Uint8bytes

func Uint8bytes(data uint8) []byte

Uint8bytes adds uint8 data to buffer

Types

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.

type Buffer

type Buffer struct {
	// contains filtered or unexported fields
}

Buffer type implements wrapper to easy marshalling & unmarshalling binary data. Defines some method to get info about stored data and marshaling/unmarshalling helpers.

func NewBuffer

func NewBuffer(data []byte) *Buffer

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) Bytes

func (x *Buffer) Bytes() []byte

Bytes returns copy of current buffer data []bytes.

func (*Buffer) Len

func (x *Buffer) Len() int

Len returns current length of buffer data in bytes.

func (*Buffer) LoadFromFilePath

func (x *Buffer) LoadFromFilePath(filePath string) (int, error)

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

func (x *Buffer) MarshalBinary() (data []byte, err error)

MarshalBinary implementing binary.BinaryMarshaler for Buffer. Simply returns copy of underlying data with always nil error.

func (*Buffer) ReadBytes

func (x *Buffer) ReadBytes(target *[]byte, numBytes int) error

ReadBytes takes required amount of bytes from buffer into target byte slice pointer. Returns nil or possible error.

func (*Buffer) ReadInt16

func (x *Buffer) ReadInt16(target *int16) error

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

func (x *Buffer) ReadInt32(target *int32) error

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

func (x *Buffer) ReadInt64(target *int64) error

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) ReadInt8

func (x *Buffer) ReadInt8(target *int8) error

ReadInt8 translates next byte from buffer into int8 value and place it into target pointer. 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

func (x *Buffer) ReadString(target *string) error

ReadString reads zero-terminated string from buffer.

func (*Buffer) ReadUint16

func (x *Buffer) ReadUint16(target *uint16) error

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

func (x *Buffer) ReadUint32(target *uint32) error

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

func (x *Buffer) ReadUint64(target *uint64) error

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) ReadUint8

func (x *Buffer) ReadUint8(target *uint8) error

ReadUint8 translates next byte from buffer into uint8 value and place it into target pointer. Returns nil or error.

func (*Buffer) SaveIntoFilePath

func (x *Buffer) SaveIntoFilePath(filePath string) (int, error)

SaveIntoFilePath unloads buffer data into binary file. Target file will be created even if buffer is empty.

func (*Buffer) UnmarshalBinary

func (x *Buffer) UnmarshalBinary(data []byte) error

UnmarshalBinary implements binary.BinaryUnmarshaler. Silently replaces underlying data with new data.

func (*Buffer) WriteBytes

func (x *Buffer) WriteBytes(data []byte) (int, error)

WriteBytes adds data from byte slice into buffer. Returns written bytes count and nil or possible error.

func (*Buffer) WriteInt16

func (x *Buffer) WriteInt16(data int16) (int, error)

WriteInt16 writes int16 value into buffer using big-endian bytes order. Returns written bytes count and possible error.

func (*Buffer) WriteInt32

func (x *Buffer) WriteInt32(data int32) (int, error)

WriteInt32 writes int32 value into buffer using big-endian bytes order. Returns written bytes count and possible error.

func (*Buffer) WriteInt64

func (x *Buffer) WriteInt64(data int64) (int, error)

WriteInt64 writes int64 value into buffer using big-endian bytes order. Returns written bytes count and possible error.

func (*Buffer) WriteInt8

func (x *Buffer) WriteInt8(data int8) (int, error)

WriteInt8 writes int8 value into buffer as byte. 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

func (x *Buffer) WriteString(data string) (int, error)

WriteString adds binary representation of string as zero-terminated string.

func (*Buffer) WriteUint16

func (x *Buffer) WriteUint16(data uint16) (int, error)

WriteUint16 writes uint16 value into buffer using big-endian bytes order. Returns written bytes count and possible error.

func (*Buffer) WriteUint32

func (x *Buffer) WriteUint32(data uint32) (int, error)

WriteUint32 writes uint32 value into buffer using big-endian bytes order. Returns written bytes count and possible error.

func (*Buffer) WriteUint64

func (x *Buffer) WriteUint64(data uint64) (int, error)

WriteUint64 writes uint64 value into buffer using big-endian bytes order. Returns written bytes count and possible error.

func (*Buffer) WriteUint8

func (x *Buffer) WriteUint8(data uint8) (int, error)

WriteUint8 writes uint8 value into buffer as byte. Returns written bytes count and possible error.

type BufferUnmarshaler

type BufferUnmarshaler interface {
	UnmarshalFromBuffer(*Buffer) error
}

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.

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error type implements error interface and used in package routines.

func WrapError

func WrapError(wrap error, format string, args ...interface{}) *Error

WrapError creates new error, wrapping underlying error with formatted string.

func (Error) Error

func (e Error) Error() string

Error returns formatted error string. Implements error interface.

func (Error) GoString

func (e Error) GoString() string

GoString returns formatted error string prefixes with package name and type. Implements GoStringer.

Jump to

Keyboard shortcuts

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