Manuscript Documentation
v2026.12.0

@std/bytes.ms#

Import each required symbol with import Name from "@std/bytes.ms".

Bytes Native type#

An immutable sequence of bytes, such as "hello".to_bytes(). Use decode_utf8() to read text; invalid UTF-8 returns null. Indices and slice bounds count bytes from zero.

Manuscript
type Bytes {
}

fn move Bytes.into_string() String? { ... }
fn Bytes.contains(value Bytes) Bool { ... }
fn Bytes.split(separator Bytes) List[Bytes] { ... }
fn Bytes.slice(start Int, end Int) Result[Bytes, Error] { ... }
fn Bytes.view(start Int, end Int) Bytes { ... }
fn Bytes.index_of(value Bytes) Int? { ... }
fn Bytes.index_of_byte(value UInt8, start Int = 0) Int? { ... }
fn Bytes.last_index_of(value Bytes) Int? { ... }
fn Bytes.starts_with(prefix Bytes) Bool { ... }
fn Bytes.ends_with(suffix Bytes) Bool { ... }
fn Bytes.reversed() Bytes { ... }
fn Bytes.with_value(index Int, value UInt8) Bytes { ... }
fn Bytes.is_empty() Bool { ... }
fn Bytes.values() List[UInt8] { ... }
fn Bytes.concat(other Bytes) Bytes { ... }
fn Bytes.length() Int { ... }
fn Bytes.decode_utf8() String? { ... }
fn Bytes.decode_utf8_range(start Int, end Int) String? { ... }

Bytes.as_bytes#

The bytes themselves, copied.

Manuscript
fn as_bytes() Bytes

Bytes.clone#

Copies byte storage without changing the receiver.

Manuscript
fn clone() Bytes

Bytes.concat#

Returns concatenated bytes without changing either operand.

Manuscript
fn concat(other Bytes) Bytes { ... }

Bytes.contains#

Tests whether value occurs as a byte subsequence.

Manuscript
fn contains(value Bytes) Bool { ... }

Bytes.decode_utf8#

Decodes valid UTF-8 as text, or returns null when the bytes are invalid.

Manuscript
fn decode_utf8() String? { ... }

Bytes.decode_utf8_range#

Decodes [start, end) as decode_utf8 does, without copying the range into a new Bytes first. Bounds outside 0 <= start <= end <= length() raise a fault.

Manuscript
fn decode_utf8_range(start Int, end Int) String? { ... }

Bytes.ends_with#

Tests whether the receiver ends with these bytes.

Manuscript
fn ends_with(suffix Bytes) Bool { ... }

Bytes.float32_be#

Reads an IEEE 754 binary32 big-endian float from four bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn float32_be(at Int) Result[Float32, Error]

Bytes.float32_le#

Reads an IEEE 754 binary32 little-endian float from four bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn float32_le(at Int) Result[Float32, Error]

Bytes.float64_be#

Reads an IEEE 754 binary64 big-endian float from eight bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn float64_be(at Int) Result[Float, Error]

Bytes.float64_le#

Reads an IEEE 754 binary64 little-endian float from eight bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn float64_le(at Int) Result[Float, Error]

Bytes.get#

Returns an unsigned byte; negative indexes are relative to the end. An out-of-range index raises a fault.

Manuscript
fn get(index Int) UInt8

Bytes.get_or#

Returns an unsigned byte, or default when the index is out of range; negative indexes are relative to the end.

Manuscript
fn get_or(index Int, default UInt8) UInt8

Bytes.index_of#

Returns the first matching byte offset or null; empty value matches at zero.

Manuscript
fn index_of(value Bytes) Int? { ... }

Bytes.index_of_byte#

Returns the first offset at or after start holding the byte value, or null. A start past length() gives null; a negative start counts as zero.

Manuscript
fn index_of_byte(value UInt8, start Int = 0) Int? { ... }

Bytes.int16_be#

Reads a signed 16-bit big-endian integer from two bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn int16_be(at Int) Result[Int16, Error]

