use alloc::vec::Vec;
use thiserror::Error;
mod core;
#[cfg(feature = "decompression")]
mod decode;
#[cfg(feature = "compression")]
mod encode;
#[cfg(not(feature = "no_std"))]
mod io;
#[cfg(feature = "decompression")]
pub use decode::*;
#[cfg(feature = "compression")]
pub use encode::*;
#[cfg(not(feature = "no_std"))]
pub use io::*;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct FramingConfig {
pub max_resources: usize,
pub max_metadata_bytes: usize,
pub max_frame_bytes: usize,
pub max_output_bytes: u64,
pub max_container_bytes: u64,
}
impl Default for FramingConfig {
fn default() -> Self {
Self {
max_resources: 10_000,
max_metadata_bytes: 1 << 20,
max_frame_bytes: 64 << 20,
max_output_bytes: 256 << 20,
max_container_bytes: 1 << 30,
}
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct MetadataField<'a> {
pub code: [u8; 2],
pub value: &'a [u8],
}
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MetadataEntry {
pub code: [u8; 2],
pub value: Vec<u8>,
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub struct ResourceInfo {
pub offset: u64,
pub length: u64,
pub decoded_size: u64,
}
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum FramedError {
#[error("invalid framed container: {0}")]
Invalid(&'static str),
#[error("unsupported framed container version {0}")]
UnsupportedVersion(u8),
#[error("unexpected end of framed container")]
UnexpectedEndOfInput,
#[error("framing limit exceeded: {0}")]
Limit(&'static str),
#[error("framing size or offset overflow")]
Overflow,
#[error("framing allocation failed")]
Allocation,
#[error("invalid framed session state")]
InvalidState,
#[error("framed output must be drained before adding a resource")]
OutputPending,
#[cfg(feature = "compression")]
#[error("framed encoder configuration: {0}")]
Config(#[from] crate::ConfigError),
#[cfg(feature = "compression")]
#[error("framed resource compression: {0}")]
Encode(#[from] crate::EncodeError),
#[cfg(feature = "decompression")]
#[error("framed resource decompression: {0}")]
Decode(#[from] crate::DecodeError),
#[cfg(not(feature = "no_std"))]
#[error("framed transport: {0}")]
Io(#[from] std::io::Error),
}