pub struct HexByteCodec { /* private fields */ }Expand description
Encodes and decodes one byte as two ASCII hexadecimal units.
HexByteCodec is the low-level Codec implementation for streaming or
generic codec call sites. It does not understand whole-string prefixes,
per-byte prefixes, separators, or whitespace. Use crate::HexCodec for
owned byte-slice helpers with those formatting options.
For a complete safe streaming adapter example, see the English README and Chinese README.
§Examples
use qubit_codec::Codec;
use qubit_codec_misc::HexByteCodec;
let mut codec = HexByteCodec::upper();
let mut output = [0_u8; 2];
let written = unsafe { Codec::encode(&mut codec, &0xaf, &mut output, 0) }?;
assert_eq!(2, written);
assert_eq!(b"AF", &output);Implementations§
Source§impl HexByteCodec
impl HexByteCodec
Sourcepub const fn is_uppercase(self) -> bool
pub const fn is_uppercase(self) -> bool
Returns whether this byte codec emits uppercase hexadecimal digits.
Sourcepub const fn with_uppercase(self, uppercase: bool) -> Self
pub const fn with_uppercase(self, uppercase: bool) -> Self
Trait Implementations§
Source§impl Clone for HexByteCodec
impl Clone for HexByteCodec
Source§impl Codec for HexByteCodec
impl Codec for HexByteCodec
Source§type DecodeError = MiscCodecError
type DecodeError = MiscCodecError
The codec error reported when either input digit is invalid.
Source§type EncodeError = MiscCodecError
type EncodeError = MiscCodecError
The codec error type required by the trait; this implementation does not produce encoding errors for byte values.
Source§unsafe fn decode(
&mut self,
input: &[u8],
input_index: usize,
) -> Result<(u8, NonZeroUsize), DecodeFailure<Self::DecodeError>>
unsafe fn decode( &mut self, input: &[u8], input_index: usize, ) -> Result<(u8, NonZeroUsize), DecodeFailure<Self::DecodeError>>
Decodes one byte from two ASCII hexadecimal digits.
The digits are read from input starting at input_index. Invalid
digits are reported with their position in the input.
§Parameters
input: The byte units containing the hexadecimal digits.input_index: The index of the first digit.
§Returns
The decoded byte and the nonzero number of input units consumed (two).
§Errors
Returns a decode failure when either input unit is not an ASCII hexadecimal digit. The failure identifies the invalid digit and its input position.
§Safety
input must contain at least two readable units starting at
input_index.
Source§unsafe fn encode(
&mut self,
value: &u8,
output: &mut [u8],
output_index: usize,
) -> Result<usize, Self::EncodeError>
unsafe fn encode( &mut self, value: &u8, output: &mut [u8], output_index: usize, ) -> Result<usize, Self::EncodeError>
Encodes one byte as two ASCII hexadecimal digits.
§Parameters
value: The byte to encode.output: The buffer that receives the encoded digits.output_index: The index of the first output unit to write.
§Returns
The number of output units written (two).
§Errors
This implementation does not return an encoding error; the result is
retained to satisfy the Codec interface.
§Safety
output must contain at least two writable units starting at
output_index.
Source§const MIN_UNITS_PER_VALUE: usize = 2
const MIN_UNITS_PER_VALUE: usize = 2
Source§const MAX_ENCODE_UNITS_PER_VALUE: usize = 2
const MAX_ENCODE_UNITS_PER_VALUE: usize = 2
Source§const MAX_DECODE_UNITS_PER_VALUE: usize = 2
const MAX_DECODE_UNITS_PER_VALUE: usize = 2
Source§const MAX_ENCODE_RESET_UNITS: usize = 0
const MAX_ENCODE_RESET_UNITS: usize = 0
Source§const MAX_ENCODE_FINISH_UNITS: usize = 0
const MAX_ENCODE_FINISH_UNITS: usize = 0
Source§const MAX_DECODE_RESET_VALUES: usize = 0
const MAX_DECODE_RESET_VALUES: usize = 0
Source§const MAX_DECODE_FINISH_VALUES: usize = 0
const MAX_DECODE_FINISH_VALUES: usize = 0
Source§fn can_encode_value(&self, _value: &Self::Value) -> bool
fn can_encode_value(&self, _value: &Self::Value) -> bool
value is in this codec’s encodable value domain. Read moreSource§fn encode_len(&self, _value: &Self::Value) -> usize
fn encode_len(&self, _value: &Self::Value) -> usize
value. Read moreSource§unsafe fn encode_reset(
&mut self,
_output: &mut [Self::Unit],
_output_index: usize,
) -> Result<usize, Self::EncodeError>
unsafe fn encode_reset( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>
Source§unsafe fn encode_finish(
&mut self,
_output: &mut [Self::Unit],
_output_index: usize,
) -> Result<usize, Self::EncodeError>
unsafe fn encode_finish( &mut self, _output: &mut [Self::Unit], _output_index: usize, ) -> Result<usize, Self::EncodeError>
Source§unsafe fn decode_reset(
&mut self,
_output: &mut [Self::Value],
_output_index: usize,
) -> Result<usize, Self::DecodeError>
unsafe fn decode_reset( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>
Source§unsafe fn decode_eof(
&mut self,
input: &[Self::Unit],
input_index: usize,
) -> Result<(Self::Value, NonZero<usize>), DecodeFailure<Self::DecodeError>>
unsafe fn decode_eof( &mut self, input: &[Self::Unit], input_index: usize, ) -> Result<(Self::Value, NonZero<usize>), DecodeFailure<Self::DecodeError>>
Source§unsafe fn decode_finish(
&mut self,
_output: &mut [Self::Value],
_output_index: usize,
) -> Result<usize, Self::DecodeError>
unsafe fn decode_finish( &mut self, _output: &mut [Self::Value], _output_index: usize, ) -> Result<usize, Self::DecodeError>
output. Read more