Derive Macro ledger_proto::DecodeOwned
#[derive(DecodeOwned)]
{
// Attributes available to this derive:
#[encdec]
}
Expand description
#[derive(DecodeOwned)]
support.
generates a [DecodeOwned
][encdec_base::decode::DecodeOwned] implementation equivalent to calling .decode()
on each field in order.
for example:
#[derive(Debug, PartialEq)]
struct Something {
a: u8,
b: u16,
c: [u8; 3],
}
// `#[derive(Decode)]` equivalent implementation
impl DecodeOwned for Something {
type Output = Something;
type Error = Error;
fn decode_owned(buff: &[u8]) -> Result<(Self::Output, usize), Self::Error> {
let mut index = 0;
let a = buff[0];
index += 1;
let b = buff[1] as u16 | (buff[2] as u16) << 8;
index += 2;
let mut c = [0u8; 3];
c.copy_from_slice(&buff[3..][..3]);
index += 3;
Ok((Self{a, b, c}, index))
}
}