Skip to main content

omp_core/encoding/
mod.rs

1//! Generic base-N encoding/decoding with compile-time dictionaries.
2//!
3//! Provides a unified interface for binary-to-text encodings (hex, base64,
4//! base32) with optimized runtime implementations and const-friendly fallbacks.
5//!
6//! # Features
7//!
8//! - **Const evaluation**: All encoding/decoding logic works in const contexts
9//! - **Zero-copy iterators**: Streaming encoders and decoders with exact size
10//!   hints
11//! - **Optimized paths**: Hand-tuned implementations for Base64/Base32
12//! - **Flexible dictionaries**: Support for custom alphabets and padding
13//!   schemes
14//! - **Stack allocation**: Fixed-size [`ArrayStr`] and [`Array`] wrappers
15//!
16//! # Submodules
17//!
18//! - [`hex`]: Hexadecimal encoding with upper/lowercase support
19//! - [`base64`]: Standard and URL-safe Base64 encodings
20//! - [`base64_url`]: URL-safe Base64 encodings
21//! - [`base32`]: RFC 4648 Base32, Base32-Hex, and Base32-DNS variants
22//! - [`base32_hex`]: RFC 4648 Base32-Hex
23//! - [`base32_dns`]: RFC 4648 Base32-DNS
24//!
25//! # Examples
26//! ```
27//! use omp_core::{base64, hex};
28//!
29//! // Hex encoding
30//! let encoded = hex::encode(b"Hello").into_string();
31//! assert_eq!(encoded, "48656c6c6f");
32//!
33//! // Base64 encoding
34//! let encoded = base64::encode(b"Hello").into_string();
35//! assert_eq!(encoded, "SGVsbG8=");
36//!
37//! // Const evaluation
38//! const HEX: hex::ArrayStr<5> = hex::encode_n(b"Hello");
39//! assert_eq!(&*HEX, "48656c6c6f");
40//! ```
41
42mod fixed_arr;
43pub mod hex;
44mod opt;
45pub use fixed_arr::{Array, ArrayStr};
46pub(crate) use fixed_arr::{ascii_to_str, ascii_to_str_owned, format_with_precision};
47
48mod error;
49pub use error::{DecodeError, Result};
50
51mod base_n;
52pub use base_n::{
53	DecodeWriter, Decoder, EncodeWriter, Encoder, Encoding, base32, base32_dns, base32_hex, base64,
54	base64_url,
55};