Manuscript Documentation
v0.1.0

@std/bytes.ms#

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

Bytes Native type#

An immutable sequence of bytes. Indices and slice bounds are zero-based.

Manuscript
type Bytes:
    fn clone() -> Bytes:
    fn contains(value: Bytes) -> Bool:
    fn split(separator: Bytes, max_parts: Optional[Int] = none) -> List[Bytes]:
    fn slice(start: Int, end: Int) -> Result[Bytes, CollectionError]:
    fn at(index: Int) -> Optional[Int]:
    fn index_of(value: Bytes) -> Optional[Int]:
    fn last_index_of(value: Bytes) -> Optional[Int]:
    fn starts_with(prefix: Bytes) -> Bool:
    fn ends_with(suffix: Bytes) -> Bool:
    fn reversed() -> Bytes:
    fn with_value(index: Int, value: Int) -> Bytes:
    fn is_empty() -> Bool:
    fn values() -> List[Int]:
    fn concat(other: Bytes) -> Bytes:
    fn length() -> Int:
    fn to_text() -> Optional[String]:

Bytes.at#

Returns an unsigned byte; negative indexes are relative to the end, and out-of-range indexes return none.

Manuscript
fn at(index: Int) -> Optional[Int]:

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.ends_with#

Tests whether the receiver ends with these bytes.

Manuscript
fn ends_with(suffix: Bytes) -> Bool:

Bytes.index_of#

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

Manuscript
fn index_of(value: Bytes) -> Optional[Int]:

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 none; empty value matches at length().

Manuscript
fn last_index_of(value: Bytes) -> Optional[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 CollectionError.OutOfRange. The immutable result may share storage with the receiver.

Manuscript
fn slice(start: Int, end: Int) -> Result[Bytes, CollectionError]:

Bytes.split#

Splits exact byte separators into a fresh list of immutable byte views. Nonempty separators retain empty parts; empty data then yields one empty Bytes. Omitted/none max_parts is unlimited; zero returns no parts, negatives fault. A cap truncates parts; empty separator yields one Bytes per byte, no parts for empty data.

Manuscript
fn split(separator: Bytes, max_parts: Optional[Int] = none) -> List[Bytes]:

Bytes.starts_with#

Tests whether the receiver begins with these bytes.

Manuscript
fn starts_with(prefix: Bytes) -> Bool:

Bytes.to_text#

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

Manuscript
fn to_text() -> Optional[String]:

Bytes.values#

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

Manuscript
fn values() -> List[Int]:

Bytes.with_value#

Returns a copy with one byte replaced; negative indexes are relative to the end. An out-of-range index or a value outside 0 through 255 faults.

Manuscript
fn with_value(index: Int, value: Int) -> Bytes:

BytesBuilder Native type#

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

Manuscript
type BytesBuilder:
    fn append(value: Int) -> Unit:
    fn concat(values: Bytes) -> Unit:
    fn freeze() -> Bytes:

BytesBuilder.append#

Appends one unsigned byte; values outside 0 through 255 or writes after freeze fault.

Manuscript
fn append(value: Int) -> Unit:

BytesBuilder.concat#

Appends all supplied bytes in order; the input is unchanged, and a sealed builder faults.

Manuscript
fn concat(values: Bytes) -> Unit:

BytesBuilder.freeze#

Seals the builder and returns its immutable bytes; repeated freeze returns the same value.

Manuscript
fn freeze() -> Bytes:

values Function#

Returns a fresh mutable list of byte values in the range 0 through 255, like data.values().

Manuscript
fn values(data: Bytes) -> List[Int]: