pub fn encode(charset: &str, encode_str: &str) -> Result<String, EncodeError>
Expand description
Encodes a given input string into an encoded format using a specified character set (charset
).
This function groups bytes in chunks of 3 and maps them into 4-character segments based on charset
.
§Parameters
charset
: A string representing the character set to use for encoding. Each character incharset
should have a unique position to ensure accurate encoding.encode_str
: The input string to encode. It will be converted to bytes and processed in 3-byte chunks.
§Returns
Returns a Result
containing the encodeed String
if successful, or a EncodeError
if the charset is invalid.
§Example
use bin_encode_decode::*;
let charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_=";
let original_str = "test";
let encoded_str = encode(charset, original_str);
assert_eq!(encoded_str.unwrap(), "aab0aabLaabZaab0");