1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
* Copyright (C) 2021 taylor.fish <contact@taylor.fish>
*
* This file is part of Base116.
*
* Base116 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Base116 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with Base116. If not, see <https://www.gnu.org/licenses/>.
*/
//! Base116 is like Base85, but it increases data size by only 1/6 instead of
//! 1/4.
//!
//! Base116 exploits properties of UTF-8 to convert arbitrary binary data to
//! valid, printable UTF-8, with a lower size overhead than is possible with
//! any printable ASCII encoding.
//!
//! For example, this binary data (in hex):
//!
//! ```text
//! 9329bd4b43da0bfdd1d97bdf081a2d42ec540155
//! ```
//!
//! is encoded as:
//!
//! ```text
//! DZ<Oȥґ|yO(WFic{2n㎨r~9*Dz
//! ```
//!
//! Wrapping ‘DZ’ and ‘Dz’ characters are added by default to make encoded data
//! easier to select, as the data may start or end with combining characters or
//! characters from right-to-left scripts.
//!
//! This crate provides both a binary and a library.
use Digit;
extern crate alloc;
const BYTES_PER_CHUNK: usize = 6;
const DIGITS_PER_CHUNK: usize = 7;
const START_CHAR: char = '\u{1f1}';
const END_CHAR: char = '\u{1f2}';
const L1_MULT: u16 = 116 + 1;
const L2_MULT: u16 = 116 * L1_MULT + 1;
pub use decode_bytes;
pub use decode_chars;
pub use decode_str;
pub use decode_to_vec;
pub use encode_to_bytes;
pub use encode_to_chars;
pub use encode_to_string;