Struct Buffer

Source
pub struct Buffer<P: ReadPrecision = ()> {
    buf: Box<[u8]>,
    filled: usize,
    precision: P,
}
Available on crate features 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.

Fields§

§buf: Box<[u8]>

The actual buffer

§filled: usize

[0..filled] has data that’s been read but not yet drained

§precision: P

Marker for the precision

Implementations§

Source§

impl Buffer<()>

Source

pub fn new() -> Self

Creates a new default Buffer

Source§

impl Buffer<PreciseReads>

Source

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>

Source

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);
Source

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 peer
  • buf[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 differetn the read precision (different P type parameter) can result in malfunctions.

Source

pub fn into_parts(self) -> (Box<[u8]>, usize)

Disassembles a Buffer, returning the pieces

Source

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.

Source

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.

Source

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 implemnetation 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>

Source§

fn fmt(&self, formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<P: ReadPrecision> Default for Buffer<P>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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> UnwindSafe for Buffer<P>
where P: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> MaybeSendSync for T