[−][src]Struct cbor_protocol::Protocol
CBOR protocol communication structure
Methods
impl Protocol
[src]
impl Protocol
pub fn new(host_url: &str, data_size: usize) -> Self
[src]
pub fn new(host_url: &str, data_size: usize) -> Self
Binds a UDP listener socket and saves it in a new protocol instance
Arguments
- host_url - The IP address and port to bind
- data_size - Expected max size of payload in messages
Errors
If this function encounters any errors, it will panic
Examples
use cbor_protocol::*; let cbor_connection = Protocol::new(&"0.0.0.0:8000".to_owned(), 4096);
pub fn send_message(
&self,
message: &[u8],
dest: SocketAddr
) -> Result<(), ProtocolError>
[src]
pub fn send_message(
&self,
message: &[u8],
dest: SocketAddr
) -> Result<(), ProtocolError>
Send a CBOR packet to a specified UDP socket destination
Arguments
- message - CBOR packet to send. Packet must be a serialized array or tuple.
- dest - UDP socket destination
Errors
If this function encounters any errors, it will return an error message string
Examples
use cbor_protocol::*; use serde_cbor::ser; let cbor_connection = Protocol::new(&"0.0.0.0:8000".to_owned(), 4096); let message = ser::to_vec_packed(&["ping"]).unwrap(); cbor_connection.send_message(&message, "0.0.0.0:8001".parse().unwrap());
use cbor_protocol::*; use serde_cbor::ser; let cbor_connection = Protocol::new(&"0.0.0.0:8000".to_owned(), 4096); let message = ser::to_vec_packed(&("hello", "world")).unwrap(); cbor_connection.send_message(&message, "0.0.0.0:8001".parse().unwrap());
pub fn send_pause(&self, dest: SocketAddr) -> Result<(), ProtocolError>
[src]
pub fn send_pause(&self, dest: SocketAddr) -> Result<(), ProtocolError>
Send a pause message to a specified UDP socket destination
Arguments
- dest - UDP socket destination
Errors
If this function encounters any errors, it will return an error message string
Examples
use cbor_protocol::*; let cbor_connection = Protocol::new(&"0.0.0.0:8000".to_owned(), 4096); cbor_connection.send_pause("0.0.0.0:8001".parse().unwrap());
pub fn send_resume(&self, dest: SocketAddr) -> Result<(), ProtocolError>
[src]
pub fn send_resume(&self, dest: SocketAddr) -> Result<(), ProtocolError>
Send a resume message to a specified UDP socket destination
Arguments
- dest - UDP socket destination
Errors
If this function encounters any errors, it will return an error message string
Examples
use cbor_protocol::*; let cbor_connection = Protocol::new(&"0.0.0.0:8000".to_owned(), 4096); cbor_connection.send_resume("0.0.0.0:8001".parse().unwrap());
pub fn recv_message(&self) -> Result<Value, ProtocolError>
[src]
pub fn recv_message(&self) -> Result<Value, ProtocolError>
Receive a UDP message (no timeout)
Errors
If this function encounters any errors, it will return an error message string
Examples
use cbor_protocol::*; let cbor_connection = Protocol::new(&"0.0.0.0:8000".to_owned(), 4096); let message = cbor_connection.recv_message().unwrap();
pub fn peek_peer(&self) -> Result<SocketAddr, ProtocolError>
[src]
pub fn peek_peer(&self) -> Result<SocketAddr, ProtocolError>
Peek at the sender information for the next message in the UDP receive buffer
Errors
If this function encounters any errors, it will return an error message string
Examples
use cbor_protocol::*; let cbor_connection = Protocol::new(&"0.0.0.0:8000".to_owned(), 4096); let source = cbor_connection.peek_peer();
pub fn recv_message_peer(&self) -> Result<(SocketAddr, Value), ProtocolError>
[src]
pub fn recv_message_peer(&self) -> Result<(SocketAddr, Value), ProtocolError>
Receive a UDP message and take note of the sender (no timeout)
Errors
If this function encounters any errors, it will return an error message string
Examples
use cbor_protocol::*; let cbor_connection = Protocol::new(&"0.0.0.0:8000".to_owned(), 4096); let (source, message) = cbor_connection.recv_message_peer().unwrap();
pub fn recv_message_peer_timeout(
&self,
timeout: Duration
) -> Result<(SocketAddr, Value), ProtocolError>
[src]
pub fn recv_message_peer_timeout(
&self,
timeout: Duration
) -> Result<(SocketAddr, Value), ProtocolError>
Receive a UDP message and take note of the sender (with timeout)
Arguments
- timeout - Maximum amount of time to wait for a UDP packet
Errors
- If this function times out, it will return Err(None)
- If this function encounters any errors, it will return an error message string
Examples
use cbor_protocol::*; use std::time::Duration; let cbor_connection = Protocol::new(&"0.0.0.0:8000".to_owned(), 4096); let (source, message) = match cbor_connection.recv_message_peer_timeout(Duration::from_secs(1)) { Ok(data) => data, Err(ProtocolError::Timeout) => { println!("Timeout waiting for message"); return; } Err(err) => panic!("Failed to receive message: {}", err), };
pub fn recv_message_timeout(
&self,
timeout: Duration
) -> Result<Value, ProtocolError>
[src]
pub fn recv_message_timeout(
&self,
timeout: Duration
) -> Result<Value, ProtocolError>
Receive a UDP message (with timeout)
Arguments
- timeout - Maximum amount of time to wait for a UDP packet
Errors
- If this function times out, it will return Err(None)
- If this function encounters any errors, it will return an error message string
Examples
use cbor_protocol::*; use std::time::Duration; let cbor_connection = Protocol::new(&"0.0.0.0:9000".to_owned(), 4096); let message = match cbor_connection.recv_message_timeout(Duration::from_secs(1)) { Ok(data) => data, Err(ProtocolError::Timeout) => { println!("Timeout while waiting for message"); return; } Err(err) => panic!("Failed to receive message: {}", err), };
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T> From for T
impl<T, U> Into for T where
U: From<T>,
[src]
impl<T, U> Into for T where
U: From<T>,
impl<T, U> TryFrom for T where
T: From<U>,
[src]
impl<T, U> TryFrom for T where
T: From<U>,
type Error = !
try_from
)The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
try_from
)Performs the conversion.
impl<T> Borrow for T where
T: ?Sized,
[src]
impl<T> Borrow for T where
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
impl<T> BorrowMut for T where
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
try_from
)The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
try_from
)Performs the conversion.
impl<T> Any for T where
T: 'static + ?Sized,
[src]
impl<T> Any for T where
T: 'static + ?Sized,
fn get_type_id(&self) -> TypeId
[src]
fn get_type_id(&self) -> TypeId
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Gets the TypeId
of self
. Read more