pub struct ChannelData<'a> { /* private fields */ }Expand description
The ChannelData Message
The ChannelData message is used to carry application data between the client and the server.
The Channel Number field specifies the number of the channel on which the data is traveling, and thus, the address of the peer that is sending or is to receive the data.
The Length field specifies the length in bytes of the application data field (i.e., it does not include the size of the ChannelData header). Note that 0 is a valid length.
The Application Data field carries the data the client is trying to send to the peer, or that the peer is sending to the client.
Implementations§
Source§impl<'a> ChannelData<'a>
impl<'a> ChannelData<'a>
pub fn new(number: u16, bytes: &'a [u8]) -> Self
pub fn number(&self) -> u16
pub fn bytes(&self) -> &'a [u8] ⓘ
Sourcepub fn message_size(bytes: &[u8], is_tcp: bool) -> Result<usize, Error>
pub fn message_size(bytes: &[u8], is_tcp: bool) -> Result<usize, Error>
§Test
use bytes::{BufMut, BytesMut};
use turn_server::codec::channel_data::ChannelData;
let data: [u8; 4] = [0x40, 0x00, 0x00, 0x40];
let mut bytes = BytesMut::with_capacity(1500);
ChannelData::new(16384, &data[..]).encode(&mut bytes);
let size = ChannelData::message_size(&bytes[..], false).unwrap();
assert_eq!(size, 8);Sourcepub fn encode(self, bytes: &mut BytesMut)
pub fn encode(self, bytes: &mut BytesMut)
§Test
use bytes::{BufMut, BytesMut};
use turn_server::codec::channel_data::ChannelData;
let data: [u8; 4] = [0x40, 0x00, 0x00, 0x40];
let mut bytes = BytesMut::with_capacity(1500);
ChannelData::new(16384, &data[..]).encode(&mut bytes);
let ret = ChannelData::decode(&bytes[..]).unwrap();
assert_eq!(ret.number(), 16384);
assert_eq!(ret.bytes(), &data[..]);Sourcepub fn decode(bytes: &'a [u8]) -> Result<Self, Error>
pub fn decode(bytes: &'a [u8]) -> Result<Self, Error>
§Test
use bytes::{BufMut, BytesMut};
use turn_server::codec::channel_data::ChannelData;
let data: [u8; 4] = [0x40, 0x00, 0x00, 0x40];
let mut bytes = BytesMut::with_capacity(1500);
ChannelData::new(16384, &data[..]).encode(&mut bytes);
let ret = ChannelData::decode(&bytes[..]).unwrap();
assert_eq!(ret.number(), 16384);
assert_eq!(ret.bytes(), &data[..]);Auto Trait Implementations§
impl<'a> Freeze for ChannelData<'a>
impl<'a> RefUnwindSafe for ChannelData<'a>
impl<'a> Send for ChannelData<'a>
impl<'a> Sync for ChannelData<'a>
impl<'a> Unpin for ChannelData<'a>
impl<'a> UnwindSafe for ChannelData<'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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request