MessageEncoder

Struct MessageEncoder 

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

Implementations§

Source§

impl<'a> MessageEncoder<'a>

Source

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

Source

pub fn extend( method: Method, reader: &Message<'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::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;

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 = Message::decode(&buffer[..], &mut attributes).unwrap();
MessageEncoder::extend(Method::Binding(MethodType::Request), &old, &mut buf);

assert_eq!(&buf[..], &buffer[..]);
Source

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::codec::message::attributes::*;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;

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 = Message::decode(&buffer[..], &mut attributes).unwrap();
let mut message =
    MessageEncoder::extend(Method::Binding(MethodType::Request), &old, &mut buf);

message.append::<UserName>("panda");

assert_eq!(&new_buf[..], &buf[..]);
Source

pub fn flush(&mut self, password: Option<&Password>) -> Result<(), Error>

try decoder bytes as message.

§Test
use bytes::BytesMut;
use std::convert::TryFrom;
use turn_server::codec::message::methods::*;
use turn_server::codec::message::*;
use turn_server::codec::*;

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 = Message::decode(&buffer[..], &mut attributes).unwrap();
let mut message =
    MessageEncoder::extend(Method::Binding(MethodType::Request), &old, &mut buf);

message
    .flush(Some(&turn_server::codec::crypto::generate_password(
        "panda",
        "panda",
        "raspberry",
        turn_server::codec::message::attributes::PasswordAlgorithm::Md5,
    )))
    .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> 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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> ErasedDestructor for T
where T: 'static,