Files
webnet/packages/binary

@webnet/binary

Binary readers and writers for webnet protocols.

BinaryWriter and BinaryReader are growable, bounds-checked big/little-endian cursors over Uint8Array. LengthPrefixedBinaryWriter and LengthPrefixedBinaryReader extend them with u32-length-prefixed byte strings and UTF-8 text.

The package has no transport or DOM dependency, so protocol packages can share binary serialization without depending on browser utilities.

Entry points

Entry point Description
@webnet/binary Binary readers and writers, length-prefixed variants, and their cursor option and endian types.

Usage

import { BinaryWriter, LengthPrefixedBinaryReader } from "@webnet/binary"

const bytes = new BinaryWriter({ endian: "little" })
  .u32(3)
  .bytes(new Uint8Array([1, 2, 3]))
  .finish()

const reader = new LengthPrefixedBinaryReader(bytes, 0, "little")
reader.string() // Uint8Array [1, 2, 3]

See also

  • @webnet/transport — byte-stream abstractions used by protocol clients and servers