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
use crate::{
decoder::{self, match_range_ct},
encoder::{self, match_gt_ct},
Error, InvalidEncodingError, InvalidLengthError,
};
#[cfg(feature = "alloc")]
use alloc::{string::String, vec::Vec};
pub fn decode(src: impl AsRef<[u8]>, dst: &mut [u8]) -> Result<&[u8], Error> {
decoder::decode(src, dst, false, decode_6bits)
}
pub fn decode_in_place(buf: &mut [u8]) -> Result<&[u8], InvalidEncodingError> {
decoder::decode_in_place(buf, false, decode_6bits)
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn decode_vec(input: &str) -> Result<Vec<u8>, Error> {
decoder::decode_vec(input, false, decode_6bits)
}
pub fn encode<'a>(src: &[u8], dst: &'a mut [u8]) -> Result<&'a str, InvalidLengthError> {
encoder::encode(src, dst, false, encode_6bits)
}
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
pub fn encode_string(input: &[u8]) -> String {
encoder::encode_string(input, false, encode_6bits)
}
pub fn encoded_len(bytes: &[u8]) -> usize {
encoder::encoded_len(bytes, false)
}
#[inline(always)]
fn decode_6bits(src: u8) -> i16 {
let mut res: i16 = -1;
res += match_range_ct(src, b'.'..b'/', src as i16 - 45);
res += match_range_ct(src, b'A'..b'Z', src as i16 - 62);
res += match_range_ct(src, b'a'..b'z', src as i16 - 68);
res + match_range_ct(src, b'0'..b'9', src as i16 + 7)
}
#[inline(always)]
fn encode_6bits(mut src: i16) -> u8 {
src += 0x2e;
src += match_gt_ct(src, 0x2f, 17);
src += match_gt_ct(src, 0x5a, 6);
src -= match_gt_ct(src, 0x7a, 75);
src as u8
}