Bytes.int16_le#

Reads a signed 16-bit little-endian integer from two bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn int16_le(at Int) Result[Int16, Error]

Bytes.int32_be#

Reads a signed 32-bit big-endian integer from four bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn int32_be(at Int) Result[Int32, Error]

Bytes.int32_le#

Reads a signed 32-bit little-endian integer from four bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn int32_le(at Int) Result[Int32, Error]

Bytes.int64_be#

Reads a signed 64-bit big-endian integer from eight bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn int64_be(at Int) Result[Int, Error]

Bytes.int64_le#

Reads a signed 64-bit little-endian integer from eight bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn int64_le(at Int) Result[Int, Error]

Bytes.int8#

Reads one signed byte at at; a missing byte returns an Error of kind ERANGE. Offsets are absolute, so a negative at is out of range.

Manuscript
fn int8(at Int) Result[Int8, Error]

Bytes.into_string#

Decodes the bytes as UTF-8 text, or returns null when they are not valid. The bytes move into the string without a copy, so the receiver is consumed; decode_utf8 borrows and copies instead.

Manuscript
move fn into_string() String? { ... }

Bytes.is_empty#

Tests whether the receiver contains no bytes.

Manuscript
fn is_empty() Bool { ... }

Bytes.last_index_of#

Returns the last matching byte offset or null; empty value matches at length().

Manuscript
fn last_index_of(value Bytes) Int? { ... }

Bytes.length#

Returns the number of bytes, not the number of Unicode characters.

Manuscript
fn length() Int { ... }

Bytes.reversed#

Returns a reversed copy without changing the receiver.

Manuscript
fn reversed() Bytes { ... }

Bytes.slice#

Selects [start, end) in bytes; negative bounds are relative to the end. Bounds outside 0 <= start <= end <= length() return an Error of kind ERANGE. The result is a new copy; view borrows instead.

Manuscript
fn slice(start Int, end Int) Result[Bytes, Error] { ... }

Bytes.split#

Splits at every occurrence of separator and returns the parts as a new list. Empty parts are kept, so empty data with a nonempty separator yields one empty Bytes. An empty separator yields one Bytes per byte, and no parts for empty data.

Manuscript
fn split(separator Bytes) List[Bytes] { ... }

Bytes.starts_with#

Tests whether the receiver begins with these bytes.

Manuscript
fn starts_with(prefix Bytes) Bool { ... }

Bytes.uint16_be#

Reads an unsigned 16-bit big-endian integer from two bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn uint16_be(at Int) Result[UInt16, Error]

Bytes.uint16_le#

Reads an unsigned 16-bit little-endian integer from two bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn uint16_le(at Int) Result[UInt16, Error]

Bytes.uint32_be#

Reads an unsigned 32-bit big-endian integer from four bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn uint32_be(at Int) Result[UInt32, Error]

Bytes.uint32_le#

Reads an unsigned 32-bit little-endian integer from four bytes at at; missing bytes return an Error of kind ERANGE.

Manuscript
fn uint32_le(at Int) Result[UInt32, Error]

Bytes.uint64_be#

Reads an unsigned 64-bit big-endian integer from eight bytes at at, including the full UInt64 range. Negative offsets or missing bytes return an Error of kind ERANGE.

Manuscript
fn uint64_be(at Int) Result[UInt64, Error]

Bytes.uint64_le#

Reads an unsigned 64-bit little-endian integer from eight bytes at at, including the full UInt64 range. Negative offsets or missing bytes return an Error of kind ERANGE.

Manuscript
fn uint64_le(at Int) Result[UInt64, Error]

Bytes.uint8#

Reads one unsigned byte at at; a missing byte returns an Error of kind ERANGE.

Manuscript
fn uint8(at Int) Result[UInt8, Error]

Bytes.uvarint#

