1#![forbid(unsafe_code)]
10
11mod decoder;
12mod encoder;
13pub mod huffman;
14mod prim;
15
16pub use decoder::{Decoded, Decoder};
17pub use encoder::Encoder;
18pub use prim::{put_int, MAX_INT, STATIC_TABLE};
19
20#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct Field {
23 pub name: Vec<u8>,
24 pub value: Vec<u8>,
25}
26
27impl Field {
28 pub fn new(name: impl Into<Vec<u8>>, value: impl Into<Vec<u8>>) -> Self {
29 Field { name: name.into(), value: value.into() }
30 }
31
32 pub fn size(&self) -> u64 {
34 self.name.len() as u64 + self.value.len() as u64 + 32
35 }
36}
37
38#[derive(Debug, Clone, Copy, PartialEq, Eq)]
40pub enum Error {
41 DecompressionFailed,
43 EncoderStream,
45 DecoderStream,
47 FieldSectionTooLarge,
50 Blocked,
52}
53
54impl Error {
55 pub fn code(&self) -> u64 {
57 match self {
58 Error::EncoderStream => 0x201,
59 Error::DecoderStream => 0x202,
60 _ => 0x200,
61 }
62 }
63}
64
65impl std::fmt::Display for Error {
66 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67 let s = match self {
68 Error::DecompressionFailed => "QPACK decompression failed",
69 Error::EncoderStream => "QPACK encoder stream error",
70 Error::DecoderStream => "QPACK decoder stream error",
71 Error::FieldSectionTooLarge => "field section too large",
72 Error::Blocked => "QPACK field section blocked",
73 };
74 f.write_str(s)
75 }
76}
77
78impl std::error::Error for Error {}