parity

package
v1.3.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

This file is a byte-identical copy of pkg/wasm/wasm-runtime/runtime/codec.go used by codec_parity_test.go to validate that the server-side stub in pkg/wasm/stubs.go and the WASM-side runtime stay in sync. Any change to runtime/codec.go MUST be mirrored here AND in stubs.go.

Index

Constants

View Source
const WireVersion byte = 1

WireVersion is the codec's frame-format version. It is written as byte 0 of every top-level frame by NewEncoder and validated by NewDecoder. Bumping it is an intentional, irreversible wire break: a decoder built for one version rejects frames carrying any other. Nested encodes (_encode_X, _encode_sliceX) receive an already-opened *Encoder and therefore never re-emit this byte — only the frame's opening carries it.

Variables

This section is empty.

Functions

func HexDecode

func HexDecode(s string) []byte

func HexEncode

func HexEncode(src []byte) string

Types

type Decoder

type Decoder struct {
	Buf []byte
	Pos int
	Err error
}

Decoder reads a little-endian binary stream. Err accumulates the first decode error — check it once at the end rather than per call.

func NewDecoder

func NewDecoder(buf []byte) *Decoder

NewDecoder opens a frame produced by NewEncoder. It validates the WireVersion header byte at position 0 and positions Pos immediately after it, so the first typed read returns the frame's first field. On an empty buffer or a version mismatch it sets Err (leaving Pos at 0) and never panics — need() short- circuits all subsequent reads. Use this at every site that decodes a complete wire frame; per-field capture helpers that walk an already-opened Decoder keep using the raw &Decoder{} form.

func (*Decoder) Bool

func (d *Decoder) Bool() bool

func (*Decoder) Bytes

func (d *Decoder) Bytes() []byte

func (*Decoder) F32

func (d *Decoder) F32() float32

func (*Decoder) F64

func (d *Decoder) F64() float64

func (*Decoder) I32

func (d *Decoder) I32() int32

func (*Decoder) I64

func (d *Decoder) I64() int64

func (*Decoder) String

func (d *Decoder) String() string

func (*Decoder) U8

func (d *Decoder) U8() uint8

func (*Decoder) U16

func (d *Decoder) U16() uint16

func (*Decoder) U32

func (d *Decoder) U32() uint32

func (*Decoder) U64

func (d *Decoder) U64() uint64

type Encoder

type Encoder struct{ Buf []byte }

Encoder writes a little-endian binary stream into Buf. Preallocate with NewEncoder to avoid repeated append growth.

func NewEncoder

func NewEncoder(cap int) *Encoder

NewEncoder opens a new frame: it returns an *Encoder whose buffer already contains the single WireVersion header byte at position 0. Every subsequent write appends after it. Because nested encoders reuse this same *Encoder, the version byte appears exactly once per frame — at the frame boundary.

func (*Encoder) Bool

func (e *Encoder) Bool(v bool)

func (*Encoder) Bytes

func (e *Encoder) Bytes(v []byte)

func (*Encoder) F32

func (e *Encoder) F32(v float32)

func (*Encoder) F64

func (e *Encoder) F64(v float64)

func (*Encoder) I32

func (e *Encoder) I32(v int32)

func (*Encoder) I64

func (e *Encoder) I64(v int64)

func (*Encoder) String

func (e *Encoder) String(v string)

func (*Encoder) U8

func (e *Encoder) U8(v uint8)

func (*Encoder) U16

func (e *Encoder) U16(v uint16)

func (*Encoder) U32

func (e *Encoder) U32(v uint32)

func (*Encoder) U64

func (e *Encoder) U64(v uint64)

Jump to

Keyboard shortcuts

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