Reads an unsigned base-128 integer, least-significant group first, starting at byte offset at. Reads at most ten bytes, and the tenth must be 0 or 1. Accepts nonminimal encodings and ignores trailing bytes. An offset outside 0 <= at <= length() returns ERANGE; input that ends before the encoding does returns EBADMSG.

Manuscript
fn uvarint(at Int) Result[VarintRead[UInt64], Error]

Bytes.values#

Returns a fresh mutable list of unsigned byte values; changing it leaves the Bytes unchanged.

Manuscript
fn values() List[UInt8] { ... }

Bytes.varint#

Reads a signed 64-bit zigzag integer: the encoded values 0, 1, 2, 3 decode to 0, -1, 1, -2. Offsets, the ten-byte bound, nonminimal encodings and errors are the same as for uvarint.

Manuscript
fn varint(at Int) Result[VarintRead[Int], Error]

Bytes.view#

Borrows [start, end) of the receiver without copying; negative bounds are relative to the end. Bounds outside 0 <= start <= end <= length() raise a fault. Like xs[i], the result borrows the receiver, which cannot change while the view is used; .clone() keeps the bytes.

Manuscript
fn view(start Int, end Int) Bytes { ... }

Bytes.with_value#

Returns a copy with one byte replaced; negative indexes are relative to the end. An out-of-range index faults.

Manuscript
fn with_value(index Int, value UInt8) Bytes { ... }

BytesBuilder Native type#

Builds a byte sequence efficiently before freezing it into an immutable value.

Manuscript
type BytesBuilder {
}

fn var BytesBuilder.append(value UInt8) Void { ... }
fn var BytesBuilder.append_bytes(values Bytes) Void { ... }
fn move BytesBuilder.build() Bytes { ... }
fn var BytesBuilder.drain() Bytes { ... }
fn var BytesBuilder.drain_string() String? { ... }
fn BytesBuilder.length() Int { ... }
fn var BytesBuilder.clear() Void { ... }
fn var BytesBuilder.reserve(extra Int) Void { ... }
fn BytesBuilder.view(start Int, end Int) Bytes { ... }
fn var BytesBuilder.set(index Int, value UInt8) Void { ... }

BytesBuilder.append#

Appends one byte to the end of the builder.

Manuscript
var fn append(value UInt8) Void { ... }

BytesBuilder.append_bytes#

Appends all supplied bytes in order; the input is unchanged.

Manuscript
var fn append_bytes(values Bytes) Void { ... }

BytesBuilder.append_float32_be#

Appends an IEEE 754 binary32 big-endian float.

Manuscript
var fn append_float32_be(value Float32) Void

BytesBuilder.append_float32_le#

Appends an IEEE 754 binary32 little-endian float.

Manuscript
var fn append_float32_le(value Float32) Void

BytesBuilder.append_float64_be#

Appends an IEEE 754 binary64 big-endian float.

Manuscript
var fn append_float64_be(value Float) Void

BytesBuilder.append_float64_le#

Appends an IEEE 754 binary64 little-endian float.

Manuscript
var fn append_float64_le(value Float) Void

BytesBuilder.append_int16_be#

Appends a signed 16-bit big-endian integer.

Manuscript
var fn append_int16_be(value Int16) Void

BytesBuilder.append_int16_le#

Appends a signed 16-bit little-endian integer.

Manuscript
var fn append_int16_le(value Int16) Void

BytesBuilder.append_int32_be#

Appends a signed 32-bit big-endian integer.

Manuscript
var fn append_int32_be(value Int32) Void

BytesBuilder.append_int32_le#

Appends a signed 32-bit little-endian integer.

Manuscript
var fn append_int32_le(value Int32) Void

BytesBuilder.append_int64_be#

Appends a signed 64-bit big-endian integer.

Manuscript
var fn append_int64_be(value Int) Void

BytesBuilder.append_int64_le#

Appends a signed 64-bit little-endian integer.

Manuscript
var fn append_int64_le(value Int) Void

BytesBuilder.append_int8#

Appends one signed byte.

