Documentation ¶
Overview ¶
The binary package implements code aiding in dealing with binary data. The goal is to have users write as little custom binary parsing code as possible by focusing instead on defining the data structures in terms of Go structs and providing struct tags to guide the loading and saving of the binary data.
Index ¶
- Variables
- type BinaryReader
- func (r *BinaryReader) Float32() (float32, error)
- func (r *BinaryReader) Float64() (float64, error)
- func (r *BinaryReader) Int16() (int16, error)
- func (r *BinaryReader) Int32() (int32, error)
- func (r *BinaryReader) Int64() (int64, error)
- func (r *BinaryReader) Int8() (int8, error)
- func (r *BinaryReader) Read(size int) ([]byte, error)
- func (r *BinaryReader) ReadInterface(v interface{}) error
- func (r *BinaryReader) Seek(offset int64, whence int) (int64, error)
- func (r *BinaryReader) Uint16() (uint16, error)
- func (r *BinaryReader) Uint32() (uint32, error)
- func (r *BinaryReader) Uint64() (uint64, error)
- func (r *BinaryReader) Uint8() (uint8, error)
- type BitReader
- type Reader
- type Validateable
Constants ¶
This section is empty.
Variables ¶
var ( LittleEndian = sb.LittleEndian BigEndian = sb.BigEndian )
Functions ¶
This section is empty.
Types ¶
type BinaryReader ¶
type BinaryReader struct { Reader io.ReadSeeker Endianess sb.ByteOrder // contains filtered or unexported fields }
The BinaryReader uses information provided in struct tags to deal with operations common when reading data from a binary file into a Go struct, such as data alignment, array lengths, "if" checks and skipping of uninteresting data.
In many instances this means that no custom loading code needs to be written and the user can focus on describing the data structures instead.
For more complex needs, the Reader interface can be implemented which then allows the user to write custom loading code only where it is needed.
func (*BinaryReader) Float32 ¶
func (r *BinaryReader) Float32() (float32, error)
func (*BinaryReader) Float64 ¶
func (r *BinaryReader) Float64() (float64, error)
func (*BinaryReader) Int16 ¶
func (r *BinaryReader) Int16() (int16, error)
func (*BinaryReader) Int32 ¶
func (r *BinaryReader) Int32() (int32, error)
func (*BinaryReader) Int64 ¶
func (r *BinaryReader) Int64() (int64, error)
func (*BinaryReader) Int8 ¶
func (r *BinaryReader) Int8() (int8, error)
func (*BinaryReader) ReadInterface ¶
func (r *BinaryReader) ReadInterface(v interface{}) error
func (*BinaryReader) Uint16 ¶
func (r *BinaryReader) Uint16() (uint16, error)
func (*BinaryReader) Uint32 ¶
func (r *BinaryReader) Uint32() (uint32, error)
func (*BinaryReader) Uint64 ¶
func (r *BinaryReader) Uint64() (uint64, error)
func (*BinaryReader) Uint8 ¶
func (r *BinaryReader) Uint8() (uint8, error)
type Reader ¶
type Reader interface {
Read(*BinaryReader) error
}
The Reader interface gives the user a chance to perform custom actions required to load specific data types.
type Validateable ¶
type Validateable interface {
Validate() error
}
If a data type being loaded implements the validateable interface, the Validate function will be called once the BinaryReader has finished reading the interface, and the error if any returned from this function will be what is returned from the BinaryReader's ReadInterface method.