Module encoding/hex

encoding/hex

Hexadecimal encoding and decoding.

Converts between raw bytes (ArrayList(u8)) and hex strings.

Example

{ hex_encode, hex_decode } :: import "std/encoding/hex";

s := hex_encode(data);         // "deadbeef"
b := hex_decode("deadbeef");

Types

EncodingError

Encoding/decoding error type.

Variants

VariantFieldsDescription
InvalidCharch: u8

Invalid character encountered during decoding.

OddLength

Input string has odd length (hex requires even length).

Trait Implementations

impl(EncodingError, ToString(...))
to_string : (self -> match(self, .InvalidChar(ch) => `encoding error: invalid character ${ch}`, .OddLength => `encoding error: odd length` ) )
impl(EncodingError, Error())

Functions

hex_encode function
fn(data : ArrayList(u8)) -> String

Encode bytes as a lowercase hexadecimal string.

Parameters

NameTypeNotes
dataArrayList(u8)

Returns: String

hex_decode function
fn(s : str, using(exn : Exception)) -> ArrayList(u8)

Decode a hexadecimal string to bytes. Throws via Exception on invalid input.

Parameters

NameTypeNotes
sstr

Effects

NameTypeNotes
exnExceptioncomptime, implicit

Returns: ArrayList(u8)