miden_node_persistence/
lib.rs1mod collections;
4mod error;
5pub mod generated;
6mod protocol;
7
8pub use error::PersistenceError;
9pub use miden_protobuf;
10pub use prost;
11
12pub trait ProtobufValue: Sized {
14 type Message: prost::Message + Default;
16 fn to_proto(&self) -> Self::Message;
18 fn from_proto(message: Self::Message) -> Result<Self, PersistenceError>;
20}
21
22pub fn encode<T: ProtobufValue>(value: &T) -> Vec<u8> {
24 prost::Message::encode_to_vec(&value.to_proto())
25}
26
27pub fn decode<T: ProtobufValue>(bytes: &[u8]) -> Result<T, PersistenceError> {
29 let message = <T::Message as prost::Message>::decode(bytes)?;
30 T::from_proto(message)
31}
32
33#[cfg(test)]
34mod tests;