pub trait ByteStructUnspecifiedByteOrder: ByteStructLen {
// Required methods
fn write_bytes_default_le(&self, bytes: &mut [u8]);
fn read_bytes_default_le(bytes: &[u8]) -> Self;
fn write_bytes_default_be(&self, bytes: &mut [u8]);
fn read_bytes_default_be(bytes: &[u8]) -> Self;
}
Expand description
A type that can be packed into or unpacked from raw bytes under given default byte order.
This trait is implemented for most numeric primitive types,
except for bool
, char
, isize
and usize
. This is also implemented for array types
whose element type implements ByteStructUnspecifiedByteOrder
.
This trait is automatically implemented for all types that implements ByteStruct
.
In this case, all members of ByteStructUnspecifiedByteOrder
are direct wrappers of ByteStruct
members.
Members in this trait are meant to be called by byte_struct internal only.
They do not do what one might expect:
the byte orders specified in read_bytes_default_*
/ write_bytes_default_*
functions
are only default byte orders.
The default byte order is only respected when the type itself does not carry byte order specification
(e.g. primitive types).
In contrast, since ByteStruct
types always have fixed packing method,
the default byte order has no effect on them, and the three versions of read / write functions for them,
_default_le
, _default_be
and no-spec from ByteStruct
, behave exactly the same.
One can implement this trait for custom types in order to pack or unpack an object in a special way,
but only when the said type changes its packing method depending on the default byte order.
An example for this is a custom fixed-size large integer type.
If the packing method is independent from the default byte order, please implement ByteStruct
instead.
Required Methods§
sourcefn write_bytes_default_le(&self, bytes: &mut [u8])
fn write_bytes_default_le(&self, bytes: &mut [u8])
Packs the object into raw bytes with little-endian as the default byte order
sourcefn read_bytes_default_le(bytes: &[u8]) -> Self
fn read_bytes_default_le(bytes: &[u8]) -> Self
Unpacks raw bytes into a new object with little-endian as the default byte order
sourcefn write_bytes_default_be(&self, bytes: &mut [u8])
fn write_bytes_default_be(&self, bytes: &mut [u8])
Packs the object into raw bytes with big-endian as the default byte order
sourcefn read_bytes_default_be(bytes: &[u8]) -> Self
fn read_bytes_default_be(bytes: &[u8]) -> Self
Unpacks raw bytes into a new object with big-endian as the default byte order