Help us shape the future of Go! Take the 2026 Go Developer Survey

binwire

package
v0.0.13 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 4 Imported by: 0

README

Typed binary primitives

The candidate runtime formats use static generated field codecs, without JSON or runtime reflection. Runtime format types carry no JSON tags or custom MarshalJSON/UnmarshalJSON methods; the SDK policy tests enforce this. internal/codegen/binary reads Go declarations at build time; generated files remain checked into Git. Run mise exec -- go generate ./format/world after changing an owned contract. The regeneration test checks world, lightmap and material snapshots together.

Each payload begins with 16 little-endian bytes: four-byte magic, uint16 binary version 1, uint16 zero flags, uint32 exact payload byte length and uint32 zero reserved. Readers reject unsupported versions, nonzero reserved fields, truncation and trailing bytes before publication. Owning packages retain their encoded limits and semantic validation.

Fields follow public Go declaration order. int uses signed int32; explicit unsigned integers keep their widths. Floats use finite IEEE float32/float64; negative zero is encoded as positive zero and rejected by the reader. Booleans and pointer presence use one byte, exactly 0 or 1. Strings use uint32 byte lengths followed by valid UTF-8. Slices use uint32 length+1, reserving zero for nil; an explicit empty slice encodes count 1. Fixed arrays omit counts.

Generated scanners traverse the complete payload without allocating strings or arrays. Count checks bound each field, its minimum encoded footprint and the aggregate conservative 32 MiB allocation estimate before typed reads. The estimate includes pointed records, slices and strings. Generated writers stop on bounds failures. Browser Wasm scans/reads/writes yield after bounded byte intervals; native code has no scheduling change. Full authored validation still runs after decoding. A binary header never substitutes for semantic checks.

Magic values are KWR1 world, KLM1 lightmap layout, KPB1 prebake manifest and KMA1 material layout. Internal digest identities use the same primitives with separate domains: KWG1 geometry, KDI1 selected direct lights, KOI1 offline controls, KRA1 reflectance assignments, KLQ1 liquid geometry and KSI1 shadow selection. These are explicit replacements for the released JSON identities; compiled artifacts and bake caches must be rebuilt. Semantic capability versions and lightmap algorithms retain their own independent gates.

Documentation

Overview

Package binwire implements bounded, canonical primitives for generated typed format codecs. It has no reflection or dynamic serialization.

Index

Constants

View Source
const AllocationLimit = 32 * 1024 * 1024
View Source
const HeaderSize = 16

Variables

View Source
var (
	ErrWire    = errors.New("invalid binary payload")
	ErrVersion = errors.New("unsupported binary version")
	ErrCount   = errors.New("binary count or allocation bound")
)

Functions

This section is empty.

Types

type Reader

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

func NewReader

func NewReader(data []byte, magic string, maximum int) *Reader

func (*Reader) Allocate

func (r *Reader) Allocate(size uint64)

func (*Reader) Bool

func (r *Reader) Bool() bool

func (*Reader) Count

func (r *Reader) Count(maximum int, minimumBytes, itemAllocation uint64) (int, bool)

func (*Reader) Done

func (r *Reader) Done() error

func (*Reader) Err

func (r *Reader) Err() error

func (*Reader) F32

func (r *Reader) F32() float32

func (*Reader) F64

func (r *Reader) F64() float64

func (*Reader) I32

func (r *Reader) I32() int

func (*Reader) SkipString

func (r *Reader) SkipString(maximum int)

func (*Reader) String

func (r *Reader) String(maximum int) string

func (*Reader) StringIn

func (r *Reader) StringIn(maximum int, choices ...string) bool

StringIn scans one bounded string without allocating a decoded copy. It supports conditional typed fields whose presence is selected by a known tag.

func (*Reader) U8

func (r *Reader) U8() uint8

func (*Reader) U16

func (r *Reader) U16() uint16

func (*Reader) U32

func (r *Reader) U32() uint32

func (*Reader) U64

func (r *Reader) U64() uint64

type Writer

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

func NewWriter

func NewWriter(magic string, maximum int) *Writer

func (*Writer) Bool

func (w *Writer) Bool(v bool)

func (*Writer) Bytes

func (w *Writer) Bytes() ([]byte, error)

func (*Writer) Count

func (w *Writer) Count(length int, absent bool, maximum int)

func (*Writer) Err

func (w *Writer) Err() error

func (*Writer) F32

func (w *Writer) F32(v float32)

func (*Writer) F64

func (w *Writer) F64(v float64)

func (*Writer) I32

func (w *Writer) I32(v int)

func (*Writer) String

func (w *Writer) String(v string, maximum int)

func (*Writer) U8

func (w *Writer) U8(v uint8)

func (*Writer) U16

func (w *Writer) U16(v uint16)

func (*Writer) U32

func (w *Writer) U32(v uint32)

func (*Writer) U64

func (w *Writer) U64(v uint64)

Jump to

Keyboard shortcuts

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