Struct codec::byte::MemComparableByteCodec[][src]

pub struct MemComparableByteCodec;

Memory-comparable encoding and decoding utility for bytes.

Implementations

impl MemComparableByteCodec[src]

pub fn encoded_len(src_len: usize) -> usize[src]

Calculates the length of the value after encoding.

fn get_first_encoded_len_internal<T: MemComparableCodecHelper>(
    encoded: &[u8]
) -> usize
[src]

Gets the length of the first encoded byte sequence in the given buffer, which is encoded in the memory-comparable format. If the buffer is not complete, the length of buffer will be returned.

pub fn get_first_encoded_len(encoded: &[u8]) -> usize[src]

Gets the length of the first encoded byte sequence in the given buffer, which is encoded in the ascending memory-comparable format.

pub fn get_first_encoded_len_desc(encoded: &[u8]) -> usize[src]

Gets the length of the first encoded byte sequence in the given buffer, which is encoded in the descending memory-comparable format.

pub fn encode_all(src: &[u8], dest: &mut [u8]) -> usize[src]

Encodes all bytes in the src into dest in ascending memory-comparable format.

Returns the number of bytes encoded.

dest must not overlaps src, otherwise encoded results will be incorrect.

Panics

Panics if there is not enough space in dest for writing encoded bytes.

You can calculate required space size via encoded_len.

pub fn encode_all_in_place(src: &mut [u8], len: usize) -> usize[src]

Encodes the bytes src[..len] in ascending memory-comparable format in place.

Returns the number of bytes encoded.

Panics

Panics if the length of src is not enough for writing encoded bytes.

fn flip_bytes_in_place(src: &mut [u8], len: usize)[src]

Performs in place bitwise NOT for specified memory region.

Panics

Panics if len exceeds src.len().

pub fn encode_all_desc(src: &[u8], dest: &mut [u8]) -> usize[src]

Encodes all bytes in the src into dest in descending memory-comparable format.

Returns the number of bytes encoded.

dest must not overlaps src, otherwise encoded results will be incorrect.

Panics

Panics if there is not enough space in dest for writing encoded bytes.

You can calculate required space size via encoded_len.

pub fn encode_all_in_place_desc(src: &mut [u8], len: usize) -> usize[src]

Encodes the bytes src[..len] in descending memory-comparable format in place.

Returns the number of bytes encoded.

Panics

Panics if the length of src is not enough for writing encoded bytes.

pub fn try_decode_first(src: &[u8], dest: &mut [u8]) -> Result<(usize, usize)>[src]

Decodes bytes in ascending memory-comparable format in the src into dest.

If there are multiple encoded byte slices in src, only the first one will be decoded.

Returns (read_bytes, written_bytes) where read_bytes is the number of bytes read in src and written_bytes is the number of bytes written in dest.

Note that actual written data may be larger than written_bytes. Bytes more than written_bytes are junk and should be ignored.

If src == dest, please use try_decode_first_in_place.

Panics

Panics if dest.len() < src.len(), although actual written data may be less.

When there is a panic, dest may contain partially written data.

Errors

Returns Error::Io if src is drained while expecting more data.

Returns Error::BadPadding if padding in src is incorrect.

When there is an error, dest may contain partially written data.

pub fn try_decode_first_desc(
    src: &[u8],
    dest: &mut [u8]
) -> Result<(usize, usize)>
[src]

Decodes bytes in descending memory-comparable format in the src into dest.

If there are multiple encoded byte slices in src, only the first one will be decoded.

Returns (read_bytes, written_bytes) where read_bytes is the number of bytes read in src and written_bytes is the number of bytes written in dest.

Note that actual written data may be larger than written_bytes. Bytes more than written_bytes are junk and should be ignored.

If src == dest, please use try_decode_first_in_place_desc.

Panics

Panics if dest.len() < src.len(), although actual written data may be less.

When there is a panic, dest may contain partially written data.

Errors

Returns Error::Io if src is drained while expecting more data.

Returns Error::BadPadding if padding in src is incorrect.

When there is an error, dest may contain partially written data.

pub fn try_decode_first_in_place(buffer: &mut [u8]) -> Result<(usize, usize)>[src]

Decodes bytes in ascending memory-comparable format in place, i.e. decoded data will overwrite the encoded data.

If there are multiple encoded byte slices in buffer, only the first one will be decoded.

Returns (read_bytes, written_bytes) where read_bytes is the number of bytes read and written_bytes is the number of bytes written.

Note that actual written data may be larger than written_bytes. Bytes more than written_bytes are junk and should be ignored.

Errors

Returns Error::Io if buffer is drained while expecting more data.

Returns Error::BadPadding if padding in buffer is incorrect.

When there is an error, dest may contain partially written data.

pub fn try_decode_first_in_place_desc(
    buffer: &mut [u8]
) -> Result<(usize, usize)>
[src]

Decodes bytes in descending memory-comparable format in place, i.e. decoded data will overwrite the encoded data.

If there are multiple encoded byte slices in buffer, only the first one will be decoded.

Returns (read_bytes, written_bytes) where read_bytes is the number of bytes read and written_bytes is the number of bytes written.

Note that actual written data may be larger than written_bytes. Bytes more than written_bytes are junk and should be ignored.

Errors

Returns Error::Io if buffer is drained while expecting more data.

Returns Error::BadPadding if padding in buffer is incorrect.

When there is an error, dest may contain partially written data.

fn try_decode_first_internal<T: MemComparableCodecHelper>(
    src_ptr: *const u8,
    src_len: usize,
    dest_ptr: *mut u8,
    dest_len: usize,
    _helper: T
) -> Result<(usize, usize)>
[src]

The internal implementation for:

  • try_decode_first
  • try_decode_first_desc
  • try_decode_first_in_place
  • try_decode_first_in_place_desc

This function uses pointers to accept the scenario that src == dest.

This function also uses generics to specialize different code path for ascending and descending decoding, which performs better than inlining a flag.

Please refer to try_decode_first for the meaning of return values, panics and errors.

Auto Trait Implementations

impl RefUnwindSafe for MemComparableByteCodec

impl Send for MemComparableByteCodec

impl Sync for MemComparableByteCodec

impl Unpin for MemComparableByteCodec

impl UnwindSafe for MemComparableByteCodec

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]