Trait spinel_pack::TryPack
source · pub trait TryPack {
// Required methods
fn try_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>;
fn pack_len(&self) -> Result<usize>;
// Provided methods
fn try_array_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize> { ... }
fn array_pack_len(&self) -> Result<usize> { ... }
fn try_packed(&self) -> Result<Vec<u8>> { ... }
}
Expand description
Trait implemented by data types that support being serialized to a spinel-based byte encoding.
Required Methods§
Provided Methods§
sourcefn try_array_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>
fn try_array_pack<T: Write + ?Sized>(&self, buffer: &mut T) -> Result<usize>
Uses Spinel array encoding to serialize to a given std::io::Write
reference.
Array encoding is occasionally different than single-value encoding, hence the need for a separate method.
Default behavior is the same as try_pack()
.
sourcefn array_pack_len(&self) -> Result<usize>
fn array_pack_len(&self) -> Result<usize>
Calculates how many bytes this type will use when serialized into an array.
Array encoding is occasionally different than single-value encoding, hence the need for a separate method.
Default behavior is the same as pack_len()
.
sourcefn try_packed(&self) -> Result<Vec<u8>>
fn try_packed(&self) -> Result<Vec<u8>>
Convenience method which serializes to a new Vec<u8>
.