#![forbid(unsafe_code)]
mod decoder;
mod encoder;
pub mod huffman;
mod prim;
pub use decoder::{Decoded, Decoder};
pub use encoder::Encoder;
pub use prim::{put_int, MAX_INT, STATIC_TABLE};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Field {
pub name: Vec<u8>,
pub value: Vec<u8>,
}
impl Field {
pub fn new(name: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>) -> Self {
Field { name: name.into(), value: value.into() }
}
pub fn size(&self) -> u64 {
self.name.len() as u64 + self.value.len() as u64 + 32
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Error {
DecompressionFailed,
EncoderStream,
DecoderStream,
FieldSectionTooLarge,
Blocked,
}
impl Error {
pub fn code(&self) -> u64 {
match self {
Error::EncoderStream => 0x201,
Error::DecoderStream => 0x202,
_ => 0x200,
}
}
}
impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let s = match self {
Error::DecompressionFailed => "QPACK decompression failed",
Error::EncoderStream => "QPACK encoder stream error",
Error::DecoderStream => "QPACK decoder stream error",
Error::FieldSectionTooLarge => "field section too large",
Error::Blocked => "QPACK field section blocked",
};
f.write_str(s)
}
}
impl std::error::Error for Error {}