Crate cbor_protocol[][src]

Kubos CBOR over UDP communication crate

Examples

extern crate cbor_protocol;
extern crate serde_cbor;

use cbor_protocol::*;
use serde_cbor::ser;
use std::time::Duration;

let cbor_connection = Protocol::new("0.0.0.0:8000".to_owned());
let message = ser::to_vec_packed(&"ping").unwrap();

cbor_connection.send_message(&message, "0.0.0.0:8001".parse().unwrap()).unwrap();

match cbor_connection.recv_message_peer_timeout(Duration::from_millis(10)) {
    Ok((source, message)) => {
        if let Some(msg) = message {
            println!("Received message from {:?}: {:?}", source, msg);
           }
       }
       Err(None) => println!("Timed out waiting for reply"),
    Err(Some(err)) => eprintln!("Failed to receive message: {}", err)
}

Structs

Protocol

CBOR protocol communication structure