pub struct Buffer<P: ReadPrecision = ()> { /* private fields */ }proxy-handshake or client-handshake only.Expand description
An input buffer containing maybe some socks data
Buffer has a capacity set at creation time,
and records how much data it contains.
Data is consumed by step(), and
received data is appended using a RecvStep returned from step.
The P type parameter indicates whether we’re allowing read-ahead,
or doing only precise reads.
See ReadPrecision for details.
Implementations§
Source§impl Buffer<PreciseReads>
impl Buffer<PreciseReads>
Sourcepub fn new_precise() -> Self
pub fn new_precise() -> Self
Creates a new Buffer for reeading precisely
use tor_socksproto::{Handshake as _, SocksProxyHandshake, SocksRequest};
let mut hs = SocksProxyHandshake::new();
let mut buf = tor_socksproto::Buffer::new_precise();Source§impl<P: ReadPrecision> Buffer<P>
impl<P: ReadPrecision> Buffer<P>
Sourcepub fn with_size(size: usize) -> Self
pub fn with_size(size: usize) -> Self
Creates a new Buffer with a specified size
Specify the P type parameter according to whether you wanted
a Buffer like from Buffer::new(), which will read eagerly,
or one like from Buffer::new_precise(), which will read eagerly,
See ReadPrecision.
let mut buf = tor_socksproto::Buffer::<tor_socksproto::PreciseReads>::with_size(2048);Sourcepub fn from_parts(buf: Box<[u8]>, filled: usize) -> Self
pub fn from_parts(buf: Box<[u8]>, filled: usize) -> Self
Creates a new Buffer from a partially-filed buffer
buf[..filled]should contain data already read from the peerbuf[filled..]should be zero (or other innocuous data), and will not be used (except if there are bugs)
Using this and into_parts to obtain a Buffer
with a different read precision (different P type parameter)
can result in malfunctions.
Sourcepub fn into_parts(self) -> (Box<[u8]>, usize)
pub fn into_parts(self) -> (Box<[u8]>, usize)
Disassembles a Buffer, returning the pieces
Sourcepub fn unfilled_slice(&mut self) -> &mut [u8] ⓘ
pub fn unfilled_slice(&mut self) -> &mut [u8] ⓘ
The portion of the buffer that is available for writing new data.
The caller may fill this (from the beginning) with more data,
and then call Buffer::note_received.
Normally, the caller will do this after receiving a NextStep::Recv instruction.
Where possible, prefer RecvStep::buf and RecvStep::note_received.
Sourcepub fn filled_slice(&mut self) -> &[u8] ⓘ
pub fn filled_slice(&mut self) -> &[u8] ⓘ
The portion of the buffer that contains already-read, but unprocessed, data.
Callers will not normally want this.
Sourcepub fn note_received(&mut self, len: NonZeroUsize)
pub fn note_received(&mut self, len: NonZeroUsize)
Notes that len bytes have been received.
The actual data must already have been written to the slice from .unfilled_slice().
Where possible, prefer RecvStep::buf and RecvStep::note_received.
(It doesn’t make sense to call this with len == 0.
If the 0 came from a read call, this indicates EOF -
but that might not be an error if the protocol implementation doesn’t need more data.
RecvStep::note_received handles this properly.)
§Panics
len must be no more than .unfilled_slice().len().
Trait Implementations§
Source§impl<P: ReadPrecision> Debug for Buffer<P>
impl<P: ReadPrecision> Debug for Buffer<P>
Auto Trait Implementations§
impl<P> Freeze for Buffer<P>where
P: Freeze,
impl<P> RefUnwindSafe for Buffer<P>where
P: RefUnwindSafe,
impl<P> Send for Buffer<P>where
P: Send,
impl<P> Sync for Buffer<P>where
P: Sync,
impl<P> Unpin for Buffer<P>where
P: Unpin,
impl<P> UnsafeUnpin for Buffer<P>where
P: UnsafeUnpin,
impl<P> UnwindSafe for Buffer<P>where
P: UnwindSafe,
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more