decode

Function decode 

Source
pub fn decode(
    encoded: &str,
    dictionary: &Dictionary,
) -> Result<Vec<u8>, DecodeError>
Expand description

Decodes a string back to binary data using the specified dictionary.

Automatically selects the appropriate decoding strategy based on the dictionary’s mode (Radix, Chunked, or ByteRange).

§Arguments

  • encoded - The encoded string to decode
  • dictionary - The dictionary used for encoding

§Returns

A Result containing the decoded binary data, or a DecodeError if the input is invalid

§Errors

Returns DecodeError if:

  • The input contains invalid characters
  • The input is empty
  • The padding is invalid (for chunked mode)

§Examples

use base_d::{Dictionary, EncodingMode, encode, decode};

let chars: Vec<char> = "01".chars().collect();
let dictionary = Dictionary::builder()
    .chars(chars)
    .mode(EncodingMode::Radix)
    .build()?;
let data = b"Hi";
let encoded = encode(data, &dictionary);
let decoded = decode(&encoded, &dictionary)?;
assert_eq!(data, &decoded[..]);