ExIcaoVds.C40 (ex_icao_vds v0.3.2)

Copy Markdown

C40 encoding and decoding for ICAO VDS header fields.

Supports Set 0 only: space (3), digits 0–9 (4–13), uppercase A–Z (14–39). Three characters are packed into two bytes using the formula: I = v1 * 1600 + v2 * 40 + v3 + 1, stored big-endian.

Partial groups (input length not a multiple of 3) are padded with SHIFT1 (value 0) so the output is always an even number of bytes.

Summary

Functions

Decodes C40 bytes, returning exactly length characters.

Returns true if all characters in string are encodable in Set 0.

Encodes string to C40 bytes. Returns {:ok, binary} or {:error, {:unsupported_character, char}} for non-Set-0 input.

Functions

decode(bytes, length \\ nil)

@spec decode(binary(), non_neg_integer() | nil) ::
  {:ok, String.t()} | {:error, term()}

Decodes C40 bytes, returning exactly length characters.

Trailing SHIFT1 padding introduced during encoding is automatically excluded. Returns {:ok, string} or {:error, reason}.

When length is nil, all decoded non-padding characters are returned.

encodable?(string)

@spec encodable?(String.t()) :: boolean()

Returns true if all characters in string are encodable in Set 0.

encode(string)

@spec encode(String.t()) :: {:ok, binary()} | {:error, term()}

Encodes string to C40 bytes. Returns {:ok, binary} or {:error, {:unsupported_character, char}} for non-Set-0 input.