Bunch of work

This commit is contained in:
Carl Lerche
2017-06-16 16:37:51 -07:00
parent c12a9a86ae
commit f6fd6a6d6e
10 changed files with 204 additions and 127 deletions

View File

@@ -4,16 +4,21 @@ use super::table::{Table, Index};
use http::header::{HeaderName, HeaderValue};
use bytes::{BytesMut, BufMut};
#[derive(Debug)]
pub struct Encoder {
table: Table,
size_update: Option<SizeUpdate>,
}
#[derive(Debug)]
pub enum Encode {
Full,
Partial(Index),
Partial(EncodeState),
}
#[derive(Debug)]
pub struct EncodeState(Index);
#[derive(Debug, PartialEq, Eq)]
pub enum EncoderError {
BufferOverflow,
@@ -67,7 +72,7 @@ impl Encoder {
}
/// Encode a set of headers into the provide buffer
pub fn encode<I>(&mut self, resume: Option<Index>, headers: &mut I, dst: &mut BytesMut)
pub fn encode<I>(&mut self, resume: Option<EncodeState>, headers: &mut I, dst: &mut BytesMut)
-> Result<Encode, EncoderError>
where I: Iterator<Item=Header>,
{
@@ -81,13 +86,13 @@ impl Encoder {
return Err(e);
}
if let Some(index) = resume {
if let Some(resume) = resume {
let len = dst.len();
match self.encode_header(&index, dst) {
match self.encode_header(&resume.0, dst) {
Err(EncoderError::BufferOverflow) => {
dst.truncate(len);
return Ok(Encode::Partial(index));
return Ok(Encode::Partial(resume));
}
Err(e) => return Err(e),
Ok(_) => {}
@@ -101,7 +106,7 @@ impl Encoder {
match self.encode_header(&index, dst) {
Err(EncoderError::BufferOverflow) => {
dst.truncate(len);
return Ok(Encode::Partial(index));
return Ok(Encode::Partial(EncodeState(index)));
}
Err(e) => return Err(e),
Ok(_) => {}

View File

@@ -7,7 +7,6 @@ mod table;
#[cfg(test)]
mod test;
pub use self::encoder::{Encoder, Encode, EncoderError};
pub use self::encoder::{Encoder, Encode, EncoderError, EncodeState};
pub use self::header::Header;
pub use self::decoder::{Decoder, DecoderError};
pub use self::table::Index;

View File

@@ -9,6 +9,7 @@ use std::collections::VecDeque;
use std::hash::{Hash, Hasher};
/// HPACK encoder table
#[derive(Debug)]
pub struct Table {
mask: usize,
indices: Vec<Option<Pos>>,
@@ -37,6 +38,7 @@ pub enum Index {
NotIndexed(Header),
}
#[derive(Debug)]
struct Slot {
hash: HashValue,
header: Header,