pub trait Encodable {
// Required method
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>;
}
Expand description
A trait for types that can be serialized using a DataEncoder
.
Types implementing Encodable
define how to write their binary representation
into an output encoder. This is the core trait used by the framework’s derive macros
and container support.
§Example
struct MyData {
id: u32,
flag: bool,
}
impl Encodable for MyData {
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()> {
encoder.add_item(self.id)?;
encoder.add_bool(self.flag)
}
}
Required Methods§
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Implementations on Foreign Types§
Source§impl Encodable for f32
impl Encodable for f32
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for f64
impl Encodable for f64
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for i8
impl Encodable for i8
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for i16
impl Encodable for i16
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for i32
impl Encodable for i32
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for i64
impl Encodable for i64
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for isize
impl Encodable for isize
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for u8
impl Encodable for u8
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for u16
impl Encodable for u16
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for u32
impl Encodable for u32
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for u64
impl Encodable for u64
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for usize
impl Encodable for usize
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl Encodable for String
impl Encodable for String
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl<T: Encodable> Encodable for Option<T>
Implements Encodable
for Option<T>
by writing a boolean flag followed by the value (if present).
impl<T: Encodable> Encodable for Option<T>
Implements Encodable
for Option<T>
by writing a boolean flag followed by the value (if present).
Format:
0x01
followed by encodedT
ifSome
0x00
ifNone
fn encode_data(&self, writer: &mut DataEncoder) -> ParseResult<()>
Source§impl<T: Encodable> Encodable for Vec<T>
Implements Encodable
for Vec<T>
by prefixing the length (as u32
), and encoding each element.
impl<T: Encodable> Encodable for Vec<T>
Implements Encodable
for Vec<T>
by prefixing the length (as u32
), and encoding each element.
Format:
[length: u32][item1][item2]...[itemN]
Note: Internally uses add_slice
.
fn encode_data(&self, encoder: &mut DataEncoder) -> ParseResult<()>
Source§impl<T: Encodable, const N: usize> Encodable for [T; N]
Implements Encodable
for arrays [T; N]
by encoding each element sequentially.
impl<T: Encodable, const N: usize> Encodable for [T; N]
Implements Encodable
for arrays [T; N]
by encoding each element sequentially.
Does not include a length prefix; assumes caller knows the array size.
Format:
[item1][item2]...[itemN]