Manuscript
var fn append_int8(value Int8) Void

BytesBuilder.append_uint16_be#

Appends an unsigned 16-bit big-endian integer.

Manuscript
var fn append_uint16_be(value UInt16) Void

BytesBuilder.append_uint16_le#

Appends an unsigned 16-bit little-endian integer.

Manuscript
var fn append_uint16_le(value UInt16) Void

BytesBuilder.append_uint32_be#

Appends an unsigned 32-bit big-endian integer.

Manuscript
var fn append_uint32_be(value UInt32) Void

BytesBuilder.append_uint32_le#

Appends an unsigned 32-bit little-endian integer.

Manuscript
var fn append_uint32_le(value UInt32) Void

BytesBuilder.append_uint64_be#

Appends an unsigned 64-bit big-endian integer, including the full UInt64 range.

Manuscript
var fn append_uint64_be(value UInt64) Void

BytesBuilder.append_uint64_le#

Appends an unsigned 64-bit little-endian integer, including the full UInt64 range.

Manuscript
var fn append_uint64_le(value UInt64) Void

BytesBuilder.append_uvarint#

Appends the shortest unsigned base-128 encoding, from one through ten bytes.

Manuscript
var fn append_uvarint(value UInt64) Void

BytesBuilder.append_varint#

Appends the shortest signed 64-bit zigzag encoding; even the most negative Int fits in ten bytes.

Manuscript
var fn append_varint(value Int) Void

BytesBuilder.build#

Consumes the builder and returns its bytes; the builder cannot be used afterwards.

Manuscript
move fn build() Bytes { ... }

BytesBuilder.clear#

Removes every appended byte and keeps the allocated capacity for reuse.

Manuscript
var fn clear() Void { ... }

BytesBuilder.drain#

Returns the bytes appended so far and leaves the builder empty, for a builder held in a field.

Manuscript
var fn drain() Bytes { ... }

BytesBuilder.drain_string#

Returns the bytes appended so far as text without copying them, or null when they are not valid UTF-8. The builder is empty afterwards either way, and keeps no buffer.

Manuscript
var fn drain_string() String? { ... }

BytesBuilder.extend#

Appends every byte of values in order, like List.extend.

Manuscript
var fn extend(values List[UInt8]) Void

BytesBuilder.get#

Returns the appended byte at index; negative indexes are relative to the end. An out-of-range index faults.

Manuscript
fn get(index Int) UInt8

BytesBuilder.length#

Returns the number of bytes appended so far.

Manuscript
fn length() Int { ... }

BytesBuilder.reserve#

Makes room for extra more bytes, so appends up to that count do not reallocate. The bytes and length are unchanged; extra of zero or below does nothing.

Manuscript
var fn reserve(extra Int) Void { ... }

BytesBuilder.set#

Overwrites the appended byte at index in place, for patching a length prefix or header after the content is written. Negative indexes are relative to the end; an out-of-range index faults.

Manuscript
var fn set(index Int, value UInt8) Void { ... }

BytesBuilder.view#

Borrows [start, end) of the appended bytes without copying; negative bounds are relative to the end. Bounds outside 0 <= start <= end <= length() fault. The builder cannot change while the view is used.

Manuscript
fn view(start Int, end Int) Bytes { ... }

VarintRead Type#

A decoded variable-length integer and the absolute offset of the next byte. Example: first := data.uvarint(0)?; second := data.varint(first.next_offset)?.

Manuscript
type VarintRead[T] {
    value T
    next_offset Int
}

VarintRead.next_offset#

The first byte after the encoding, relative to the receiver, including for a slice.

Manuscript
next_offset Int

VarintRead.value#

The integer decoded as unsigned base-128 or signed zigzag by the read method.

Manuscript
value T

join Function#

Joins the parts end to end into one new Bytes; an empty list gives empty bytes. It allocates once and copies each part once, unlike repeated concat.

Manuscript
fn join(parts List[Bytes]) Bytes { ... }