binio

package module
v0.0.0-...-732dac8 Latest Latest
Warning

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

Go to latest
Published: Sep 21, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

README

Go Binio

Go Reference

A library for decoding binary data into structs.

[!WARNING]
This lib is currently not ready for production use!

Example

type Data struct {
    MyString string `bin:"size=12"` // ASCII string with a length of 12
    A uint32
    B float32
    C float64
    _ [2]byte // skip 2 bytes
    D uint64

    E []int32 `bin:"size=3,if=%A"`

    MyArrayLength int32
    MyArrayData []float64 `bin:"size=%MyArrayLength"`
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (

	// ErrMissingTag will be returned if a required tag is missing
	// e.g. for a field with the type string we need one
	ErrMissingTag  = errors.New("missing field tag")
	ErrMissingSize = errors.New("missing size")
)
View Source
var (
	ErrUnknownTagOption = errors.New("unknown tag option")
	ErrInvalidTagOption = errors.New("invalid tag option")
)

Functions

func IntSize

func IntSize(name string) int

func RegisterDecoder

func RegisterDecoder(typ ref.Type, dec DecodeFunc)

func Unmarshal

func Unmarshal(rd io.Reader, v any) error

func ValueSize

func ValueSize(v ref.Type) (int, error)

func WriteVarString

func WriteVarString[E SizedUnsigned](w io.Writer, str string) error

Types

type DecodeFunc

type DecodeFunc func(dec *Decoder, v reflect.Value) error

type Decoder

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

func NewDecoder

func NewDecoder(rd io.Reader) *Decoder

func (*Decoder) Decode

func (dec *Decoder) Decode(v any) (err error)

func (*Decoder) DecodeValue

func (dec *Decoder) DecodeValue(v reflect.Value) error

func (*Decoder) Int16

func (dec *Decoder) Int16() (v int16)

func (*Decoder) Int32

func (dec *Decoder) Int32() (v int32)

func (*Decoder) Int64

func (dec *Decoder) Int64() (v int64)

func (*Decoder) Int8

func (dec *Decoder) Int8() (v int8)

func (*Decoder) Pos

func (dec *Decoder) Pos() int64

func (*Decoder) Read

func (dec *Decoder) Read(p []byte) (n int, err error)

func (*Decoder) Skip

func (dec *Decoder) Skip(n int64) error

func (*Decoder) Uint

func (dec *Decoder) Uint(n int) int

func (*Decoder) Uint16

func (dec *Decoder) Uint16() (v uint16)

func (*Decoder) Uint32

func (dec *Decoder) Uint32() (v uint32)

func (*Decoder) Uint64

func (dec *Decoder) Uint64() (v uint64)

func (*Decoder) Uint8

func (dec *Decoder) Uint8() (v uint8)

type DecodingError

type DecodingError struct {
	Pos  int64
	Err  error
	Path []string
}

func (*DecodingError) Error

func (err *DecodingError) Error() string

func (*DecodingError) Unwrap

func (err *DecodingError) Unwrap() error

type Encoder

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

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

func (*Encoder) Encode

func (enc *Encoder) Encode(v any) error

func (*Encoder) EncodeValue

func (enc *Encoder) EncodeValue(v reflect.Value) error

func (*Encoder) Write

func (enc *Encoder) Write(buf []byte) (n int, err error)

type SizedInteger

type SizedInteger interface {
	SizedSigned | SizedUnsigned
}

type SizedSigned

type SizedSigned interface {
	~int8 | ~int16 | ~int32 | ~int64
}

type SizedUnsigned

type SizedUnsigned interface {
	~uint8 | ~uint16 | ~uint32 | ~uint64
}

type Tag

type Tag struct {
	Size expr.Expr
	If   expr.Expr
	Ptrs expr.Expr

	Vars map[string]expr.Expr
	// contains filtered or unexported fields
}

func ParseTag

func ParseTag(str string) (*Tag, error)

func (*Tag) AddVar

func (t *Tag) AddVar(name string, value expr.Expr)

func (*Tag) HasVar

func (t *Tag) HasVar(name string) bool

func (*Tag) IsDynArray

func (t *Tag) IsDynArray() bool

func (*Tag) IsDynString

func (t *Tag) IsDynString() bool

func (*Tag) IsHoleyArray

func (t *Tag) IsHoleyArray() bool

func (*Tag) VarNames

func (t *Tag) VarNames() []string

type Type

type Type byte

type Unmarshaler

type Unmarshaler interface {
	UnmarshalDAT(dec *Decoder) error
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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