pub struct Data {
body: Vec<u8>,
}
Expand description
A Data message represents data sent along a stream.
Upon receiving a Data message for a live stream, the client or exit sends that data onto the associated TCP connection.
These messages hold between 1 and Data::MAXLEN bytes of data each; they are the most numerous messages on the Tor network.
Fields§
§body: Vec<u8>
Contents of the cell, to be sent on a specific stream
INVARIANT: Holds between 1 and Data::MAXLEN
bytes, inclusive.
Implementations§
Source§impl Data
impl Data
Sourcepub const MAXLEN_V0: usize = 498usize
pub const MAXLEN_V0: usize = 498usize
The longest allowable body length for a single V0 data cell.
Relay command (1) + ‘Recognized’ (2) + StreamID (2) + Digest (4) + Length (2) = 11
Sourcepub const MAXLEN_V1: usize = 488usize
pub const MAXLEN_V1: usize = 488usize
The longest allowable body length for a single V1 data cell.
Tag (16) + Relay command (1) + Length (2) + StreamID (2) = 21
Sourcepub const MAXLEN: usize = 498usize
pub const MAXLEN: usize = 498usize
The longest allowable body length for any data cell.
Note that this value is too large to fit into a v1 relay cell;
see MAXLEN_V1
if you are making a v1 data cell.
Sourcepub fn new(inp: &[u8]) -> Result<Self>
pub fn new(inp: &[u8]) -> Result<Self>
Construct a new data cell.
Returns an error if inp
is longer than Data::MAXLEN
bytes.
Sourcepub fn try_split_from(
version: RelayCellFormat,
inp: &[u8],
) -> Option<(Self, &[u8])>
pub fn try_split_from( version: RelayCellFormat, inp: &[u8], ) -> Option<(Self, &[u8])>
Construct a new data cell, taking as many bytes from inp
as possible.
Return the data cell, and a slice holding any bytes that wouldn’t fit (if any).
Returns None if the input was empty.
Sourcefn new_unchecked(body: Vec<u8>) -> Self
fn new_unchecked(body: Vec<u8>) -> Self
Construct a new data cell from a provided vector of bytes.
The vector must not have more than Data::MAXLEN
bytes, and must
not be empty.
Sourcepub fn max_body_len(format: RelayCellFormat) -> usize
pub fn max_body_len(format: RelayCellFormat) -> usize
Return the maximum allowable body length for a Data message
using the provided format
.
Trait Implementations§
Source§impl Body for Data
impl Body for Data
Source§fn decode_from_reader(r: &mut Reader<'_>) -> Result<Self>
fn decode_from_reader(r: &mut Reader<'_>) -> Result<Self>
Source§fn encode_onto<W: Writer + ?Sized>(self, w: &mut W) -> EncodeResult<()>
fn encode_onto<W: Writer + ?Sized>(self, w: &mut W) -> EncodeResult<()>
Source§impl From<Data> for AnyRelayMsg
impl From<Data> for AnyRelayMsg
Source§fn from(m: Data) -> AnyRelayMsg
fn from(m: Data) -> AnyRelayMsg
Source§impl HasMemoryCostStructural for Data
impl HasMemoryCostStructural for Data
Source§fn indirect_memory_cost(&self, et: EnabledToken) -> usize
fn indirect_memory_cost(&self, et: EnabledToken) -> usize
Auto Trait Implementations§
impl Freeze for Data
impl RefUnwindSafe for Data
impl Send for Data
impl Sync for Data
impl Unpin for Data
impl UnwindSafe for Data
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
, which can then be
downcast
into Box<dyn ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
, which can then be further
downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.§impl<T> DowncastSend for T
impl<T> DowncastSend for T
§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> HasMemoryCost for Twhere
T: HasMemoryCostStructural,
impl<T> HasMemoryCost for Twhere
T: HasMemoryCostStructural,
§fn memory_cost(&self, et: EnabledToken) -> usize
fn memory_cost(&self, et: EnabledToken) -> usize
self
, in bytes Read more§impl<T> HasTypedMemoryCost<T> for Twhere
T: HasMemoryCost,
impl<T> HasTypedMemoryCost<T> for Twhere
T: HasMemoryCost,
§fn typed_memory_cost(&self, enabled: EnabledToken) -> TypedMemoryCost<T>
fn typed_memory_cost(&self, enabled: EnabledToken) -> TypedMemoryCost<T>
TypedMemoryCost<T>
rather than a raw usize
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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 moreSource§impl<T> ToHex for T
impl<T> ToHex for T
Source§fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Lower case
letters are used (e.g. f9b4ca
)Source§fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
fn encode_hex_upper<U>(&self) -> Uwhere
U: FromIterator<char>,
self
into the result. Upper case
letters are used (e.g. F9B4CA
)