mod vbyte;
pub use vbyte::*;
mod varint;
pub use varint::*;
crate::cfg_feature_std! {
mod code_dictionary;
pub use code_dictionary::*;
}
crate::cfg_feature_alloc! {
extern crate alloc;
use alloc::string::{String, ToString};
use alloc::vec::Vec;
}
use irox_bits::{Bits, Error, MutBits};
pub trait Codec {
fn encode<I: Bits, O: MutBits>(&self, input: I, output: &mut O) -> Result<usize, Error>;
fn decode<I: Bits, O: MutBits>(&self, input: I, output: &mut O) -> Result<usize, Error>;
crate::cfg_feature_alloc! {
fn encode_to_str<I: Bits>(&self, input: I) -> Result<String, Error> {
let vec = self.encode_to_vec(input)?;
Ok(String::from_utf8_lossy(vec.as_slice()).to_string())
}
}
crate::cfg_feature_alloc! {
fn encode_to_vec<I: Bits>(&self, input: I) -> Result<Vec<u8>, Error> {
let mut vec = Vec::new();
self.encode(input, &mut vec)?;
Ok(vec)
}
}
crate::cfg_feature_alloc! {
fn decode_to_str_lossy<I: Bits>(&self, input: I) -> Result<String, Error> {
let vec = self.decode_to_vec(input)?;
Ok(String::from_utf8_lossy(&vec).to_string())
}
}
crate::cfg_feature_alloc! {
fn decode_to_vec<I: Bits>(&self, input: I) -> Result<Vec<u8>, Error> {
let mut vec = Vec::new();
self.decode(input, &mut vec)?;
Ok(vec)
}
}
}