use std::fmt::Debug; use bincode::{Decode, Encode, config::Configuration}; use crate::Error; #[derive(Debug, Encode, Decode, Clone)] pub enum Packets { SyncUUID(String), Update { routes: Vec, }, Disconnect { routes: Vec, }, // Send single data packet without routing details DataUnrouted { src: String, dest: String, data: Vec, }, // Send single data packet with routing details DataRouted { path: Vec, data: Vec, }, // DataStreamRouted { // path: Vec, // data: Vec, // }, ErrorNameExists, } impl Packets { pub fn encode(&self) -> Result, Error> { encode_vec(self) } pub fn decode(data: &[u8]) -> Result { decode_vec(data) } } pub fn encode_vec

(object: &P) -> Result, Error> where P: Encode + Decode<()> + Debug + Clone + 'static, { Ok(bincode::encode_to_vec(object, crate::BINCODE_CONFIG)?) } pub fn decode_vec

(data: &[u8]) -> Result where P: Encode + Decode<()> + Debug + Clone + 'static, { let (decoded, _) = bincode::decode_from_slice::(&data[..], crate::BINCODE_CONFIG)?; Ok(decoded) }