Expose Codec via an unstable flag (#49)
Exposes `Codec` using an unstable flag. This is useful for testing.
This commit is contained in:
@@ -258,3 +258,14 @@ impl<T: AsyncRead, B> AsyncRead for FramedWrite<T, B> {
|
||||
self.inner.prepare_uninitialized_buffer(buf)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
mod unstable {
|
||||
use super::*;
|
||||
|
||||
impl<T, B> FramedWrite<T, B> {
|
||||
pub fn get_ref(&self) -> &T {
|
||||
&self.inner
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,11 @@ impl<T, B> Codec<T, B> {
|
||||
self.inner.get_ref().max_frame_size()
|
||||
}
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
pub fn get_ref(&self) -> &T {
|
||||
self.inner.get_ref().get_ref()
|
||||
}
|
||||
|
||||
pub fn get_mut(&mut self) -> &mut T {
|
||||
self.inner.get_mut().get_mut()
|
||||
}
|
||||
@@ -146,3 +151,12 @@ impl<T, B> Sink for Codec<T, B>
|
||||
Ok(Async::Ready(()))
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: remove (or improve) this
|
||||
impl<T> From<T> for Codec<T, ::std::io::Cursor<::bytes::Bytes>>
|
||||
where T: AsyncRead + AsyncWrite,
|
||||
{
|
||||
fn from(src: T) -> Self {
|
||||
Self::new(src)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ use bytes::{BufMut, Bytes, Buf};
|
||||
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub struct Data<T = Bytes> {
|
||||
stream_id: StreamId,
|
||||
data: T,
|
||||
|
||||
@@ -2,7 +2,7 @@ use frame::{self, Head, Error, Kind, StreamId, Reason};
|
||||
|
||||
use bytes::{BufMut, BigEndian};
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
|
||||
pub struct GoAway {
|
||||
last_stream_id: StreamId,
|
||||
error_code: u32,
|
||||
|
||||
@@ -15,6 +15,7 @@ use std::io::Cursor;
|
||||
/// Header frame
|
||||
///
|
||||
/// This could be either a request or a response.
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub struct Headers {
|
||||
/// The ID of the stream with which this frame is associated.
|
||||
stream_id: StreamId,
|
||||
@@ -36,7 +37,7 @@ pub struct Headers {
|
||||
#[derive(Copy, Clone, Eq, PartialEq)]
|
||||
pub struct HeadersFlag(u8);
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct PushPromise {
|
||||
/// The ID of the stream with which this frame is associated.
|
||||
stream_id: StreamId,
|
||||
@@ -63,7 +64,7 @@ pub struct Continuation {
|
||||
headers: Iter,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
#[derive(Debug, Default, Eq, PartialEq)]
|
||||
pub struct Pseudo {
|
||||
// Request
|
||||
pub method: Option<Method>,
|
||||
|
||||
@@ -61,6 +61,7 @@ pub type FrameSize = u32;
|
||||
|
||||
pub const HEADER_LEN: usize = 9;
|
||||
|
||||
#[derive(Eq, PartialEq)]
|
||||
pub enum Frame<T = Bytes> {
|
||||
Data(Data<T>),
|
||||
Headers(Headers),
|
||||
|
||||
@@ -5,7 +5,7 @@ const ACK_FLAG: u8 = 0x1;
|
||||
|
||||
pub type Payload = [u8; 8];
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Ping {
|
||||
ack: bool,
|
||||
payload: Payload,
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use frame::*;
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Priority {
|
||||
stream_id: StreamId,
|
||||
dependency: StreamDependency,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct StreamDependency {
|
||||
/// The ID of the stream dependency target
|
||||
dependency_id: StreamId,
|
||||
|
||||
@@ -2,7 +2,7 @@ use frame::{self, Head, Error, Kind, StreamId, Reason};
|
||||
|
||||
use bytes::{BufMut, BigEndian};
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
pub struct Reset {
|
||||
stream_id: StreamId,
|
||||
error_code: u32,
|
||||
|
||||
@@ -29,8 +29,8 @@ pub fn strip_padding(payload: &mut Bytes) -> Result<u8, Error> {
|
||||
return Err(Error::TooMuchPadding);
|
||||
}
|
||||
|
||||
let _ = payload.split_off(pad_len);
|
||||
let _ = payload.split_to(1);
|
||||
let _ = payload.split_off(pad_len);
|
||||
|
||||
Ok(pad_len as u8)
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ use bytes::{BufMut, BigEndian};
|
||||
|
||||
const SIZE_INCREMENT_MASK: u32 = 1 << 31;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
|
||||
pub struct WindowUpdate {
|
||||
stream_id: StreamId,
|
||||
size_increment: u32,
|
||||
|
||||
10
src/lib.rs
10
src/lib.rs
@@ -1,4 +1,4 @@
|
||||
// #![deny(warnings, missing_debug_implementations)]
|
||||
#![deny(warnings, missing_debug_implementations)]
|
||||
|
||||
#[macro_use]
|
||||
extern crate futures;
|
||||
@@ -28,9 +28,17 @@ mod error;
|
||||
mod codec;
|
||||
mod hpack;
|
||||
mod proto;
|
||||
|
||||
#[cfg(not(feature = "unstable"))]
|
||||
mod frame;
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
pub mod frame;
|
||||
|
||||
pub mod client;
|
||||
pub mod server;
|
||||
|
||||
pub use error::{Error, Reason};
|
||||
|
||||
#[cfg(feature = "unstable")]
|
||||
pub use codec::{Codec, SendError, RecvError, UserError};
|
||||
|
||||
Reference in New Issue
Block a user