SagaSaga
Standard Library

Std.BitString

Operations on raw binary data (Erlang bitstrings).

Functions

size

fun size : (bs: BitString) -> Int

Returns the size of the bitstring in bytes.

from_list

fun from_list : (bytes: List Int) -> BitString

Creates a bitstring from a list of byte values (0-255).

to_list

fun to_list : (bs: BitString) -> List Int

Converts a bitstring to a list of byte values.

from_string

fun from_string : (s: String) -> BitString

Creates a bitstring from a UTF-8 encoded string. This is a zero-cost operation since Dylan strings are already UTF-8 binaries.

to_string

fun to_string : (bs: BitString) -> Result String String

Attempts to decode a bitstring as a UTF-8 string. Returns Err if the bitstring is not valid UTF-8.

at

fun at : (index: Int) -> (bs: BitString) -> Maybe Int

Returns the byte at the given zero-based index, or Nothing if out of bounds.

slice

fun slice : (start: Int) -> (len: Int) -> (bs: BitString) -> BitString

Extracts a sub-bitstring starting at position for length bytes.

append

fun append : (a: BitString) -> (b: BitString) -> BitString

Appends two bitstrings. Also available via the <> operator.

zeroes

fun zeroes : (n: Int) -> BitString

Creates a bitstring of the given size filled with zero bytes.

from_byte

fun from_byte : (byte: Int) -> BitString

Creates a single-byte bitstring from an integer (0-255).

encode_int

fun encode_int : (width: Int) -> (value: Int) -> BitString

Encodes an integer as a big-endian bitstring of the given byte width.

decode_int

fun decode_int : (bs: BitString) -> Int

Decodes a big-endian integer from a bitstring.

encode_int_little

fun encode_int_little : (width: Int) -> (value: Int) -> BitString

Encodes an integer as a little-endian bitstring of the given byte width.

decode_int_little

fun decode_int_little : (bs: BitString) -> Int

Decodes a little-endian integer from a bitstring.

is_empty

fun is_empty : BitString -> Bool

Returns True if the bitstring is empty (zero bytes).