Struct codec::number::NumberCodec[][src]

pub struct NumberCodec;

Byte encoding and decoding utility for primitive number types.

Implementations

impl NumberCodec[src]

pub fn encode_u8(buf: &mut [u8], v: u8)[src]

Encodes an unsigned 8 bit integer v to buf, which is memory-comparable in ascending order.

Panics

Panics when buf.len() < 1.

pub fn decode_u8(buf: &[u8]) -> u8[src]

Decodes an unsigned 8 bit integer from buf, which is previously encoded via encode_u8.

Panics

Panics when buf.len() < 1.

pub fn encode_u16(buf: &mut [u8], v: u16)[src]

Encodes an unsigned 16 bit integer v to buf, which is memory-comparable in ascending order.

Panics

Panics when buf.len() < 2.

pub fn decode_u16(buf: &[u8]) -> u16[src]

Decodes an unsigned 16 bit integer from buf, which is previously encoded via encode_u16.

Panics

Panics when buf.len() < 2.

pub fn encode_u32(buf: &mut [u8], v: u32)[src]

Encodes an unsigned 32 bit integer v to buf, which is memory-comparable in ascending order.

Panics

Panics when buf.len() < 4.

pub fn decode_u32(buf: &[u8]) -> u32[src]

Decodes an unsigned 32 bit integer from buf, which is previously encoded via encode_u32.

Panics

Panics when buf.len() < 4.

pub fn encode_u64(buf: &mut [u8], v: u64)[src]

Encodes an unsigned 64 bit integer v to buf, which is memory-comparable in ascending order.

Panics

Panics when buf.len() < 8.

pub fn decode_u64(buf: &[u8]) -> u64[src]

Decodes an unsigned 64 bit integer from buf, which is previously encoded via encode_u64.

Panics

Panics when buf.len() < 8.

pub fn encode_u64_desc(buf: &mut [u8], v: u64)[src]

Encodes an unsigned 64 bit integer v to buf, which is memory-comparable in descending order.

Panics

Panics when buf.len() < 8.

pub fn decode_u64_desc(buf: &[u8]) -> u64[src]

Decodes an unsigned 64 bit integer from buf, which is previously encoded via encode_u64_desc.

Panics

Panics when buf.len() < 8.

pub fn encode_i64(buf: &mut [u8], v: i64)[src]

Encodes a signed 64 bit integer v to buf, which is memory-comparable in ascending order.

Panics

Panics when buf.len() < 8.

pub fn decode_i64(buf: &[u8]) -> i64[src]

Decodes a signed 64 bit integer from buf, which is previously encoded via encode_i64.

Panics

Panics when buf.len() < 8.

pub fn encode_i64_desc(buf: &mut [u8], v: i64)[src]

Encodes a signed 64 bit integer v to buf, which is memory-comparable in descending order.

Panics

Panics when buf.len() < 8.

pub fn decode_i64_desc(buf: &[u8]) -> i64[src]

Decodes a signed 64 bit integer from buf, which is previously encoded via encode_i64_desc.

Panics

Panics when buf.len() < 8.

pub fn encode_f64(buf: &mut [u8], v: f64)[src]

Encodes a 64 bit float number v to buf, which is memory-comparable in ascending order.

Panics

Panics when buf.len() < 8.

pub fn decode_f64(buf: &[u8]) -> f64[src]

Decodes a 64 bit float number from buf, which is previously encoded via encode_f64.

Panics

Panics when buf.len() < 8.

pub fn encode_f64_desc(buf: &mut [u8], v: f64)[src]

Encodes a 64 bit float number v to buf, which is memory-comparable in descending order.

Panics

Panics when buf.len() < 8.

pub fn decode_f64_desc(buf: &[u8]) -> f64[src]

Decodes a 64 bit float number from buf, which is previously encoded via encode_f64_desc.

Panics

Panics when buf.len() < 8.

pub fn encode_u16_le(buf: &mut [u8], v: u16)[src]

Encodes an unsigned 16 bit integer v to buf in little endian, which is not memory-comparable.

Panics

Panics when buf.len() < 2.

pub fn decode_u16_le(buf: &[u8]) -> u16[src]

Decodes an unsigned 16 bit integer from buf in little endian, which is previously encoded via encode_u16_le.

Panics

Panics when buf.len() < 2.

pub fn encode_i16_le(buf: &mut [u8], v: i16)[src]

Encodes a signed 16 bit integer v to buf in little endian, which is not memory-comparable.

Panics

Panics when buf.len() < 2.

pub fn decode_i16_le(buf: &[u8]) -> i16[src]

