binary

package
v1.3.5 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2019 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package binary provides helpers for encoding binary data from a spec file very loosely based on kaitai; see https://doc.kaitai.io. Only flat primitive types are supported.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadF32 added in v1.3.4

func ReadF32(rdr io.Reader, endian binary.ByteOrder) float32

func ReadF64 added in v1.3.4

func ReadF64(rdr io.Reader, endian binary.ByteOrder) float64

func ReadS8 added in v1.3.4

func ReadS8(rdr io.Reader, endian binary.ByteOrder) int8

func ReadS16 added in v1.3.4

func ReadS16(rdr io.Reader, endian binary.ByteOrder) int16

func ReadS32 added in v1.3.4

func ReadS32(rdr io.Reader, endian binary.ByteOrder) int32

func ReadS64 added in v1.3.4

func ReadS64(rdr io.Reader, endian binary.ByteOrder) int64

func ReadU8 added in v1.3.4

func ReadU8(rdr io.Reader, endian binary.ByteOrder) uint8

func ReadU16 added in v1.3.4

func ReadU16(rdr io.Reader, endian binary.ByteOrder) uint16

func ReadU32 added in v1.3.4

func ReadU32(rdr io.Reader, endian binary.ByteOrder) uint32

func ReadU64 added in v1.3.4

func ReadU64(rdr io.Reader, endian binary.ByteOrder) uint64

Types

type Decoder

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

Decoder is a binary object decoder

func NewDecoder

func NewDecoder(spec *Spec) *Decoder

NewDecoder returns a new decoder with the spec

func (*Decoder) Decode

func (d *Decoder) Decode(data []byte) (types.StringMap, error)

Decode decodes the binary data using its spec

type Instance added in v1.3.4

type Instance struct {
	Sequence `yaml:",inline"`

	// Pos is the position of the data in the byte stream
	Pos *string `yaml:"pos,omitempty"`

	// Value is the computed value of the instance object
	Value *string `yaml:"value,omitempty"`
}

Instance is an instance definition

type Meta

type Meta struct {
	ID       string `yaml:"id"`
	Endian   string `yaml:"endian"`
	Encoding string `yaml:"encoding"`
}

Meta provides meta-information for the spec

type Sequence

type Sequence struct {
	// ID is the label for the field
	ID string `yaml:"id"`

	// Type defines the type, width, and byte order or a custom definde type
	Type string `yaml:"type"`

	// Size is the length of the field in bytes, or points to another sequence value
	Size *string `yaml:"size,omitempty"`

	// Repeat is used for array values
	Repeat *string `yaml:"repeat,omitempty"`

	// Omit when set the sequenece will be omitted from the final value
	Omit bool `yaml:"omit"`
	// contains filtered or unexported fields
}

Sequence is a field definition

type Spec

type Spec struct {
	Meta      Meta                `yaml:"meta"`
	Sequence  []Sequence          `yaml:"seq"`
	Instances map[string]Instance `yaml:"instances"`
	Types     map[string]Type     `yaml:"types"`
}

Spec defines the specification

type Type added in v1.3.4

type Type struct {
	Sequence []Sequence `yaml:"seq"`
}

Type is a type definition

Jump to

Keyboard shortcuts

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