pub struct MessageWriter<'a> { /* private fields */ }
Implementations§
Source§impl<'a, 'b> MessageWriter<'a>
impl<'a, 'b> MessageWriter<'a>
pub fn new(method: Method, token: &'a [u8; 12], buf: &'a mut BytesMut) -> Self
Sourcepub fn extend(
method: Method,
reader: &MessageReader<'a, 'b>,
buf: &'a mut BytesMut,
) -> Self
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[..]);
Sourcepub fn append<T: Property<'a>>(&mut self, value: T::Inner)
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[..]);
Sourcepub fn flush(&mut self, auth: Option<&[u8; 16]>) -> Result<(), StunError>
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> 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