veko doc
Self-Contained API Reference • Gradual Types • Capabilities • Wasm Sandbox

codec/wire

lib/codec/wire.vk

lib/codec/wire.vk Pure-Veko schema-driven binary packet/frame packer and unpacker over hardware LE/BE wire intrinsics. Supports fixed-width integers (.u8, .u16_le, .u16_be, .u32_le, .u32_be, .i64_le, .i64_be), LEB128 .varint, .f64_be, length-prefixed .bytes_u16_be / .str_u16_be, and fixed-length .raw. Zero capabilities required.

Field struct
signature
Field = struct { name str, kind enum, size i64 = ... }

Describes a single field in a binary wire packet schema.

pack fn
signature
pack = fn [schema block[Field], record map] bytes

Packs a map of field values according to schema (block[Field]) into bytes.

Executable Example
veko
use [w = codec/wire]
schema = [
  w/Field { name = 'version', kind = .u16_be }
  w/Field { name = 'flags',   kind = .u8 }
  w/Field { name = 'seq',     kind = .varint }
  w/Field { name = 'topic',   kind = .str_u16_be }
]
pkt = w/pack schema { version = 0x0303, flags = 5, seq = 300, topic = 'metrics' }
dec = w/unpack schema pkt
if (map/get dec 'version') != 0x0303 or (map/get dec 'seq') != 300 or (map/get dec 'topic') != 'metrics' [
  err 'wire roundtrip'
] else [ .ok ]
signature
unpack = fn [schema block[Field], data bytes] map

Unpacks data according to schema (block[Field]) into a map of decoded values.