Documentation
¶
Overview ¶
Package binaryio provides a wrapper to encoding/binary to provide a concise API.
Numbers are translated by reading and writing fixed-size values. A fixed-size value is either a fixed-size arithmetic type (bool, int8, uint8, int16, ...) or an array only fixed-size values.
This package is intended for decoding and encoding existing binary formats and is not written as a high performance serializer deserializer.
Index ¶
- Variables
- func Size(value interface{}) int
- type BinaryBufferReader
- type BinaryBufferWriter
- type BinaryReader
- func (reader BinaryReader) Read(value interface{}) error
- func (reader BinaryReader) ReadByte() (byte, error)
- func (reader BinaryReader) ReadBytes(expected int) ([]byte, error)
- func (reader BinaryReader) ReadInt16() (int16, error)
- func (reader BinaryReader) ReadInt16s(expected int) ([]int16, error)
- func (reader BinaryReader) ReadInt32() (int32, error)
- func (reader BinaryReader) ReadInt32s(expected int) ([]int32, error)
- func (reader BinaryReader) ReadInt64() (int64, error)
- func (reader BinaryReader) ReadInt64s(expected int) ([]int64, error)
- func (reader BinaryReader) ReadUint16() (uint16, error)
- func (reader BinaryReader) ReadUint16s(expected int) ([]uint16, error)
- func (reader BinaryReader) ReadUint32() (uint32, error)
- func (reader BinaryReader) ReadUint32s(expected int) ([]uint32, error)
- func (reader BinaryReader) ReadUint64() (uint64, error)
- func (reader BinaryReader) ReadUint64s(expected int) ([]uint64, error)
- func (reader BinaryReader) Skip(count int) error
- type BinaryWriter
- func (writer BinaryWriter) Write(value interface{}) error
- func (writer BinaryWriter) WriteByte(b byte) error
- func (writer BinaryWriter) WriteBytes(bytes []byte) error
- func (writer BinaryWriter) WriteInt16(value int16) error
- func (writer BinaryWriter) WriteInt16s(values []int16) error
- func (writer BinaryWriter) WriteInt32(value int32) error
- func (writer BinaryWriter) WriteInt32s(values []int32) error
- func (writer BinaryWriter) WriteInt64(value int64) error
- func (writer BinaryWriter) WriteInt64s(values []int64) error
- func (writer BinaryWriter) WriteUint16(value uint16) error
- func (writer BinaryWriter) WriteUint16s(values []uint16) error
- func (writer BinaryWriter) WriteUint32(value uint32) error
- func (writer BinaryWriter) WriteUint32s(values []uint32) error
- func (writer BinaryWriter) WriteUint64(value uint64) error
- func (writer BinaryWriter) WriteUint64s(values []uint64) error
- type IBinaryBufferReader
- type IBinaryBufferWriter
- type IBinaryReader
- type IBinaryWriter
Constants ¶
This section is empty.
Variables ¶
var ErrShortRead = errors.New("short read")
Functions ¶
Types ¶
type BinaryBufferReader ¶
type BinaryBufferReader struct { BinaryReader // contains filtered or unexported fields }
func (BinaryBufferReader) Len ¶
func (reader BinaryBufferReader) Len() int
Return the number of bytes remaining in the buffer
type BinaryBufferWriter ¶
type BinaryBufferWriter struct { BinaryWriter // contains filtered or unexported fields }
func (BinaryBufferWriter) Bytes ¶
func (writer BinaryBufferWriter) Bytes() []byte
Return the byte representation of the underlying buffer
func (BinaryBufferWriter) Len ¶
func (writer BinaryBufferWriter) Len() int
Return the length of the byte representation of the underlying buffer
type BinaryReader ¶
type BinaryReader struct {
// contains filtered or unexported fields
}
func (BinaryReader) Read ¶
func (reader BinaryReader) Read(value interface{}) error
Read any fixed size value. The parameter should be a pointer to the underlying type.
// var value uint32 // if err := reader.Read(&value); err != nil { // ... // }
func (BinaryReader) ReadByte ¶
func (reader BinaryReader) ReadByte() (byte, error)
func (BinaryReader) ReadInt16 ¶
func (reader BinaryReader) ReadInt16() (int16, error)
func (BinaryReader) ReadInt16s ¶
func (reader BinaryReader) ReadInt16s(expected int) ([]int16, error)
func (BinaryReader) ReadInt32 ¶
func (reader BinaryReader) ReadInt32() (int32, error)
func (BinaryReader) ReadInt32s ¶
func (reader BinaryReader) ReadInt32s(expected int) ([]int32, error)
func (BinaryReader) ReadInt64 ¶
func (reader BinaryReader) ReadInt64() (int64, error)
func (BinaryReader) ReadInt64s ¶
func (reader BinaryReader) ReadInt64s(expected int) ([]int64, error)
func (BinaryReader) ReadUint16 ¶
func (reader BinaryReader) ReadUint16() (uint16, error)
func (BinaryReader) ReadUint16s ¶
func (reader BinaryReader) ReadUint16s(expected int) ([]uint16, error)
func (BinaryReader) ReadUint32 ¶
func (reader BinaryReader) ReadUint32() (uint32, error)
func (BinaryReader) ReadUint32s ¶
func (reader BinaryReader) ReadUint32s(expected int) ([]uint32, error)
func (BinaryReader) ReadUint64 ¶
func (reader BinaryReader) ReadUint64() (uint64, error)
func (BinaryReader) ReadUint64s ¶
func (reader BinaryReader) ReadUint64s(expected int) ([]uint64, error)
func (BinaryReader) Skip ¶
func (reader BinaryReader) Skip(count int) error
Skip n bytes of the output
type BinaryWriter ¶
type BinaryWriter struct {
// contains filtered or unexported fields
}
func (BinaryWriter) Write ¶
func (writer BinaryWriter) Write(value interface{}) error
Write any fixed sized type or array of fixed size types
func (BinaryWriter) WriteByte ¶
func (writer BinaryWriter) WriteByte(b byte) error
func (BinaryWriter) WriteBytes ¶
func (writer BinaryWriter) WriteBytes(bytes []byte) error
func (BinaryWriter) WriteInt16 ¶
func (writer BinaryWriter) WriteInt16(value int16) error
func (BinaryWriter) WriteInt16s ¶
func (writer BinaryWriter) WriteInt16s(values []int16) error
func (BinaryWriter) WriteInt32 ¶
func (writer BinaryWriter) WriteInt32(value int32) error
func (BinaryWriter) WriteInt32s ¶
func (writer BinaryWriter) WriteInt32s(values []int32) error
func (BinaryWriter) WriteInt64 ¶
func (writer BinaryWriter) WriteInt64(value int64) error
func (BinaryWriter) WriteInt64s ¶
func (writer BinaryWriter) WriteInt64s(values []int64) error
func (BinaryWriter) WriteUint16 ¶
func (writer BinaryWriter) WriteUint16(value uint16) error
func (BinaryWriter) WriteUint16s ¶
func (writer BinaryWriter) WriteUint16s(values []uint16) error
func (BinaryWriter) WriteUint32 ¶
func (writer BinaryWriter) WriteUint32(value uint32) error
func (BinaryWriter) WriteUint32s ¶
func (writer BinaryWriter) WriteUint32s(values []uint32) error
func (BinaryWriter) WriteUint64 ¶
func (writer BinaryWriter) WriteUint64(value uint64) error
func (BinaryWriter) WriteUint64s ¶
func (writer BinaryWriter) WriteUint64s(values []uint64) error
type IBinaryBufferReader ¶
type IBinaryBufferReader interface { IBinaryReader // Get the number of bytes remaining in the buffer. Len() int }
IBinaryBufferReader implements the IBinaryReader interface over a bytes.Buffer
func BigEndianBufferReader ¶
func BigEndianBufferReader(buf []byte) IBinaryBufferReader
Create a new big endian reader using the provided buf as the underlying stream.
func LittleEndianBufferReader ¶
func LittleEndianBufferReader(buf []byte) IBinaryBufferReader
Create a new little endian reader using the provided buf as the underlying stream.
type IBinaryBufferWriter ¶
type IBinaryBufferWriter interface { IBinaryWriter // Return the number of bytes in the buffer Len() int // Return the binary representation of Bytes() []byte }
IBinaryBufferWriter implements the IBinaryWriter interfaces on top of bytes.Buffer
func BigEndianBufferWriter ¶
func BigEndianBufferWriter() IBinaryBufferWriter
Create a new big endian writer using a bytes.Buffer as the underlying stream
func LittleEndianBufferWriter ¶
func LittleEndianBufferWriter() IBinaryBufferWriter
Create a new little endian writer using a bytes.Buffer as the underlying stream
func NewBigEndianBufferWriter ¶
func NewBigEndianBufferWriter(capacity int) IBinaryBufferWriter
Create a new big endian writer using a bytes.Buffer as the underlying stream. The buffer will have capacity specified.
func NewLittleEndianBufferWriter ¶
func NewLittleEndianBufferWriter(capacity int) IBinaryBufferWriter
Create a new little endian writer using a bytes.Buffer as the underlying stream. The buffer will have capacity specified.
type IBinaryReader ¶
type IBinaryReader interface { // Read any fixed size value. The parameter should be a pointer to the underlying type. // // var value uint32 // // if err := reader.Read(&value); err != nil { // // ... // // } Read(value interface{}) error ReadByte() (byte, error) ReadBytes(expected int) ([]byte, error) ReadUint16() (uint16, error) ReadInt16() (int16, error) ReadUint16s(expected int) ([]uint16, error) ReadInt16s(expected int) ([]int16, error) ReadUint32() (uint32, error) ReadInt32() (int32, error) ReadUint32s(expected int) ([]uint32, error) ReadInt32s(expected int) ([]int32, error) ReadUint64() (uint64, error) ReadInt64() (int64, error) ReadUint64s(expected int) ([]uint64, error) ReadInt64s(expected int) ([]int64, error) // Skip n bytes of the output Skip(count int) error }
IBinaryReader wraps the encoding/binary interface to allow decoding of binary streams.
func BigEndianReaderFrom ¶
func BigEndianReaderFrom(reader io.Reader) IBinaryReader
Create a new big endian reader using the provided reader as the underlying stream.
func LittleEndianReaderFrom ¶
func LittleEndianReaderFrom(reader io.Reader) IBinaryReader
Create a new little endian reader using the provided reader as the underlying stream.
type IBinaryWriter ¶
type IBinaryWriter interface { // Write any fixed sized type or array of fixed size types Write(interface{}) error WriteByte(byte) error WriteBytes([]byte) error WriteInt16(int16) error WriteUint16(uint16) error WriteInt16s([]int16) error WriteUint16s([]uint16) error WriteInt32(int32) error WriteUint32(uint32) error WriteInt32s([]int32) error WriteUint32s([]uint32) error WriteInt64(int64) error WriteUint64(uint64) error WriteInt64s([]int64) error WriteUint64s([]uint64) error }
IBinaryWriter exposes methods to write fixed sized numbers to an underlying writer implementation
func NewBigEndianFromWriter ¶
func NewBigEndianFromWriter(writer io.Writer) IBinaryWriter
Create a new big endian writer using the provided writer as the underlying stream
func NewLittleEndianFromWriter ¶
func NewLittleEndianFromWriter(writer io.Writer) IBinaryWriter
Create a new little endian writer using the provided writer as the underlying stream