ezbin

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2025 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StringFormat_Invalid = StringFormat(0)
	StringFormat_ASCII
)

Variables

View Source
var ErrInvalidByteOrder = errors.New("invalid byte order, expected 0xFEFF or 0xFFFE")
View Source
var ErrInvalidByteOrderType = errors.New("invalid byte order type, expected [2]byte")
View Source
var ErrInvalidFixedPointBits = errors.New("invalid fixed point bits, bit counts cannot be below 0")
View Source
var ErrInvalidFixedPointSign = errors.New("invalid fixed point sign, sign can only be 0 or 1 bit")
View Source
var ErrInvalidFixedPointSignature = errors.New("invalid fixed point tag, expected \"int,int,int\"")
View Source
var ErrInvalidFixedPointSize = errors.New("invalid fixed point size, expected multiple of 8 bits, max 64")
View Source
var ErrInvalidFixedPointType = errors.New("invalid fixed point type, expected float32 or float64")
View Source
var ErrInvalidTellType = errors.New("invalid seekpos type, expected integer")
View Source
var ErrNotSeeker = errors.New("reader does not implement io.Seeker")
View Source
var ErrSliceMissingLength = errors.New("cannot decode slice without length tag")
View Source
var ErrUnknownNamedInt = errors.New("malformed int or invalid named int field")
View Source
var ErrUnknownString = errors.New("unknown string type")
View Source
var SignatureBE = [2]byte{0xFE, 0xFF}
View Source
var SignatureLE = [2]byte{0xFF, 0xFE}

Functions

func Align

func Align[K Integer](s io.Seeker, lim K) (K, error)

Aligns seeker head to match lim (rounds UP)

func At

func At[K Integer](w io.Seeker) (K, error)

Get current position of seeker, but as any integer type

func Bitget added in v0.2.0

func Bitget[OUT Integer, IN Integer](bitlist IN, bits int, pos int) OUT

func BitgetFlag added in v0.2.0

func BitgetFlag[IN Integer](bitlist IN, pos int) bool

func BitgetSigned added in v0.2.0

func BitgetSigned[OUT Integer, IN Integer](bitlist IN, bits int, pos int) OUT

func Bitset added in v0.2.0

func Bitset[IN Integer, VAL Integer](bitlist IN, val VAL, bits int, pos int) IN

func BitsetFlag added in v0.2.0

func BitsetFlag[IN Integer](bitlist IN, flag bool, pos int) IN

func Decode added in v0.2.0

func Decode[T any](r io.Reader) (v T, err error)

func DecodeFixedPoint added in v0.4.0

func DecodeFixedPoint(rawData uint64, signBits int, wholeBits int, fractBits int) float64

func FillerArray

func FillerArray[K any](length int, value K) []K

Create a pre-initialized array.

func Get

func Get(buf []byte, pos int, data ...any) error

func GetEndianFromSignature added in v0.2.0

func GetEndianFromSignature(signature [2]byte) binary.ByteOrder

func Pad

func Pad[K Integer](n K, lim K) K

Returns the amount of padding needed to align number

func PadTo

func PadTo[K Integer](n K, lim K) K

Returns the number padded

func Put

func Put(buf []byte, pos int, data ...any) ([]byte, error)

func PutAny

func PutAny[K any](buf []K, pos int, data ...K) []K

func Read

func Read(r io.Reader, data ...any) error

Read data from r into data. All entries in data should be pointers/references. Errors are ignored.

func ReadAt

func ReadAt[K Integer](r io.ReaderAt, at K, data ...any) error

Same as Read, but reads AT in a io.ReaderAt. Errors are ignored.

func ReadBytesAsInt added in v0.4.0

func ReadBytesAsInt(r io.Reader, numBytes int) (uint64, error)

func ReadFixedPoint added in v0.4.0

func ReadFixedPoint(r io.Reader, signBits int, wholeBits int, fractBits int) (float64, error)

func ReadSingle

func ReadSingle[K any](r io.Reader) K

Return single read value. Errors are ignored.

func ReadString added in v0.4.0

func ReadString(r io.Reader, format StringFormat, fixedLength int) (string, error)

func ReadWithOrder added in v0.4.0

func ReadWithOrder(r io.Reader, buf []byte, byteOrder binary.ByteOrder) (n int, err error)

Reads bytes as if an integer was read. If big endian, this is the same as reading normally. If little endian, the bytes will be in reversed before being returned.

func Seek

func Seek[K Integer](s io.Seeker, offset K, whence int) (K, error)

io.Seeker.Seek() but with generic offset types

func Skip added in v0.4.0

func Skip[K Integer](w io.Seeker, num K) (K, error)

Skips over a few bytes

func StructTagAdd added in v0.2.0

func StructTagAdd(tag reflect.StructTag, key string, value string) reflect.StructTag

Adds a key/value pair to the struct tag

func StructTagFind added in v0.2.0

func StructTagFind(tag reflect.StructTag, key string) (start int, end int, ok bool)

This is modified code from the GO standard library. It finds the position of a specific key/value pair in a tag.

func StructTagRemove added in v0.2.0

func StructTagRemove(tag reflect.StructTag, key string) reflect.StructTag

Removes a key/value pair from the struct tag

func Write

func Write(w io.Writer, data ...any) error

Write all data into w. Errors are ignored.

func WriteAt

func WriteAt[K Integer](w io.WriterAt, at K, data ...any) error

Same as Write, but with WriterAt. Errors are ignored.

func WritePadded

func WritePadded(w io.Writer, lim int, filler byte, data ...any) error

Assumes the write head is aligned. If you want to make sure it is, use the Align function.

Types

type Decodable added in v0.4.0

type Decodable interface {
	// Reader may be an io.Seeker as well
	EzbinDecode(r io.Reader) error
}

type Endianed added in v0.2.0

type Endianed interface {
	GetEndian() binary.ByteOrder
}

type EndianedReader added in v0.2.0

type EndianedReader struct {
	io.Reader
	ByteOrder binary.ByteOrder
}

func (*EndianedReader) GetEndian added in v0.2.0

func (r *EndianedReader) GetEndian() binary.ByteOrder

func (*EndianedReader) ReadWithOrder added in v0.2.0

func (r *EndianedReader) ReadWithOrder(buf []byte) (n int, err error)

Reads bytes as if an integer was read. If big endian, this is the same as reading normally. If little endian, the bytes will be in reversed before being returned.

type EndianedWriter added in v0.2.0

type EndianedWriter struct {
	io.Writer
	ByteOrder binary.ByteOrder
}

func (*EndianedWriter) GetEndian added in v0.2.0

func (w *EndianedWriter) GetEndian() binary.ByteOrder

func (*EndianedWriter) WriteWithOrder added in v0.2.0

func (r *EndianedWriter) WriteWithOrder(buf []byte) (n int, err error)

Writes bytes as if an integer was written. If big endian, this is the same as writing normally. If little endian, the bytes will be written in reverse order.

type Integer

type Integer interface {
	~int | ~uint | ~int8 | ~uint8 | ~int16 | ~uint16 | ~int32 | ~uint32 | ~int64 | ~uint64 | ~uintptr
}

type StringFormat added in v0.4.0

type StringFormat int

func StringFormatFromString added in v0.4.0

func StringFormatFromString(format string) StringFormat

Jump to

Keyboard shortcuts

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