bluetape-rs-codec
Codec and encoding helpers for bluetape-rs.
This crate is part of the 0.4.0 workspace release. It provides strict
hexadecimal encoding and decoding primitives plus focused Base64, Base58,
Base62, and UTF-8 text/byte boundary helpers.
Scope
- strict hex encoding and decoding
- Base64 standard and URL-safe variants
- Bitcoin Base58 byte encoding
- byte-oriented Base62 encoding
- typed errors for caller-owned invalid encoded input
- UTF-8 text/byte boundary helpers for codec call sites
Out Of Scope
- compression helpers; those belong to
0.4.0 - serde-oriented serialization interfaces; those belong to
0.5.0 - encryption, signing, checksums, database bind encoding, random string helpers, and broad text normalization
Usage
[]
= "0.4.0"
Or enable the optional root facade:
[]
= { = "0.4.0", = ["codec"] }
Hex
use ;
let bytes = ;
assert_eq!;
assert_eq!;
assert_eq!;
The decoder is intentionally strict. It accepts uppercase and lowercase ASCII
hexadecimal digits, but rejects odd-length input, prefixes such as 0x,
whitespace, separators, and non-ASCII digits with typed errors that include the
input byte position when available.
Base64
use ;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Standard helpers use the + and / alphabet. URL-safe helpers use - and
_. Function names ending in _unpadded reject = padding during decode.
Base58 And Base62
use ;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Base58 uses the Bitcoin alphabet
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz and preserves
leading zero bytes as 1. Base62 uses the bluetape alphabet
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz and preserves
leading zero bytes as 0. The current Base62 primitive is byte-oriented;
integer, UUID, and ID-generator rendering APIs remain separate higher-level
scope.
UTF-8 Text Boundaries
use ;
let token = encode_base64_url_unpadded;
assert_eq!;
let bytes = decode_base64_url_unpadded.expect;
assert_eq!;
assert_eq!;
decode_utf8_text is non-lossy and returns a typed [TextDecodeError] with the
valid byte prefix when the decoded bytes are not valid UTF-8. Lossy replacement
is only available through the explicitly named decode_utf8_text_lossy helper.
General string utilities, normalization, compression registries, and
serde-oriented serialization stay outside this crate.
Test Layout
Public codec behavior is tested from the crate boundary under tests/:
tests/hex.rstests/base64.rstests/base58.rstests/base62.rstests/text.rs
Source-local tests are reserved for private implementation details, such as the shared internal base-N converter.