Crate cuprate_epee_encoding

Source
Expand description

Epee Encoding

This library contains the Epee binary format found in Monero, unlike other crates this crate does not use serde.

See epee_object for how to easily implement EpeeObject for your types.

example without macro:


pub struct Test {
    val: u64
}

#[derive(Default)]
pub struct __TestEpeeBuilder {
    val: Option<u64>,
}

impl EpeeObjectBuilder<Test> for __TestEpeeBuilder {
    fn add_field<B: Buf>(&mut self, name: &str, r: &mut B) -> cuprate_epee_encoding::error::Result<bool> {
        match name {
            "val" => {self.val = Some(read_epee_value(r)?);}
            _ => return Ok(false),
        }
        Ok(true)
    }

    fn finish(self) -> cuprate_epee_encoding::error::Result<Test> {
        Ok(
            Test {
                val: self.val.ok_or_else(|| cuprate_epee_encoding::error::Error::Format("Required field was not found!"))?
            }
        )
    }
}

impl EpeeObject for Test {
    type Builder = __TestEpeeBuilder;

    fn number_of_fields(&self) -> u64 {
        1
    }

    fn write_fields<B: BufMut>(self, w: &mut B) -> cuprate_epee_encoding::error::Result<()> {
       // write the fields
       write_field(self.val, "val", w)
   }
}


let data = [1, 17, 1, 1, 1, 1, 2, 1, 1, 4, 3, 118, 97, 108, 5, 4, 0, 0, 0, 0, 0, 0, 0]; // the data to decode;
let val: Test = from_bytes(&mut data.as_slice()).unwrap();
let data = to_bytes(val).unwrap();

Re-exports§

Modules§

Macros§

Traits§

  • A trait for an object that can be turned into epee bytes.
  • A trait for an object that can build a type T from the epee format.
  • A trait for epee values.

Functions§