Trait Buffers
pub trait Buffers {
// Required methods
fn output(&mut self) -> &mut [u8] ⓘ;
fn input(&self) -> &[u8] ⓘ;
fn input_append_buf(&mut self) -> &mut [u8] ⓘ;
fn input_appended(&mut self, amount: usize);
fn input_consume(&mut self, amount: usize);
fn tmp_and_output(&mut self) -> (&mut [u8], &mut [u8]) ⓘ;
fn can_use_input(&self) -> bool;
}
dep_ureq
only.Expand description
Abstraction over input/output buffers.
In ureq, the buffers are provided by the Transport
.
Required Methods§
fn output(&mut self) -> &mut [u8] ⓘ
fn output(&mut self) -> &mut [u8] ⓘ
Mut handle to output buffers to write new data. Data is always
written from 0..
.
fn input(&self) -> &[u8] ⓘ
fn input(&self) -> &[u8] ⓘ
Unconsumed bytes in the input buffer as read only.
The input buffer is written to by using Buffers::input_append_buf
followed by
Buffers::input_appended
to indiciate how many additional bytes were added to the
input.
This buffer should return the total unconsumed bytes.
Example: if the internal buffer is input: Vec<u8>
, and we have counters for
filled: usize
and consumed: usize
. This returns &input[consumed..filled]
.
fn input_append_buf(&mut self) -> &mut [u8] ⓘ
fn input_append_buf(&mut self) -> &mut [u8] ⓘ
Input buffer to write to. This can be called despite there being unconsumed bytes left in the buffer already.
Example: if the internal buffer is input: Vec<u8>
, and we have counters for
filled: usize
and consumed: usize
. This returns &mut input[filled..]
.
fn input_appended(&mut self, amount: usize)
fn input_appended(&mut self, amount: usize)
Add a number of read bytes into Buffers::input_append_buf()
.
Example: if the internal buffer is input: Vec<u8>
, and we have counters for
filled: usize
and consumed: usize
, this increases filled
.
fn input_consume(&mut self, amount: usize)
fn input_consume(&mut self, amount: usize)
Consume a number of bytes from &input
.
Example: if the internal buffer is input: Vec<u8>
, and we have counters for
filled: usize
and consumed: usize
, this increases consumed
.
fn tmp_and_output(&mut self) -> (&mut [u8], &mut [u8]) ⓘ
fn tmp_and_output(&mut self) -> (&mut [u8], &mut [u8]) ⓘ
Helper to get a scratch buffer (tmp
) and the output buffer. This is used when
sending the request body in which case we use a Read
trait to read from the
SendBody
into tmp and then write it to the output buffer.
fn can_use_input(&self) -> bool
fn can_use_input(&self) -> bool
Helper to determine if the &input
already holds unconsumed data or we need to
read more input from the transport. This indicates two things:
- There is unconsumed data in the input buffer
- The last call to consume was > 0.
Step 2 is because the input buffer might contain half a response body, and we cannot parse it until we got the entire buffer. In this case the transport must read more data first.