March Docs

Bytes

Bytes module: raw byte manipulation.

Bytes wraps a List(Int) of byte values in the range 0–255. March strings are UTF-8 byte sequences; Bytes exposes the raw bytes. All encoding functions (hex, base64) are implemented in pure March.

This module is self-contained: it does not depend on List. or String. being loaded, so it can be tested or used in isolation.

Types

typeBytesBytes = Bytes(List(Int))#

Functions

fnfrom_listfrom_list(xs) do Bytes(xs) end#

Wrap a List(Int) of byte values (0–255) as Bytes.

fnto_listto_list(b)#

Unwrap Bytes to the underlying List(Int).

fnemptyempty() do Bytes(Nil) end#

An empty Bytes value.

fnfrom_stringfrom_string(s)#

Convert a String to Bytes (raw UTF-8 byte values, each 0–255).

fnto_stringto_string(b)#

Convert Bytes back to a String (bytes interpreted as UTF-8).

fnlengthlength(b)#

Number of bytes.

fnis_emptyis_empty(b)#

True if the Bytes is empty.

fngetget(b, i)#

Byte at position i (0-based). Panics if out of bounds.

fnsliceslice(b, start, len)#

Sub-slice: bytes from position start with given length.

fnconcatconcat(b1, b2)#

Concatenate two Bytes values.

fnencode_utf8encode_utf8(s) do from_string(s) end#

Encode a String as UTF-8 bytes. Equivalent to from_string for March strings.

fndecode_utf8decode_utf8(b) do Ok(to_string(b)) end#

Decode UTF-8 bytes to a String. Returns Ok(s) always (same as to_string).

fnto_hexto_hex(b)#

Encode Bytes as a lowercase hexadecimal string.

fnfrom_hexfrom_hex(s)#

Parse a hex string to Bytes. Returns Err if the input is not valid hex.

fnencode_base64encode_base64(b)#

Encode Bytes as a Base64 string (with padding).

fndecode_base64decode_base64(s)#

Decode a Base64 string to Bytes. Returns Err on invalid input.