[−][src]Trait byte_array::BinaryBuilder
This trait helps you handle user-defined structs via ByteArray
.
Examples
use byte_array::{ BinaryBuilder, ByteArray, }; struct Foo(u64); impl BinaryBuilder for Foo { fn new() -> Self { Self(123) } fn from_raw(ba: &mut ByteArray) -> Option<Self> { Some(Self(ba.read_safe()?)) } fn to_raw(&self, mut ba: &mut ByteArray) { ba <<= &self.0; } } let mut ba = ByteArray::new(); // Write ba <<= &Foo::new(); ba <<= &Foo(321); ba.write(&Foo(222)); // Read ba.seek_first(); assert_eq!(123, ba.read::<u64>()); assert_eq!(321, ba.read::<u64>()); assert_eq!(222, ba.read::<u64>());
Required methods
fn new() -> Self
Creates an empty Data.
fn from_raw(ba: &mut ByteArray) -> Option<Self>
fn to_raw(&self, ba: &mut ByteArray)
Adds data to the ByteArray
.