pub struct Encoding<Bit: BitWidth, Msb: Bool, Pad: Bool, Wrap: Bool, Ignore: Bool> { /* private fields */ }Expand description
Base-conversion encoding.
See Specification for technical details or how to define a new one.
Implementations§
Source§impl<Bit: BitWidth, Msb: Bool, Pad: Bool, Wrap: Bool, Ignore: Bool> Encoding<Bit, Msb, Pad, Wrap, Ignore>
impl<Bit: BitWidth, Msb: Bool, Pad: Bool, Wrap: Bool, Ignore: Bool> Encoding<Bit, Msb, Pad, Wrap, Ignore>
Sourcepub fn encode_len(&self, len: usize) -> usize
pub fn encode_len(&self, len: usize) -> usize
Returns the encoded length of an input of length len.
See Self::encode_mut() for when to use it.
Sourcepub fn encode_mut_uninit<'a>(
&self,
input: &[u8],
output: &'a mut [MaybeUninit<u8>],
) -> &'a mut [u8] ⓘ
pub fn encode_mut_uninit<'a>( &self, input: &[u8], output: &'a mut [MaybeUninit<u8>], ) -> &'a mut [u8] ⓘ
Encodes input in output.
§Panics
Panics if the output length does not match the result of Self::encode_len() for the
input length.
Sourcepub fn encode_mut(&self, input: &[u8], output: &mut [u8])
pub fn encode_mut(&self, input: &[u8], output: &mut [u8])
Encodes input in output.
§Panics
Panics if the output length does not match the result of Self::encode_len() for the
input length.
Sourcepub fn encode_append(&self, input: &[u8], output: &mut String)
Available on crate feature alloc only.
pub fn encode_append(&self, input: &[u8], output: &mut String)
alloc only.Appends the encoding of input to output.
Sourcepub fn encode_write_buffer_uninit(
&self,
input: &[u8],
output: &mut impl Write,
buffer: &mut [MaybeUninit<u8>],
) -> Result
pub fn encode_write_buffer_uninit( &self, input: &[u8], output: &mut impl Write, buffer: &mut [MaybeUninit<u8>], ) -> Result
Sourcepub fn encode_write_buffer(
&self,
input: &[u8],
output: &mut impl Write,
buffer: &mut [u8],
) -> Result
pub fn encode_write_buffer( &self, input: &[u8], output: &mut impl Write, buffer: &mut [u8], ) -> Result
Sourcepub fn encode_write(&self, input: &[u8], output: &mut impl Write) -> Result
pub fn encode_write(&self, input: &[u8], output: &mut impl Write) -> Result
Writes the encoding of input to output.
This allocates a buffer of 1024 bytes on the stack. If you want to control the buffer size
and location, use Self::encode_write_buffer() instead.
§Errors
Returns an error when writing to the output fails.
Sourcepub fn encode(&self, input: &[u8]) -> String
Available on crate feature alloc only.
pub fn encode(&self, input: &[u8]) -> String
alloc only.Returns encoded input.
Sourcepub fn decode_len(&self, len: usize) -> Result<usize, DecodeError>
pub fn decode_len(&self, len: usize) -> Result<usize, DecodeError>
Returns the decoded length of an input of length len.
See Self::decode_mut() for when to use it.
§Errors
Returns an error if len is invalid. The error kind is
DecodeKind::Length and the error position is the greatest valid
input length.
Sourcepub fn decode_mut_uninit<'a>(
&self,
input: &[u8],
output: &'a mut [MaybeUninit<u8>],
) -> Result<&'a mut [u8], DecodePartial>
pub fn decode_mut_uninit<'a>( &self, input: &[u8], output: &'a mut [MaybeUninit<u8>], ) -> Result<&'a mut [u8], DecodePartial>
Decodes input in output.
Returns the decoded output. Its length may be smaller than the output length if the input contained padding or ignored characters. The output bytes after the returned length are not initialized and should not be read.
§Panics
Panics if the output length does not match the result of Self::decode_len() for the
input length. Also panics if decode_len fails for the input length.
§Errors
Returns an error if input is invalid. See Self::decode_mut() for more details.
Sourcepub fn decode_mut(
&self,
input: &[u8],
output: &mut [u8],
) -> Result<usize, DecodePartial>
pub fn decode_mut( &self, input: &[u8], output: &mut [u8], ) -> Result<usize, DecodePartial>
Decodes input in output.
Returns the length of the decoded output. This length may be smaller than the output length if the input contained padding or ignored characters. The output bytes after the returned length are not initialized and should not be read.
§Panics
Panics if the output length does not match the result of Self::decode_len() for the
input length. Also panics if decode_len fails for the input length.
§Errors
Returns an error if input is invalid. See Self::decode() for more details. The are two
differences though:
DecodeKind::Lengthmay be returned only if the encoding allows ignored characters, because otherwise this is already checked bySelf::decode_len().- The
DecodePartial::readfirst bytes of the input have been successfully decoded to theDecodePartial::writtenfirst bytes of the output.
Sourcepub fn decode(&self, input: &[u8]) -> Result<Vec<u8>, DecodeError>
Available on crate feature alloc only.
pub fn decode(&self, input: &[u8]) -> Result<Vec<u8>, DecodeError>
alloc only.Returns decoded input.
§Errors
Returns an error if input is invalid. The error kind can be:
DecodeKind::Lengthif the input length is invalid. The position is the greatest valid input length.DecodeKind::Symbolif the input contains an invalid character. The position is the first invalid character.DecodeKind::Trailingif the input has non-zero trailing bits. This is only possible if the encoding checks trailing bits. The position is the first character containing non-zero trailing bits.DecodeKind::Paddingif the input has an invalid padding length. This is only possible if the encoding uses padding. The position is the first padding character of the first padding of invalid length.
Sourcepub fn specification(&self) -> Specification
Available on crate feature alloc only.
pub fn specification(&self) -> Specification
alloc only.TODO
Sourcepub fn as_dyn(&self) -> &DynEncoding
pub fn as_dyn(&self) -> &DynEncoding
TODO