use cbor::{Decoder, Encoder};

fn main() {
    let data = vec![('a', 1), ('b', 2), ('c', 3)];

    println!("Encode/Decode by cbor");
    let mut e = Encoder::from_memory();
    e.encode(&data).unwrap();
    let encoded_bytes = e.as_bytes();
    println!("Encoded: {}", hex::encode(encoded_bytes));
    let mut d = Decoder::from_bytes(e.as_bytes());
    let items: Vec<(char, i32)> = d.decode().collect::<Result<_, _>>().unwrap();
    println!("Decoded: {:?}", items);

    println!("\nEncode/Decode by serde_cbor");
    let encoded_bytes_by_serde = serde_cbor::to_vec(&data).unwrap();
    println!("Encoded: {}", hex::encode(&encoded_bytes_by_serde));
    let items: Vec<(char, u8)> = serde_cbor::from_slice(&encoded_bytes_by_serde).unwrap();
    println!("Decoded: {:?}", items);
}
