lib

Core libraries for Radroots
git clone https://radroots.dev/git/lib.git
Log | Files | Refs | README | LICENSE

encode.rs (970B)


      1 #[cfg(not(feature = "std"))]
      2 use alloc::{string::String, vec::Vec};
      3 
      4 use radroots_events::kinds::KIND_SEAL;
      5 use radroots_events::seal::RadrootsSeal;
      6 
      7 use crate::error::EventEncodeError;
      8 use crate::wire::WireEventParts;
      9 
     10 const DEFAULT_KIND: u32 = KIND_SEAL;
     11 
     12 pub fn seal_build_tags(_seal: &RadrootsSeal) -> Result<Vec<Vec<String>>, EventEncodeError> {
     13     if _seal.content.trim().is_empty() {
     14         return Err(EventEncodeError::EmptyRequiredField("content"));
     15     }
     16     Ok(Vec::new())
     17 }
     18 
     19 pub fn to_wire_parts(seal: &RadrootsSeal) -> Result<WireEventParts, EventEncodeError> {
     20     let tags = seal_build_tags(seal)?;
     21     Ok(WireEventParts {
     22         kind: DEFAULT_KIND,
     23         content: seal.content.clone(),
     24         tags,
     25     })
     26 }
     27 
     28 pub fn to_wire_parts_with_kind(
     29     seal: &RadrootsSeal,
     30     kind: u32,
     31 ) -> Result<WireEventParts, EventEncodeError> {
     32     if kind != DEFAULT_KIND {
     33         return Err(EventEncodeError::InvalidKind(kind));
     34     }
     35     to_wire_parts(seal)
     36 }