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
impl StunPacketDecoder
sourcepub fn new(buffer: Vec<u8>) -> Result<Self, StunPacketDecodedError>
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.
sourcepub fn decode(
self,
data: &[u8],
) -> Result<StunPacketDecodedValue, StunPacketDecodedError>
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§
Auto Trait Implementations§
impl Freeze for StunPacketDecoder
impl RefUnwindSafe for StunPacketDecoder
impl Send for StunPacketDecoder
impl Sync for StunPacketDecoder
impl Unpin for StunPacketDecoder
impl UnwindSafe for StunPacketDecoder
Blanket Implementations§
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
Mutably borrows from an owned value. Read more