Struct MessageWriter

Source
pub struct MessageWriter<'a> { /* private fields */ }

Implementations§

Source§

impl<'a, 'b> MessageWriter<'a>

Source

pub fn new(method: Method, token: &'a [u8; 12], buf: &'a mut BytesMut) -> Self

Source

pub fn extend( method: Method, reader: &MessageReader<'a, 'b>, buf: &'a mut BytesMut, ) -> Self

rely on old message to create new message.

§Unit Test
use bytes::BytesMut;
use faster_stun::*;
use std::convert::TryFrom;

let buffer = [
    0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
    0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];

let mut attributes = Vec::new();
let mut buf = BytesMut::new();
let old = MessageReader::decode(&buffer[..], &mut attributes).unwrap();
MessageWriter::extend(Method::Binding(Kind::Request), &old, &mut buf);
assert_eq!(&buf[..], &buffer[..]);
Source

pub fn append<T: Property<'a>>(&mut self, value: T::Inner)

append attribute.

append attribute to message attribute list.

§Unit Test
use bytes::BytesMut;
use faster_stun::attribute::UserName;
use faster_stun::*;
use std::convert::TryFrom;

let buffer = [
    0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
    0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];

let new_buf = [
    0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
    0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b, 0x00, 0x06, 0x00,
    0x05, 0x70, 0x61, 0x6e, 0x64, 0x61, 0x00, 0x00, 0x00,
];

let mut buf = BytesMut::new();
let mut attributes = Vec::new();
let old = MessageReader::decode(&buffer[..], &mut attributes).unwrap();
let mut message =
    MessageWriter::extend(Method::Binding(Kind::Request), &old, &mut buf);
message.append::<UserName>("panda");
assert_eq!(&new_buf[..], &buf[..]);
Source

pub fn flush(&mut self, auth: Option<&[u8; 16]>) -> Result<(), StunError>

try decoder bytes as message.

§Unit Test
use bytes::BytesMut;
use faster_stun::*;
use std::convert::TryFrom;

let buffer = [
    0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
    0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];

let result = [
    0x00u8, 0x01, 0x00, 0x20, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
    0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b, 0x00, 0x08, 0x00,
    0x14, 0x45, 0x0e, 0x6e, 0x44, 0x52, 0x1e, 0xe8, 0xde, 0x2c, 0xf0, 0xfa,
    0xb6, 0x9c, 0x5c, 0x19, 0x17, 0x98, 0xc6, 0xd9, 0xde, 0x80, 0x28, 0x00,
    0x04, 0xed, 0x41, 0xb6, 0xbe,
];

let mut attributes = Vec::new();
let mut buf = BytesMut::with_capacity(1280);
let old = MessageReader::decode(&buffer[..], &mut attributes).unwrap();
let mut message =
    MessageWriter::extend(Method::Binding(Kind::Request), &old, &mut buf);
message
    .flush(Some(&util::long_key("panda", "panda", "raspberry")))
    .unwrap();
assert_eq!(&buf[..], &result);

Auto Trait Implementations§

§

impl<'a> Freeze for MessageWriter<'a>

§

impl<'a> RefUnwindSafe for MessageWriter<'a>

§

impl<'a> Send for MessageWriter<'a>

§

impl<'a> Sync for MessageWriter<'a>

§

impl<'a> Unpin for MessageWriter<'a>

§

impl<'a> !UnwindSafe for MessageWriter<'a>

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.