Struct Sv2Frame

Source
pub struct Sv2Frame<T, B> { /* private fields */ }
Expand description

Abstraction for a Sv2 frame.

Represents a regular Sv2 frame, used for all communication outside of the Noise protocol handshake process. It contains a Header and a message payload, which can be serialized for encoding and transmission or decoded and deserialized upon receipt.

Implementations§

Source§

impl<T, B> Sv2Frame<T, B>
where T: Encodable + GetSize, B: AsMut<[u8]> + AsRef<[u8]>,

Source

pub fn serialize(self, dst: &mut [u8]) -> Result<(), Error>

Writes the serialized Sv2Frame into dst.

This operation when called on an already serialized frame is very cheap. When called on a non serialized frame, it is not so cheap (because it serializes it).

Source

pub fn payload(&mut self) -> &mut [u8]

Returns the message payload.

self can be either serialized (self.serialized is Some()) or deserialized (self.serialized is None, self.payload is Some()).

This function is only intended as a fast way to get a reference to an already serialized payload. If the frame has not yet been serialized, this function should never be used (it will panic).

Source

pub fn get_header(&self) -> Option<Header>

Sv2Frame always returns Some(self.header).

Source

pub fn from_bytes(bytes: B) -> Result<Sv2Frame<T, B>, isize>

Tries to build a Sv2Frame from raw bytes.

It assumes the raw bytes represent a serialized Sv2Frame frame (Self.serialized). Returns a Sv2Frame on success, or the number of the bytes needed to complete the frame as an error. Self.serialized is Some, but nothing is assumed or checked about the correctness of the payload.

Source

pub fn from_bytes_unchecked(bytes: B) -> Sv2Frame<T, B>

Constructs an Sv2Frame from raw bytes without performing byte content validation.

Source

pub fn size_hint(bytes: &[u8]) -> isize

After parsing bytes into a Header, this function helps to determine if the msg_length field is correctly representing the size of the frame.

  • Returns 0 if the byte slice is of the expected size according to the header.
  • Returns a negative value if the byte slice is shorter than expected; this value represents how many bytes are missing.
  • Returns a positive value if the byte slice is longer than expected; this value indicates the surplus of bytes beyond the expected size.
Source

pub fn encoded_length(&self) -> usize

If Sv2Frame is serialized, returns the length of self.serialized, otherwise, returns the length of self.payload.

Source

pub fn from_message( message: T, message_type: u8, extension_type: u16, channel_msg: bool, ) -> Option<Sv2Frame<T, B>>

Tries to build a Sv2Frame from a non-serialized payload.

Returns a Sv2Frame if the size of the payload fits in the frame, None otherwise.

Source§

impl<A, B> Sv2Frame<A, B>

Source

pub fn map<C>(self, fun: fn(A) -> C) -> Sv2Frame<C, B>

Maps a Sv2Frame<A, B> to Sv2Frame<C, B> by applying fun, which is assumed to be a closure that converts A to C

Trait Implementations§

Source§

impl<T, B> Clone for Sv2Frame<T, B>
where T: Clone, B: Clone,

Source§

fn clone(&self) -> Sv2Frame<T, B>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T, B> Debug for Sv2Frame<T, B>
where T: Debug, B: Debug,

Source§

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

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

impl<T, B> From<Sv2Frame<T, B>> for Frame<T, B>

Source§

fn from(v: Sv2Frame<T, B>) -> Frame<T, B>

Converts to this type from the input type.
Source§

impl<T, B> TryFrom<Frame<T, B>> for Sv2Frame<T, B>

Source§

type Error = Error

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

fn try_from(v: Frame<T, B>) -> Result<Sv2Frame<T, B>, Error>

Performs the conversion.

Auto Trait Implementations§

§

impl<T, B> Freeze for Sv2Frame<T, B>
where T: Freeze, B: Freeze,

§

impl<T, B> RefUnwindSafe for Sv2Frame<T, B>

§

impl<T, B> Send for Sv2Frame<T, B>
where T: Send, B: Send,

§

impl<T, B> Sync for Sv2Frame<T, B>
where T: Sync, B: Sync,

§

impl<T, B> Unpin for Sv2Frame<T, B>
where T: Unpin, B: Unpin,

§

impl<T, B> UnwindSafe for Sv2Frame<T, B>
where T: UnwindSafe, B: 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
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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V