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§
pub use marker::InnerMarker;
pub use marker::Marker;
pub use error::*;
Modules§
Macros§
- Macro to derive
EpeeObject
for structs.
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§
- Read the object
T
from a byte array. - Read an epee value from the stream, an epee value is the part after the key including the marker.
- Read a marker from the
Buf
, this function should only be used for custom serialisation based on the marker otherwise just useread_epee_value
. - Read an epee variable sized number from
r
. - Turn the object into epee bytes.
- Write a byte array to
w
withwrite_varint
. - Write an epee field.
- Write an epee variable sized number into
w
.