1#![cfg_attr(not(feature = "std"), no_std)]
17
18#[cfg(feature = "postcard")]
19pub(crate) mod postcard;
20
21#[cfg(feature = "prost")]
22pub(crate) mod prost;
23
24#[cfg(feature = "rkyv")]
25pub(crate) mod rkyv;
26
27#[cfg(feature = "postcard")]
28pub use postcard::PostcardCodec;
29
30#[cfg(feature = "prost")]
31pub use prost::ProstCodec;
32
33#[cfg(feature = "rkyv")]
34pub use rkyv::RkyvCodec;
35
36pub trait Codec: core::marker::Sized {
37 type Error: core::fmt::Debug;
38}
39
40pub trait CodecFor<T>: Codec {
41 type Decoded<'buf>: 'buf
42 where
43 T: 'buf;
44
45 fn encode(msg: &T, buf: &mut [u8]) -> core::result::Result<usize, Self::Error>;
46
47 fn decode<'buf>(buf: &'buf [u8]) -> core::result::Result<Self::Decoded<'buf>, Self::Error>
48 where
49 T: 'buf;
50}
51
52#[cfg(feature = "rkyv")]
53pub use consortium_codec_macros::TrustedArchive;
54
55#[cfg(feature = "rkyv")]
56pub use crate::rkyv::TrustedArchive;