Trait integer_encoding::FixedInt

source ·
pub trait FixedInt: Sized + Copy {
    const REQUIRED_SPACE: usize;

    // Required methods
    fn required_space() -> usize;
    fn encode_fixed(self, dst: &mut [u8]);
    fn decode_fixed(src: &[u8]) -> Self;
    fn encode_fixed_light<'a>(&'a self) -> &'a [u8] ;

    // Provided methods
    fn encode_fixed_vec(self) -> Vec<u8> { ... }
    fn decode_fixed_vec(v: &Vec<u8>) -> Self { ... }
}
Expand description

FixedInt provides encoding/decoding to and from fixed int representations.

The emitted bytestring contains the bytes of the integer in machine endianness.

Required Associated Constants§

Required Methods§

source

fn required_space() -> usize

Returns how many bytes are required to represent the given type.

source

fn encode_fixed(self, dst: &mut [u8])

Encode a value into the given slice. dst must be exactly REQUIRED_SPACE bytes.

source

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

Decode a value from the given slice. src must be exactly REQUIRED_SPACE bytes.

source

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

Perform a transmute, i.e. return a “view” into the integer’s memory, which is faster than performing a copy.

Provided Methods§

source

fn encode_fixed_vec(self) -> Vec<u8>

Helper: Encode the value and return a Vec.

source

fn decode_fixed_vec(v: &Vec<u8>) -> Self

Helper: Decode the value from the Vec.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl FixedInt for i8

source§

const REQUIRED_SPACE: usize = 1usize

source§

fn required_space() -> usize

source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

source§

fn encode_fixed(self, dst: &mut [u8])

source§

fn decode_fixed(src: &[u8]) -> i8

source§

impl FixedInt for i16

source§

const REQUIRED_SPACE: usize = 2usize

source§

fn required_space() -> usize

source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

source§

fn encode_fixed(self, dst: &mut [u8])

source§

fn decode_fixed(src: &[u8]) -> i16

source§

impl FixedInt for i32

source§

const REQUIRED_SPACE: usize = 4usize

source§

fn required_space() -> usize

source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

source§

fn encode_fixed(self, dst: &mut [u8])

source§

fn decode_fixed(src: &[u8]) -> i32

source§

impl FixedInt for i64

source§

const REQUIRED_SPACE: usize = 8usize

source§

fn required_space() -> usize

source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

source§

fn encode_fixed(self, dst: &mut [u8])

source§

fn decode_fixed(src: &[u8]) -> i64

source§

impl FixedInt for isize

source§

const REQUIRED_SPACE: usize = 8usize

source§

fn required_space() -> usize

source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

source§

fn encode_fixed(self, dst: &mut [u8])

source§

fn decode_fixed(src: &[u8]) -> isize

source§

impl FixedInt for u8

source§

const REQUIRED_SPACE: usize = 1usize

source§

fn required_space() -> usize

source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

source§

fn encode_fixed(self, dst: &mut [u8])

source§

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

source§

impl FixedInt for u16

source§

const REQUIRED_SPACE: usize = 2usize

source§

fn required_space() -> usize

source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

source§

fn encode_fixed(self, dst: &mut [u8])

source§

fn decode_fixed(src: &[u8]) -> u16

source§

impl FixedInt for u32

source§

const REQUIRED_SPACE: usize = 4usize

source§

fn required_space() -> usize

source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

source§

fn encode_fixed(self, dst: &mut [u8])

source§

fn decode_fixed(src: &[u8]) -> u32

source§

impl FixedInt for u64

source§

const REQUIRED_SPACE: usize = 8usize

source§

fn required_space() -> usize

source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

source§

fn encode_fixed(self, dst: &mut [u8])

source§

fn decode_fixed(src: &[u8]) -> u64

source§

impl FixedInt for usize

source§

const REQUIRED_SPACE: usize = 8usize

source§

fn required_space() -> usize

source§

fn encode_fixed_light<'a>(&'a self) -> &'a [u8]

source§

fn encode_fixed(self, dst: &mut [u8])

source§

fn decode_fixed(src: &[u8]) -> usize

Implementors§