rings_node/extension/ext/
envelope.rs1use bytes::Bytes;
4use serde::Deserialize;
5use serde::Serialize;
6
7use crate::error::Error;
8use crate::error::Result;
9
10#[derive(Clone, Debug, Serialize, Deserialize)]
13pub struct Envelope {
14 pub namespace: String,
16 pub payload: Bytes,
18}
19
20impl Envelope {
21 pub fn new(namespace: impl Into<String>, payload: Bytes) -> Self {
23 Self {
24 namespace: namespace.into(),
25 payload,
26 }
27 }
28
29 pub fn encode(&self) -> Result<Vec<u8>> {
31 rings_codec::serialize(self).map_err(|_| Error::EncodeError)
32 }
33
34 pub fn decode(bytes: &[u8]) -> Result<Self> {
36 rings_codec::deserialize(bytes).map_err(|_| Error::DecodeError)
37 }
38}