stun_agent

Struct StunPacketDecoder

source
pub struct StunPacketDecoder { /* private fields */ }
Expand description

A STUN packet decoder that can be used to decode a STUN packet. The StunPacketDecoder is helpful when reading bytes from a stream oriented connection, such as a TCP stream, or even when reading bytes from a datagram oriented connection, such as a UDP socket when the STUN packet is fragmented.


 //let buffer = vec![0; 1024];
 //let mut decoder = StunPacketDecoder::new(buffer).expect("Failed to create decoder");

Implementations§

source§

impl StunPacketDecoder

source

pub fn new(buffer: Vec<u8>) -> Result<Self, StunPacketDecodedError>

Creates a new STUN packet decoder using the provided buffer. The buffer must be at least 20 bytes long to accommodate the STUN message header. If the buffer is too small, an error is returned.

source

pub fn decode( self, data: &[u8], ) -> Result<StunPacketDecodedValue, StunPacketDecodedError>

Decodes the given data and returns the decoded STUN packet. This method takes the data read so far as an argument and returns one of the following outcomes:

  • If the STUN packet has been fully decoded, the method returns the decoded STUN packet and the number of bytes consumed.
  • If the STUN packet has not been fully decoded, the method returns the decoder and the number of bytes still needed to complete the STUN packet, if known.
  • If the buffer is too small or the header does not correspond to a STUN message, the method returns an error. Note: This method does not perform a full validation of the STUN message; it only checks the header. Integrity checks and other validations will be performed by the STUN agent.

Trait Implementations§

source§

impl Debug for StunPacketDecoder

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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