Skip to main content

IntEncoding

Trait IntEncoding 

Source
pub unsafe trait IntEncoding<B: ByteOrder>: 'static {
    const STATIC: bool;
    const ZERO_COPY: bool;
Show 24 methods // Required methods fn encode_u16(val: u16, writer: impl Writer) -> WriteResult<()>; fn size_of_u16(val: u16) -> usize; fn decode_u16<'de>(reader: impl Reader<'de>) -> ReadResult<u16>; fn encode_u32(val: u32, writer: impl Writer) -> WriteResult<()>; fn size_of_u32(val: u32) -> usize; fn decode_u32<'de>(reader: impl Reader<'de>) -> ReadResult<u32>; fn encode_u64(val: u64, writer: impl Writer) -> WriteResult<()>; fn size_of_u64(val: u64) -> usize; fn decode_u64<'de>(reader: impl Reader<'de>) -> ReadResult<u64>; fn encode_u128(val: u128, writer: impl Writer) -> WriteResult<()>; fn size_of_u128(val: u128) -> usize; fn decode_u128<'de>(reader: impl Reader<'de>) -> ReadResult<u128>; fn encode_i16(val: i16, writer: impl Writer) -> WriteResult<()>; fn size_of_i16(val: i16) -> usize; fn decode_i16<'de>(reader: impl Reader<'de>) -> ReadResult<i16>; fn encode_i32(val: i32, writer: impl Writer) -> WriteResult<()>; fn size_of_i32(val: i32) -> usize; fn decode_i32<'de>(reader: impl Reader<'de>) -> ReadResult<i32>; fn encode_i64(val: i64, writer: impl Writer) -> WriteResult<()>; fn size_of_i64(val: i64) -> usize; fn decode_i64<'de>(reader: impl Reader<'de>) -> ReadResult<i64>; fn encode_i128(val: i128, writer: impl Writer) -> WriteResult<()>; fn size_of_i128(val: i128) -> usize; fn decode_i128<'de>(reader: impl Reader<'de>) -> ReadResult<i128>;
}
Expand description

Integer encoding trait.

This trait provides encoding, decoding, and sizing for all integer types.

§Safety

Implementors must adhere to the Safety section of the associated constants STATIC and ZERO_COPY.

size_of_* implementations must always correspond to the number of bytes read by the corresponding decode_* and bytes written by the corresponding encode_*.

Required Associated Constants§

Source

const STATIC: bool

Whether the encoded length for all integer types T is constant and equal to size_of::<T>().

§SAFETY

If STATIC is true, for all integer types T, the encoded size must be constant for all values of T and equal to size_of::<T>().

Source

const ZERO_COPY: bool

Whether the encoding format for integer types T matches their in-memory representation.

§SAFETY

If ZERO_COPY is true, for all integer types T, the in-memory representation must correspond exactly to the serialized form, and all byte sequences must be valid in-memory representations of T. This must respect both the configured byte order and the platform endianness, and any direct reads must uphold T’s alignment requirements.

Required Methods§

Source

fn encode_u16(val: u16, writer: impl Writer) -> WriteResult<()>

Encode the given u16 value and write it to the writer.

Source

fn size_of_u16(val: u16) -> usize

Get the encoded size of the given u16 value.

§SAFETY

Must return the exact number of bytes written by the Self::encode_u16 function and read by the Self::decode_u16 function for this particular u16 instance.

Source

fn decode_u16<'de>(reader: impl Reader<'de>) -> ReadResult<u16>

Decode a u16 value from the reader.

Source

fn encode_u32(val: u32, writer: impl Writer) -> WriteResult<()>

Encode a u32 value and write it to the writer.

Source

fn size_of_u32(val: u32) -> usize

Get the encoded size of the given u32 value.

§SAFETY

Must return the exact number of bytes written by the Self::encode_u32 function and read by the Self::decode_u32 function for this particular u32 instance.

Source

fn decode_u32<'de>(reader: impl Reader<'de>) -> ReadResult<u32>

Decode a u32 value from the reader.

Source

fn encode_u64(val: u64, writer: impl Writer) -> WriteResult<()>

Encode a u64 value and write it to the writer.

Source

fn size_of_u64(val: u64) -> usize

Get the encoded size of the given u64 value.

§SAFETY

Must return the exact number of bytes written by the Self::encode_u64 function and read by the Self::decode_u64 function for this particular u64 instance.

Source

fn decode_u64<'de>(reader: impl Reader<'de>) -> ReadResult<u64>

Decode a u64 value from the reader.

Source

fn encode_u128(val: u128, writer: impl Writer) -> WriteResult<()>

Encode a u128 value and write it to the writer.

Source

fn size_of_u128(val: u128) -> usize

Get the encoded size of the given u128 value.

§SAFETY

Must return the exact number of bytes written by the Self::encode_u128 function and read by the Self::decode_u128 function for this particular u128 instance.

Source

fn decode_u128<'de>(reader: impl Reader<'de>) -> ReadResult<u128>

Decode a u128 value from the reader.

Source

fn encode_i16(val: i16, writer: impl Writer) -> WriteResult<()>

Encode a i16 value and write it to the writer.

Source

fn size_of_i16(val: i16) -> usize

Get the encoded size of the given i16 value.

§SAFETY

Must return the exact number of bytes written by the Self::encode_i16 function and read by the Self::decode_i16 function for this particular i16 instance.

Source

fn decode_i16<'de>(reader: impl Reader<'de>) -> ReadResult<i16>

Decode a i16 value from the reader.

Source

fn encode_i32(val: i32, writer: impl Writer) -> WriteResult<()>

Encode a i32 value and write it to the writer.

Source

fn size_of_i32(val: i32) -> usize

Get the encoded size of the given i32 value.

§SAFETY

Must return the exact number of bytes written by the Self::encode_i32 function and read by the Self::decode_i32 function for this particular i32 instance.

Source

fn decode_i32<'de>(reader: impl Reader<'de>) -> ReadResult<i32>

Decode a i32 value from the reader.

Source

fn encode_i64(val: i64, writer: impl Writer) -> WriteResult<()>

Encode a i64 value and write it to the writer.

Source

fn size_of_i64(val: i64) -> usize

Get the encoded size of the given i64 value.

§SAFETY

Must return the exact number of bytes written by the Self::encode_i64 function and read by the Self::decode_i64 function for this particular i64 instance.

Source

fn decode_i64<'de>(reader: impl Reader<'de>) -> ReadResult<i64>

Decode a i64 value from the reader.

Source

fn encode_i128(val: i128, writer: impl Writer) -> WriteResult<()>

Encode a i128 value and write it to the writer.

Source

fn size_of_i128(val: i128) -> usize

Get the encoded size of the given i128 value.

§SAFETY

Must return the exact number of bytes written by the Self::encode_i128 function and read by the Self::decode_i128 function for this particular i128 instance.

Source

fn decode_i128<'de>(reader: impl Reader<'de>) -> ReadResult<i128>

Decode a i128 value from the reader.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§