Decodes a signed 16 bit integer from buf in little endian, which is previously encoded via encode_i16_le.

Panics

Panics when buf.len() < 2.

pub fn encode_f32_le(buf: &mut [u8], v: f32)[src]

Encodes a 32 bit float number v to buf in little endian, which is not memory-comparable.

Panics

Panics when buf.len() < 4.

pub fn decode_f32_le(buf: &[u8]) -> f32[src]

Decodes a 32 bit float number v to buf in little endian, which is not memory-comparable.

Panics

Panics when buf.len() < 4.

pub fn encode_u32_le(buf: &mut [u8], v: u32)[src]

Encodes an unsigned 32 bit integer v to buf in little endian, which is not memory-comparable.

Panics

Panics when buf.len() < 4.

pub fn decode_u32_le(buf: &[u8]) -> u32[src]

Decodes an unsigned 32 bit integer from buf in little endian, which is previously encoded via encode_u32_le.

Panics

Panics when buf.len() < 4.

pub fn encode_i32_le(buf: &mut [u8], v: i32)[src]

Encodes a signed 32 bit integer v to buf in little endian, which is not memory-comparable.

Panics

Panics when buf.len() < 4.

pub fn decode_i32_le(buf: &[u8]) -> i32[src]

Decodes a signed 32 bit integer from buf in little endian, which is previously encoded via encode_i32_le.

Panics

Panics when buf.len() < 4.

pub fn encode_u64_le(buf: &mut [u8], v: u64)[src]

Encodes an unsigned 64 bit integer v to buf in little endian, which is not memory-comparable.

Panics

Panics when buf.len() < 8.

pub fn decode_u64_le(buf: &[u8]) -> u64[src]

Decodes an unsigned 64 bit integer from buf in little endian, which is previously encoded via encode_u64_le.

Panics

Panics when buf.len() < 8.

pub fn encode_i64_le(buf: &mut [u8], v: i64)[src]

Encodes a signed 64 bit integer v to buf in little endian, which is not memory-comparable.

Panics

Panics when buf.len() < 8.

pub fn decode_i64_le(buf: &[u8]) -> i64[src]

Decodes a signed 64 bit integer from buf in little endian, which is previously encoded via encode_i64_le.

Panics

Panics when buf.len() < 8.

pub fn encode_f64_le(buf: &mut [u8], v: f64)[src]

Encodes a 64 bit float number v to buf in little endian, which is not memory-comparable.

Panics

Panics when buf.len() < 8.

pub fn decode_f64_le(buf: &[u8]) -> f64[src]

Decodes a 64 bit float number from buf in little endian, which is previously encoded via encode_f64_le.

Panics

Panics when buf.len() < 8.

pub fn encode_var_u64(buf: &mut [u8], v: u64) -> usize[src]

Encodes an unsigned 64 bit integer v to buf in VarInt encoding, which is not memory-comparable. Returns the number of bytes that encoded.

Note: VarInt encoding is slow, try avoid using it.

Panics

Panics when buf.len() < 10.

pub fn try_decode_var_u64(buf: &[u8]) -> Result<(u64, usize)>[src]

Decodes an unsigned 64 bit integer from buf in VarInt encoding. Returns decoded result and the number of bytes that successfully decoded.

This function is more efficient when buf.len() >= 10.

Errors

Returns Error::Io if there is not enough space to decode the whole VarInt.

pub fn encode_var_i64(buf: &mut [u8], v: i64) -> usize[src]

Encodes a signed 64 bit integer v to buf in VarInt encoding, which is not memory-comparable. Returns the number of bytes that encoded.

Note: VarInt encoding is slow, try avoid using it.

Panics

Panics when buf.len() < 10.

pub fn try_decode_var_i64(buf: &[u8]) -> Result<(i64, usize)>[src]

Decodes a signed 64 bit integer from buf in VarInt encoding. Returns decoded result and the number of bytes that successfully decoded.

This function is more efficient when buf.len() >= 10.

Errors

Returns Error::Io if there is not enough space to decode the whole VarInt.

pub fn get_first_encoded_var_int_len(buf: &[u8]) -> usize[src]

Gets the length of the first encoded VarInt in the given buffer. If the buffer is not complete, the length of buffer will be returned.

This function is more efficient when buf.len() >= 10.

Auto Trait Implementations

impl RefUnwindSafe for NumberCodec

impl Send for NumberCodec

impl Sync for NumberCodec

impl Unpin for NumberCodec

impl UnwindSafe for NumberCodec

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SendSyncUnwindSafe for T where
    T: Send + Sync + UnwindSafe + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>, 
[src]