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§

Required Methods§

source

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.

source

fn encode_fixed_light(self) -> Self::Bytes

Returns the representation of FixedInt as [Bytes], the little-endian representation of self in the stack.

source

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.

source

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§

source

fn encode_fixed_vec(self) -> Vec<u8>

Helper: Encode the value and return a Vec.

Implementations on Foreign Types§

source§

impl FixedInt for u64

§

type Bytes = [u8; 8]

source§

fn encode_fixed(self, dst: &mut [u8]) -> Option<()>

source§

fn encode_fixed_light(self) -> Self::Bytes

source§

fn decode_fixed(src: &[u8]) -> Option<Self>

source§

fn switch_endianness(self) -> Self

source§

impl FixedInt for isize

§

type Bytes = [u8; 8]

source§

fn encode_fixed(self, dst: &mut [u8]) -> Option<()>

source§

fn encode_fixed_light(self) -> Self::Bytes

source§

fn decode_fixed(src: &[u8]) -> Option<Self>

source§

fn switch_endianness(self) -> Self

source§

impl FixedInt for u32

§

type Bytes = [u8; 4]

source§

fn encode_fixed(self, dst: &mut [u8]) -> Option<()>

source§

fn encode_fixed_light(self) -> Self::Bytes

source§

fn decode_fixed(src: &[u8]) -> Option<Self>

source§

fn switch_endianness(self) -> Self

source§

impl FixedInt for i16

§

type Bytes = [u8; 2]

source§

fn encode_fixed(self, dst: &mut [u8]) -> Option<()>

source§

fn encode_fixed_light(self) -> Self::Bytes

source§

fn decode_fixed(src: &[u8]) -> Option<Self>

source§

fn switch_endianness(self) -> Self

source§

impl FixedInt for i32

§

type Bytes = [u8; 4]

source§

fn encode_fixed(self, dst: &mut [u8]) -> Option<()>

source§

fn encode_fixed_light(self) -> Self::Bytes

source§

fn decode_fixed(src: &[u8]) -> Option<Self>

source§

fn switch_endianness(self) -> Self

source§

impl FixedInt for i64

§

type Bytes = [u8; 8]

source§

fn encode_fixed(self, dst: &mut [u8]) -> Option<()>

source§

fn encode_fixed_light(self) -> Self::Bytes

source§

fn decode_fixed(src: &[u8]) -> Option<Self>

source§

fn switch_endianness(self) -> Self

source§

impl FixedInt for usize

§

type Bytes = [u8; 8]

source§

fn encode_fixed(self, dst: &mut [u8]) -> Option<()>

source§

fn encode_fixed_light(self) -> Self::Bytes

source§

fn decode_fixed(src: &[u8]) -> Option<Self>

source§

fn switch_endianness(self) -> Self

source§

impl FixedInt for u16

§

type Bytes = [u8; 2]

source§

fn encode_fixed(self, dst: &mut [u8]) -> Option<()>

source§

fn encode_fixed_light(self) -> Self::Bytes

source§

fn decode_fixed(src: &[u8]) -> Option<Self>

source§

fn switch_endianness(self) -> Self

source§

impl FixedInt for i8

§

type Bytes = [u8; 1]

source§

fn encode_fixed(self, dst: &mut [u8]) -> Option<()>

source§

fn encode_fixed_light(self) -> Self::Bytes

source§

fn decode_fixed(src: &[u8]) -> Option<Self>

source§

fn switch_endianness(self) -> Self

source§

impl FixedInt for u8

§

type Bytes = [u8; 1]

source§

fn encode_fixed(self, dst: &mut [u8]) -> Option<()>

source§

fn encode_fixed_light(self) -> Self::Bytes

source§

fn decode_fixed(src: &[u8]) -> Option<Self>

source§

fn switch_endianness(self) -> Self

Implementors§