Skip to main content

Crate base94_simd

Crate base94_simd 

Source
Expand description

SIMD-accelerated base94 codec: binary data in printable ASCII.

Each byte b maps to (b - kf) mod 256; mixed values >= 93 escape into two chars (0x7D/0x7E leader + follower) so every emitted char stays in 0x20..=0x7E and the output is at most 2x the input. kf is a key-mixing parameter (only its low byte participates); pass 0 for the plain codec. The format is a faithful port of openppp2 ppp/cryptography/ssea.cpp.

Performance notes (wire output unchanged):

  • encode/decode run SIMD fast paths over 16-byte blocks (see simd): the decoder solves the leader/follower alternation and escape reconstruction in-register and compacts leaders via a byte-shuffle LUT (pshufb on x86_64, vqtbl1 on aarch64; ~3x over scalar); the encoder precomputes interleaved leader/follower pairs and deletes non-escape followers through the same LUT (~2.5x).
  • Invalid input and sub-block tails fall back to the scalar reference loop, so error semantics stay bit-exact (pinned by fuzz + unit tests).

Structs§

DecodeError
The input contains characters outside the printable alphabet or a truncated/overflowing escape sequence.

Constants§

DECIMAL_MAX_LEN
Max digits of a u64 in base 94 (94^10 > 2^64 > 94^9).
SYMBOL_COUNT
Number of printable symbols: 0x20..=0x7E.

Functions§

decimal_decode
Parses base94 digits (produced by decimal_encode, possibly zero-padded with 0x20 chars) back into a u64.
decimal_encode
Minimal-length base94 digits of v; returns the digit count written.
decode_into
Decodes base94 text (see encode_into) and appends the bytes to out. On invalid input out is left unchanged and an error is returned.
encode_into
Encodes binary bytes into printable 0x20..=0x7E chars, appending to out.
encoded_len
Number of chars encode_into would emit for src.