Documentation
¶
Overview ¶
Package bin provides utility interfaces for working with binary data streams
Index ¶
- type Reader
- func (b *Reader) Discard(n int64) error
- func (b *Reader) GetByteOrder() binary.ByteOrder
- func (b *Reader) GetPosition() int64
- func (b *Reader) Peek(dst []byte) error
- func (b *Reader) Read(p []byte) (n int, err error)
- func (b *Reader) ReadByte(dst *byte) error
- func (b *Reader) ReadBytes(dst []byte) error
- func (b *Reader) ReadFloat32(dst *float32) error
- func (b *Reader) ReadFloat64(dst *float64) error
- func (b *Reader) ReadUint16(dst *uint16) error
- func (b *Reader) ReadUint32(dst *uint32) error
- func (b *Reader) ReadUint64(dst *uint64) error
- func (b *Reader) Reset(source io.Reader, bo binary.ByteOrder)
- func (b *Reader) SetByteOrder(bo binary.ByteOrder)
- type Writer
- func (b *Writer) GetByteOrder() binary.ByteOrder
- func (b *Writer) GetPosition() int64
- func (b *Writer) Reset(dest io.Writer, bo binary.ByteOrder)
- func (b *Writer) SetByteOrder(bo binary.ByteOrder)
- func (b *Writer) Write(p []byte) (n int, err error)
- func (b *Writer) WriteByte(src byte) error
- func (b *Writer) WriteBytes(src []byte) error
- func (b *Writer) WriteFloat32(src float32) error
- func (b *Writer) WriteFloat64(src float64) error
- func (b *Writer) WriteUint16(src uint16) error
- func (b *Writer) WriteUint32(src uint32) error
- func (b *Writer) WriteUint64(src uint64) error
- func (b *Writer) ZeroFill(n int64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader provides methods for reading various data types from an `io.Reader`.
func NewReader ¶
NewReader creates a new `Reader` encapsulating the given `source`, and using the byte order `bo` to specify endianness.
For futureproofing, it is suggested to use these constructors rather than manually creating an instance (i.e. `br := Reader{}`)
func NewReaderBytes ¶
NewReaderBytes creates a new `Reader` to read from the given `source`, using the byte order `bo` to specify endianness.
Since `source` is a slice of bytes, a `bytes.Reader` will wrap the slice to satisfy the `io.Reader` interface.
For futureproofing, it is suggested to use these constructors rather than manually creating an instance (i.e. `br := Reader{}`)
func (*Reader) GetByteOrder ¶
GetByteOrder returns the current byte order.
Note that this can be `nil` if the interface was not created via a constructor method.
func (*Reader) GetPosition ¶
func (b *Reader) GetPosition() int64
GetPosition returns the current reader offset as a 64-bit integer.
func (*Reader) Peek ¶
Peek returns the next n bytes without advancing the reader. If the operation cannot fully write to `dst`, it will return an error.
func (*Reader) ReadBytes ¶
ReadBytes attempts to read `len(dst)` bytes into `dst`. Multiple calls will be made to `source.Read` in the case of a partial read.
If unable to completely read into `dst`, `io.ErrUnexpectedEOF` will be returned.
func (*Reader) ReadFloat32 ¶
ReadFloat32 reads a 32-bit IEEE 754 floating-point integer into `dst` according to the current byte order.
func (*Reader) ReadFloat64 ¶
ReadFloat64 reads a 64-bit IEEE 754 floating-point integer into `dst` according to the current byte order.
func (*Reader) ReadUint16 ¶
ReadUint16 reads an unsigned 16-bit integer into `dst` according to the current byte order.
func (*Reader) ReadUint32 ¶
ReadUint32 reads an unsigned 32-bit integer into `dst` according to the current byte order.
func (*Reader) ReadUint64 ¶
ReadUint64 reads an unsigned 64-bit integer into `dst` according to the current byte order.
func (*Reader) SetByteOrder ¶
SetByteOrder sets the current byte order to `bo`. This can be done on-the-fly.
type Writer ¶
type Writer struct {
// contains filtered or unexported fields
}
Writer provides methods for reading various data types to an `io.Writer`.
func NewWriter ¶
NewWriter creates a new `Writer` targetted at the given `dest`, and using the byte order `bo` to specify endianness.
For futureproofing, it is suggested to use these constructors rather than manually creating an instance (i.e. `bw := Writer{}`)
func (*Writer) GetByteOrder ¶
GetByteOrder returns the current byte order.
Note that this can be `nil` if the interface was not created via a constructor method.
func (*Writer) GetPosition ¶
func (b *Writer) GetPosition() int64
GetPosition returns the current reader offset as a 64-bit integer.
func (*Writer) SetByteOrder ¶
SetByteOrder sets the current byte order to `bo`. This can be done on-the-fly.
func (*Writer) WriteBytes ¶
WriteBytes writes all bytes from `src`
func (*Writer) WriteFloat32 ¶
WriteFloat32 writes a 32-bit IEEE 754 floating-point integer according to the current byte order.
func (*Writer) WriteFloat64 ¶
WriteFloat64 writes a 64-bit IEEE 754 floating-point integer according to the current byte order.
func (*Writer) WriteUint16 ¶
WriteUint16 writes an unsigned 16-bit integer according to the current byte order.
func (*Writer) WriteUint32 ¶
WriteUint32 writes an unsigned 32-bit integer according to the current byte order.
func (*Writer) WriteUint64 ¶
WriteUint64 writes an unsigned 64-bit integer according to the current byte order.