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

Implementations§

rely on old message to create new message.

Unit Test
use faster_stun::*;
use bytes::BytesMut;
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[..]);

append attribute.

append attribute to message attribute list.

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

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[..]);

try decoder bytes as message.

Unit Test
use faster_stun::*;
use bytes::BytesMut;
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§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Should always be Self
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.