pub struct Leb128Codec<T, P = NonStrict> { /* private fields */ }Expand description
Type-level unchecked LEB128 codec.
T selects the decoded integer type and P selects the decoding policy.
Encoding is always canonical; P only affects decoding.
Implementations§
Source§impl<P> Leb128Codec<u8, P>where
P: DecodePolicy,
impl<P> Leb128Codec<u8, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(u8, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(u8, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: u8,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: u8, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<u16, P>where
P: DecodePolicy,
impl<P> Leb128Codec<u16, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(u16, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(u16, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: u16,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: u16, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<u32, P>where
P: DecodePolicy,
impl<P> Leb128Codec<u32, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(u32, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(u32, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: u32,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: u32, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<u64, P>where
P: DecodePolicy,
impl<P> Leb128Codec<u64, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(u64, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(u64, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: u64,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: u64, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<u128, P>where
P: DecodePolicy,
impl<P> Leb128Codec<u128, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(u128, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(u128, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: u128,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: u128, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<usize, P>where
P: DecodePolicy,
impl<P> Leb128Codec<usize, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(usize, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(usize, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: usize,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: usize, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<i8, P>where
P: DecodePolicy,
impl<P> Leb128Codec<i8, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(i8, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(i8, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: i8,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: i8, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<i16, P>where
P: DecodePolicy,
impl<P> Leb128Codec<i16, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(i16, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(i16, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: i16,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: i16, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<i32, P>where
P: DecodePolicy,
impl<P> Leb128Codec<i32, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(i32, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(i32, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: i32,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: i32, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<i64, P>where
P: DecodePolicy,
impl<P> Leb128Codec<i64, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(i64, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(i64, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: i64,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: i64, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<i128, P>where
P: DecodePolicy,
impl<P> Leb128Codec<i128, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(i128, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(i128, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: i128,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: i128, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Source§impl<P> Leb128Codec<isize, P>where
P: DecodePolicy,
impl<P> Leb128Codec<isize, P>where
P: DecodePolicy,
Sourcepub const REQUIRED_MIN_BUFFER_LEN: usize
pub const REQUIRED_MIN_BUFFER_LEN: usize
Minimum number of bytes required to encode or decode this type.
Sourcepub unsafe fn read_unchecked(
input: &[u8],
index: usize,
) -> Result<(isize, usize), Leb128DecodeError>
pub unsafe fn read_unchecked( input: &[u8], index: usize, ) -> Result<(isize, usize), Leb128DecodeError>
Decodes a value from input starting at index without bounds checks.
§Parameters
input: Source byte buffer.index: Start index ininput.
§Returns
Returns the decoded value and the number of consumed bytes.
§Errors
Returns Leb128DecodeError if the bytes are malformed or strict
decoding rejects a non-canonical representation.
§Safety
The caller must guarantee that input.as_ptr().add(index) is valid to
read Self::REQUIRED_MIN_BUFFER_LEN bytes, or that a valid terminating byte
appears before that limit.
Sourcepub unsafe fn write_unchecked(
output: &mut [u8],
index: usize,
value: isize,
) -> usize
pub unsafe fn write_unchecked( output: &mut [u8], index: usize, value: isize, ) -> usize
Encodes value into output starting at index without bounds checks.
§Parameters
output: Destination byte buffer.index: Start index inoutput.value: Value to encode.
§Returns
Returns the number of written bytes.
§Safety
The caller must guarantee that output.as_mut_ptr().add(index) is valid
to write Self::REQUIRED_MIN_BUFFER_LEN bytes.
Trait Implementations§
Source§impl<T: Clone, P: Clone> Clone for Leb128Codec<T, P>
impl<T: Clone, P: Clone> Clone for Leb128Codec<T, P>
Source§fn clone(&self) -> Leb128Codec<T, P>
fn clone(&self) -> Leb128Codec<T, P>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<T: Default, P: Default> Default for Leb128Codec<T, P>
impl<T: Default, P: Default> Default for Leb128Codec<T, P>
Source§fn default() -> Leb128Codec<T, P>
fn default() -> Leb128Codec<T, P>
Source§impl<T: PartialEq, P: PartialEq> PartialEq for Leb128Codec<T, P>
impl<T: PartialEq, P: PartialEq> PartialEq for Leb128Codec<T, P>
Source§fn eq(&self, other: &Leb128Codec<T, P>) -> bool
fn eq(&self, other: &Leb128Codec<T, P>) -> bool
self and other values to be equal, and is used by ==.