wire

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package wire is the runtime for the Nimbus Native wire format: the binary encoding every message between Go and a host uses. Generated code (see wire/gen) calls these functions; apps rarely touch them directly.

Encoding, identical in Go, Swift and Java:

bool                1 byte, 0 or 1
uint8…uint64        unsigned LEB128 varint
int8…int64          zigzag, then varint
float32, float64    IEEE 754, little-endian, 4 / 8 bytes
string, []byte      varint length, then the bytes (strings are UTF-8)
[]T                 varint count, then each element
map[K]V             varint count, then key, value pairs sorted by key
*T (optional)       1 byte present flag, then the value if present
struct              its fields in declaration order, no tags
union (interface)   varint variant index (1-based), then the variant

Structs carry no field tags: both sides are generated from the same schema, and the schema hash checked at nn_start guarantees they match.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrShort    = errors.New("wire: message ends early")
	ErrOverflow = errors.New("wire: varint overflows 64 bits")
	ErrRange    = errors.New("wire: value out of range for its type")
	ErrVariant  = errors.New("wire: unknown union variant or message id")
	ErrTrailing = errors.New("wire: bytes left over after the message")
)

Errors a Reader reports. Decoding stops at the first one.

Functions

func AppendBool

func AppendBool(b []byte, v bool) []byte

func AppendBytes

func AppendBytes(b []byte, v []byte) []byte

func AppendFloat32

func AppendFloat32(b []byte, v float32) []byte

func AppendFloat64

func AppendFloat64(b []byte, v float64) []byte

func AppendInt

func AppendInt(b []byte, v int64) []byte

func AppendString

func AppendString(b []byte, v string) []byte

func AppendUint

func AppendUint(b []byte, v uint64) []byte

func Cap

func Cap(n int) int

Cap is the capacity to preallocate for a list of n elements.

func Combine

func Combine(hashes []uint64) uint64

Combine folds schema hashes into one value; order does not matter and no hashes is 0. The generators bake the same value into host code.

func Combined

func Combined() uint64

Combined is the hash of every registered schema, the value a host must pass to nn_start. It is 0 when no schema is linked.

func Register

func Register(pkg string, hash uint64)

Register records a schema linked into the app. Generated code calls it from init; apps never do.

Types

type Reader

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

Reader decodes from a byte slice. The first error sticks: later reads return zero values, and Err reports what went wrong. Generated code reads a whole message and checks Err once.

func NewReader

func NewReader(b []byte) *Reader

func (*Reader) Bool

func (r *Reader) Bool() bool

func (*Reader) Bytes

func (r *Reader) Bytes() []byte

func (*Reader) Count

func (r *Reader) Count() int

Count reads a list or map length and checks it is plausible: every element takes at least one byte, so a count beyond the remaining bytes is corrupt.

func (*Reader) Done

func (r *Reader) Done() error

Done reports ErrTrailing if bytes remain, and returns the reader's error.

func (*Reader) Err

func (r *Reader) Err() error

Err is the first error encountered, or nil.

func (*Reader) Fail

func (r *Reader) Fail(err error)

Fail records err unless an earlier error is already recorded.

func (*Reader) Float32

func (r *Reader) Float32() float32

func (*Reader) Float64

func (r *Reader) Float64() float64

func (*Reader) Int

func (r *Reader) Int() int64

func (*Reader) IntRange

func (r *Reader) IntRange(min, max int64) int64

IntRange reads a signed varint and fails with ErrRange outside [min, max].

func (*Reader) String

func (r *Reader) String() string

func (*Reader) Uint

func (r *Reader) Uint() uint64

func (*Reader) UintMax

func (r *Reader) UintMax(max uint64) uint64

UintMax reads an unsigned varint and fails with ErrRange above max — for uint8/16/32 fields.

Directories

Path Synopsis
Package gen turns a wire schema into code: Go (methods on the schema's own types), Swift (NimbusNativeKit hosts) and Kotlin (Android hosts).
Package gen turns a wire schema into code: Go (methods on the schema's own types), Swift (NimbusNativeKit hosts) and Kotlin (Android hosts).
internal
kitchen
Package kitchen is a wire schema that uses every feature the generators support.
Package kitchen is a wire schema that uses every feature the generators support.
Package schema reads a wire schema: a Go package of plain types marked with //wire: directives.
Package schema reads a wire schema: a Go package of plain types marked with //wire: directives.

Jump to

Keyboard shortcuts

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