binary

package
v0.0.0-...-938d948 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2014 License: BSD-2-Clause Imports: 7 Imported by: 9

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

Constants

This section is empty.

Variables

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

func (r *BinaryReader) Read(size int) ([]byte, error)

func (*BinaryReader) ReadInterface

func (r *BinaryReader) ReadInterface(v interface{}) error

func (*BinaryReader) Seek

func (r *BinaryReader) Seek(offset int64, whence int) (int64, 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 BitReader

type BitReader struct {
	Inner io.Reader
	// contains filtered or unexported fields
}

func (*BitReader) ReadBit

func (b *BitReader) ReadBit() (bool, error)

func (*BitReader) ReadBits

func (b *BitReader) ReadBits(count int) (int64, 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.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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