1mod vbyte;
11pub use vbyte::*;
12mod varint;
13pub use varint::*;
14
15crate::cfg_feature_std! {
16 mod code_dictionary;
17 pub use code_dictionary::*;
18}
19
20crate::cfg_feature_alloc! {
21 extern crate alloc;
22 use alloc::string::{String, ToString};
23 use alloc::vec::Vec;
24}
25use irox_bits::{Bits, Error, MutBits};
26
27pub trait Codec {
29 fn encode<I: Bits, O: MutBits>(&self, input: I, output: &mut O) -> Result<usize, Error>;
31 fn decode<I: Bits, O: MutBits>(&self, input: I, output: &mut O) -> Result<usize, Error>;
33
34 crate::cfg_feature_alloc! {
35 fn encode_to_str<I: Bits>(&self, input: I) -> Result<String, Error> {
38 let vec = self.encode_to_vec(input)?;
39 Ok(String::from_utf8_lossy(vec.as_slice()).to_string())
40 }
41 }
42 crate::cfg_feature_alloc! {
43 fn encode_to_vec<I: Bits>(&self, input: I) -> Result<Vec<u8>, Error> {
46 let mut vec = Vec::new();
47 self.encode(input, &mut vec)?;
48 Ok(vec)
49 }
50 }
51 crate::cfg_feature_alloc! {
52 fn decode_to_str_lossy<I: Bits>(&self, input: I) -> Result<String, Error> {
55 let vec = self.decode_to_vec(input)?;
56 Ok(String::from_utf8_lossy(&vec).to_string())
57 }
58 }
59 crate::cfg_feature_alloc! {
60 fn decode_to_vec<I: Bits>(&self, input: I) -> Result<Vec<u8>, Error> {
62 let mut vec = Vec::new();
63 self.decode(input, &mut vec)?;
64 Ok(vec)
65 }
66 }
67}