Skip to main content

zlicenser_protocol/wire/
cbor.rs

1use serde::{de::DeserializeOwned, Serialize};
2
3use crate::error::Error;
4
5pub fn encode<T: Serialize>(value: &T) -> Result<Vec<u8>, Error> {
6    let mut buf = Vec::new();
7    ciborium::ser::into_writer(value, &mut buf).map_err(|e| Error::Encode(e.to_string()))?;
8    Ok(buf)
9}
10
11pub fn decode<T: DeserializeOwned>(bytes: &[u8]) -> Result<T, Error> {
12    ciborium::de::from_reader(bytes).map_err(|e| Error::Decode(e.to_string()))
13}