pub struct HexCodec { /* private fields */ }Expand description
Encodes and decodes hexadecimal byte strings.
Implementations§
Source§impl HexCodec
impl HexCodec
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a lowercase codec without prefix or separators.
§Returns
A hexadecimal codec using lowercase digits.
Sourcepub fn upper() -> Self
pub fn upper() -> Self
Creates an uppercase codec without prefix or separators.
§Returns
A hexadecimal codec using uppercase digits.
Sourcepub fn with_uppercase(self, uppercase: bool) -> Self
pub fn with_uppercase(self, uppercase: bool) -> Self
Sourcepub fn with_prefix(self, prefix: impl Into<String>) -> Self
pub fn with_prefix(self, prefix: impl Into<String>) -> Self
Sets a per-byte prefix.
The prefix is written before every encoded byte and required before
every decoded byte. For example, using prefix 0x and separator
encodes bytes as 0x1F 0x8B.
This is not a whole-output prefix: [0x1F, 0x8B] is encoded as
0x1F 0x8B, not 0x1F 8B.
§Parameters
prefix: Prefix text such as0x.
§Returns
The updated codec.
Sourcepub fn with_separator(self, separator: impl Into<String>) -> Self
pub fn with_separator(self, separator: impl Into<String>) -> Self
Sourcepub fn with_ignored_ascii_whitespace(self, ignore: bool) -> Self
pub fn with_ignored_ascii_whitespace(self, ignore: bool) -> Self
Sourcepub fn encode_into(&self, bytes: &[u8], output: &mut String)
pub fn encode_into(&self, bytes: &[u8], output: &mut String)
Encodes bytes into an existing string.
§Parameters
bytes: Bytes to encode.output: Destination string.
Sourcepub fn decode(&self, text: &str) -> CodecResult<Vec<u8>>
pub fn decode(&self, text: &str) -> CodecResult<Vec<u8>>
Decodes hexadecimal text into bytes.
§Parameters
text: Hexadecimal text.
§Returns
Decoded bytes.
§Errors
Returns CodecError when a configured per-byte prefix is missing,
when the normalized digit count is odd, or when a non-hex digit is found.
Sourcepub fn decode_into(&self, text: &str, output: &mut Vec<u8>) -> CodecResult<()>
pub fn decode_into(&self, text: &str, output: &mut Vec<u8>) -> CodecResult<()>
Decodes hexadecimal text into an existing byte vector.
§Parameters
text: Hexadecimal text.output: Destination byte vector.
§Errors
Returns CodecError when the input is malformed.