add streaming body to requests and responses #3
2 changed files with 9 additions and 9 deletions
|
@ -91,8 +91,8 @@ pub(crate) trait RecvLoop: Sync + 'static {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
let has_cont = (size & CHUNK_HAS_CONTINUATION) != 0;
|
let has_cont = (size & CHUNK_FLAG_HAS_CONTINUATION) != 0;
|
||||||
let is_error = (size & ERROR_MARKER) != 0;
|
let is_error = (size & CHUNK_FLAG_ERROR) != 0;
|
||||||
let size = (size & CHUNK_LENGTH_MASK) as usize;
|
let size = (size & CHUNK_LENGTH_MASK) as usize;
|
||||||
let mut next_slice = vec![0; size as usize];
|
let mut next_slice = vec![0; size as usize];
|
||||||
read.read_exact(&mut next_slice[..]).await?;
|
read.read_exact(&mut next_slice[..]).await?;
|
||||||
|
|
14
src/send.rs
14
src/send.rs
|
@ -19,8 +19,8 @@ use crate::stream::*;
|
||||||
// Chunk format:
|
// Chunk format:
|
||||||
// - u32 BE: request id (same for request and response)
|
// - u32 BE: request id (same for request and response)
|
||||||
// - u16 BE: chunk length + flags:
|
// - u16 BE: chunk length + flags:
|
||||||
// CHUNK_HAS_CONTINUATION when this is not the last chunk of the stream
|
// CHUNK_FLAG_HAS_CONTINUATION when this is not the last chunk of the stream
|
||||||
// ERROR_MARKER if this chunk denotes an error
|
// CHUNK_FLAG_ERROR if this chunk denotes an error
|
||||||
// (these two flags are exclusive, an error denotes the end of the stream)
|
// (these two flags are exclusive, an error denotes the end of the stream)
|
||||||
// **special value** 0xFFFF indicates a CANCEL message
|
// **special value** 0xFFFF indicates a CANCEL message
|
||||||
// - [u8; chunk_length], either
|
// - [u8; chunk_length], either
|
||||||
|
@ -28,14 +28,14 @@ use crate::stream::*;
|
||||||
// - if error:
|
// - if error:
|
||||||
// - u8: error kind, encoded using error::io_errorkind_to_u8
|
// - u8: error kind, encoded using error::io_errorkind_to_u8
|
||||||
// - rest: error message
|
// - rest: error message
|
||||||
// - absent for cancel message
|
// - absent for cancel messag
|
||||||
|
|
||||||
pub(crate) type RequestID = u32;
|
pub(crate) type RequestID = u32;
|
||||||
pub(crate) type ChunkLength = u16;
|
pub(crate) type ChunkLength = u16;
|
||||||
|
|
||||||
pub(crate) const MAX_CHUNK_LENGTH: ChunkLength = 0x3FF0;
|
pub(crate) const MAX_CHUNK_LENGTH: ChunkLength = 0x3FF0;
|
||||||
pub(crate) const ERROR_MARKER: ChunkLength = 0x4000;
|
pub(crate) const CHUNK_FLAG_ERROR: ChunkLength = 0x4000;
|
||||||
pub(crate) const CHUNK_HAS_CONTINUATION: ChunkLength = 0x8000;
|
pub(crate) const CHUNK_FLAG_HAS_CONTINUATION: ChunkLength = 0x8000;
|
||||||
pub(crate) const CHUNK_LENGTH_MASK: ChunkLength = 0x3FFF;
|
pub(crate) const CHUNK_LENGTH_MASK: ChunkLength = 0x3FFF;
|
||||||
pub(crate) const CANCEL_REQUEST: ChunkLength = 0xFFFF;
|
pub(crate) const CANCEL_REQUEST: ChunkLength = 0xFFFF;
|
||||||
|
|
||||||
|
@ -237,8 +237,8 @@ impl DataFrame {
|
||||||
fn header(&self) -> [u8; 2] {
|
fn header(&self) -> [u8; 2] {
|
||||||
let header_u16 = match self {
|
let header_u16 = match self {
|
||||||
DataFrame::Data(data, false) => data.len() as u16,
|
DataFrame::Data(data, false) => data.len() as u16,
|
||||||
DataFrame::Data(data, true) => data.len() as u16 | CHUNK_HAS_CONTINUATION,
|
DataFrame::Data(data, true) => data.len() as u16 | CHUNK_FLAG_HAS_CONTINUATION,
|
||||||
DataFrame::Error(msg) => msg.len() as u16 | ERROR_MARKER,
|
DataFrame::Error(msg) => msg.len() as u16 | CHUNK_FLAG_ERROR,
|
||||||
};
|
};
|
||||||
ChunkLength::to_be_bytes(header_u16)
|
ChunkLength::to_be_bytes(header_u16)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue