1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
//! Base module provides a low-level structure for data encoding and decoding mod header; pub use header::*; mod base; pub use base::*; /// Parse trait for building parse-able objects pub trait Parse { /// Output type returned from parsing type Output; /// Error type returned on parse error type Error; /// Parse method consumes a slice and returns an object and the remaining slice. fn parse(buff: &[u8]) -> Result<(Self::Output, usize), Self::Error>; } /// Encode trait for building encodable objects pub trait Encode { /// Error type returned on parse error type Error; /// Encode method writes object data to the provided writer fn encode(&self, buff: &mut [u8]) -> Result<usize, Self::Error>; } pub trait WireEncode { type Error; fn encode(&mut self, buff: &mut [u8]) -> Result<usize, Self::Error>; } /// Parse trait for building parse-able objects pub trait WireDecode { /// Output type returned from parsing type Output; /// Error type returned on parse error type Error; /// Context used in decoding type Ctx; /// Parse method consumes a slice and returns an object and the remaining slice. fn decode(ctx: Self::Ctx, buff: &[u8]) -> Result<(Self::Output, usize), Self::Error>; }