pub struct MessageEncoder<'a> {
pub token: &'a [u8],
pub bytes: &'a mut BytesMut,
}Fields§
§token: &'a [u8]§bytes: &'a mut BytesMutImplementations§
Source§impl<'a, 'b> MessageEncoder<'a>
impl<'a, 'b> MessageEncoder<'a>
pub fn new( method: StunMethod, token: &'a [u8; 12], bytes: &'a mut BytesMut, ) -> Self
Sourcepub fn extend(
method: StunMethod,
reader: &MessageRef<'a>,
bytes: &'a mut BytesMut,
) -> Self
pub fn extend( method: StunMethod, reader: &MessageRef<'a>, bytes: &'a mut BytesMut, ) -> Self
rely on old message to create new message.
§Test
use bytes::BytesMut;
use std::convert::TryFrom;
use turn_server::stun::method::{
StunMethod as Method, StunMethodKind as Kind,
};
use turn_server::stun::*;
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 = Attributes::default();
let mut buf = BytesMut::new();
let old = MessageDecoder::decode(&buffer[..], &mut attributes).unwrap();
MessageEncoder::extend(Method::Binding(Kind::Request), &old, &mut buf);
assert_eq!(&buf[..], &buffer[..]);Sourcepub fn append<'c, T: Attribute<'c>>(&'c mut self, value: T::Item)
pub fn append<'c, T: Attribute<'c>>(&'c mut self, value: T::Item)
append attribute.
append attribute to message attribute list.
§Test
use bytes::BytesMut;
use std::convert::TryFrom;
use turn_server::stun::attribute::UserName;
use turn_server::stun::method::{
StunMethod as Method, StunMethodKind as Kind,
};
use turn_server::stun::*;
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 = Attributes::default();
let old = MessageDecoder::decode(&buffer[..], &mut attributes).unwrap();
let mut message =
MessageEncoder::extend(Method::Binding(Kind::Request), &old, &mut buf);
message.append::<UserName>("panda");
assert_eq!(&new_buf[..], &buf[..]);Sourcepub fn flush(&mut self, digest: Option<&[u8; 16]>) -> Result<(), StunError>
pub fn flush(&mut self, digest: Option<&[u8; 16]>) -> Result<(), StunError>
try decoder bytes as message.
§Test
use bytes::BytesMut;
use std::convert::TryFrom;
use turn_server::stun::method::{
StunMethod as Method, StunMethodKind as Kind,
};
use turn_server::stun::*;
let buffer = [
0x00u8, 0x01, 0x00, 0x00, 0x21, 0x12, 0xa4, 0x42, 0x72, 0x6d, 0x49,
0x42, 0x72, 0x52, 0x64, 0x48, 0x57, 0x62, 0x4b, 0x2b,
];
let result = [
0, 1, 0, 32, 33, 18, 164, 66, 114, 109, 73, 66, 114, 82, 100, 72, 87,
98, 75, 43, 0, 8, 0, 20, 69, 14, 110, 68, 82, 30, 232, 222, 44, 240,
250, 182, 156, 92, 25, 23, 152, 198, 217, 222, 128, 40, 0, 4, 74, 165,
171, 86,
];
let mut attributes = Attributes::default();
let mut buf = BytesMut::with_capacity(1280);
let old = MessageDecoder::decode(&buffer[..], &mut attributes).unwrap();
let mut message =
MessageEncoder::extend(Method::Binding(Kind::Request), &old, &mut buf);
message
.flush(Some(&util::long_term_credential_digest(
"panda",
"panda",
"raspberry",
)))
.unwrap();
assert_eq!(&buf[..], &result);Auto Trait Implementations§
impl<'a> Freeze for MessageEncoder<'a>
impl<'a> RefUnwindSafe for MessageEncoder<'a>
impl<'a> Send for MessageEncoder<'a>
impl<'a> Sync for MessageEncoder<'a>
impl<'a> Unpin for MessageEncoder<'a>
impl<'a> !UnwindSafe for MessageEncoder<'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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more