use serde::{Deserialize, Serialize};
#[cfg(feature = "codec-postcard")]
pub fn to_bytes<T: Serialize>(value: &T) -> Box<[u8]> {
postcard::to_allocvec(value)
.expect("WebWorker serialization failed")
.into()
}
#[cfg(feature = "codec-postcard")]
pub fn from_bytes<'de, T: Deserialize<'de>>(bytes: &'de [u8]) -> T {
postcard::from_bytes(bytes).expect("WebWorker deserialization failed")
}
#[cfg(all(feature = "codec-pot", not(feature = "codec-postcard")))]
const POT_CONFIG: pot::Config = pot::Config::new().compatibility(pot::Compatibility::V4);
#[cfg(all(feature = "codec-pot", not(feature = "codec-postcard")))]
pub fn to_bytes<T: Serialize>(value: &T) -> Box<[u8]> {
POT_CONFIG
.serialize(value)
.expect("WebWorker serialization failed")
.into()
}
#[cfg(all(feature = "codec-pot", not(feature = "codec-postcard")))]
pub fn from_bytes<'de, T: Deserialize<'de>>(bytes: &'de [u8]) -> T {
POT_CONFIG
.deserialize(bytes)
.expect("WebWorker deserialization failed")
}
#[cfg(not(any(feature = "codec-postcard", feature = "codec-pot")))]
compile_error!("No codec selected. Enable `codec-postcard` (default) or `codec-pot`.");