Modules

std.codec

Little-endian integer helpers, unsigned varints, and CRC-32 primitives.

Status

Runnable today:

APIReturnNotes
std.codec.crc32(bytes)u32Computes CRC-32 for a string-backed byte input.
std.codec.crc32Bytes(bytes)u32Computes CRC-32 for a span or mutable span without allocation.
std.codec.encodedVarintLen(value)usizeReturns the byte length of an unsigned varint encoding.
std.codec.readU8(bytes)u8Reads one byte.
std.codec.readU16(bytes)u16Reads two bytes as little-endian.
std.codec.readU32(bytes)u32Reads four bytes as little-endian.
std.codec.writeU16(value)u32Packs a u16 value into the current write representation.
std.codec.writeU32(value)u32Packs a u32 value into the current write representation.

Current limits:

  • Buffer-backed write APIs.
  • Error-producing reads for short inputs.
  • Streaming encoders and decoders.

Example

use std.codecuse std.mem pub fun main(world: World) -> Void raises {    let len = std.codec.encodedVarintLen(300)    let checksum = std.codec.crc32("zero")    let bytes = std.mem.span("zero")    let byte_checksum = std.codec.crc32Bytes(bytes)    if len == 2 && checksum == byte_checksum {        check world.out.write("codec primitives ok\n")    }}

Design Notes

The current helpers are intentionally narrow. They prove integer widths and deterministic byte math before allocator-backed buffers are added.