Trait integer_encoding::FixedInt
source · pub trait FixedInt: Sized + Copy {
type Bytes: AsRef<[u8]>;
const ENCODED_SIZE: usize = _;
// Required methods
fn encode_fixed(self, dst: &mut [u8]) -> Option<()>;
fn encode_fixed_light(self) -> Self::Bytes;
fn decode_fixed(src: &[u8]) -> Option<Self>;
fn switch_endianness(self) -> Self;
// Provided method
fn encode_fixed_vec(self) -> Vec<u8> { ... }
}
Expand description
FixedInt
provides encoding/decoding to and from fixed int representations. Note that current
Rust versions already provide this functionality via the to_le_bytes()
and to_be_bytes()
methods.
The emitted bytestring contains the bytes of the integer in machine endianness.
Required Associated Types§
Provided Associated Constants§
const ENCODED_SIZE: usize = _
Required Methods§
sourcefn encode_fixed(self, dst: &mut [u8]) -> Option<()>
fn encode_fixed(self, dst: &mut [u8]) -> Option<()>
Encode a value into the given slice using little-endian. Returns None
if dst
doesn’t provide enough space to encode this integer.
Use switch_endianness()
if machine endianness doesn’t match the desired target encoding.
sourcefn encode_fixed_light(self) -> Self::Bytes
fn encode_fixed_light(self) -> Self::Bytes
Returns the representation of FixedInt
as [Bytes
], the little-endian representation
of self in the stack.
sourcefn decode_fixed(src: &[u8]) -> Option<Self>
fn decode_fixed(src: &[u8]) -> Option<Self>
Decode a value from the given slice assuming little-endian. Use switch_endianness()
on
the returned value if the source was not encoded in little-endian.
sourcefn switch_endianness(self) -> Self
fn switch_endianness(self) -> Self
integer-encoding-rs always emits and receives little-endian integers (converting implicitly on big-endian machines). If you receive a big-endian integer, and would like it to be treated correctly, use this helper method to convert between endiannesses.
Provided Methods§
sourcefn encode_fixed_vec(self) -> Vec<u8>
fn encode_fixed_vec(self) -> Vec<u8>
Helper: Encode the value and return a Vec.