pub struct FormUrlencodedCodec;Expand description
Encodes and decodes application/x-www-form-urlencoded text fragments.
Its low-level Codec<Value = u8, Unit = u8> implementation converts one
byte at a time, including the form-specific space and + mapping. UTF-8
validation remains part of the owned decode helper.
Streaming skip/replace hooks may consume the malformed span visible in the
current input chunk, so recovery output for malformed input can depend on
chunk boundaries. This does not affect valid input or strict decoding.
§Examples
use qubit_codec_misc::FormUrlencodedCodec;
let codec = FormUrlencodedCodec::new();
let encoded = codec.encode("hello world");
assert_eq!(encoded, "hello+world");
assert_eq!(codec.decode(&encoded).unwrap(), "hello world");Implementations§
Source§impl FormUrlencodedCodec
impl FormUrlencodedCodec
Sourcepub fn decode(&self, text: &str) -> MiscCodecResult<String>
pub fn decode(&self, text: &str) -> MiscCodecResult<String>
Decodes text, treating + as space.
§Parameters
text: Text to decode.
§Returns
Decoded UTF-8 text.
§Errors
Returns MiscCodecError when an escape is malformed or decoded bytes
are not valid UTF-8.
Trait Implementations§
Source§impl Clone for FormUrlencodedCodec
impl Clone for FormUrlencodedCodec
Source§impl Codec for FormUrlencodedCodec
impl Codec for FormUrlencodedCodec
Source§type DecodeError = MiscCodecError
type DecodeError = MiscCodecError
Errors raised when an encoded byte sequence cannot be decoded.
Source§type EncodeError = MiscCodecError
type EncodeError = MiscCodecError
Errors raised when a value cannot be encoded.
Source§fn encode_len(&self, value: &u8) -> usize
fn encode_len(&self, value: &u8) -> usize
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 raw byte, +, or %XX escape.
§Parameters
input: Encoded input bytes.input_index: Index of the value to decode.
§Returns
The decoded byte and the non-zero number of consumed input units.
§Errors
Returns a decode failure when the input is malformed or incomplete.
§Safety
The caller must provide an input index with at least one readable unit and a slice satisfying the codec trait’s decode preconditions.
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 using form URL encoding.
§Parameters
value: Byte to encode.output: Destination buffer.output_index: Index at which encoding begins.
§Returns
The number of output bytes written.
§Errors
This implementation does not fail when the caller satisfies the safety preconditions.
§Safety
The caller must provide enough writable output units for
Self::encode_len.
Source§unsafe fn decode_eof(
&mut self,
input: &[u8],
input_index: usize,
) -> Result<(u8, NonZeroUsize), DecodeFailure<Self::DecodeError>>
unsafe fn decode_eof( &mut self, input: &[u8], input_index: usize, ) -> Result<(u8, NonZeroUsize), DecodeFailure<Self::DecodeError>>
Decodes one value after end of input has been confirmed.
§Parameters
input: Encoded input bytes.input_index: Index of the value to decode.
§Returns
The decoded byte and the non-zero number of consumed input units.
§Errors
Returns a decode failure when the input is malformed or incomplete at end of input.
§Safety
The caller must provide an input index with at least one readable unit and a slice satisfying the codec trait’s EOF decode preconditions.
Source§const MIN_UNITS_PER_VALUE: usize = 1
const MIN_UNITS_PER_VALUE: usize = 1
Source§const MAX_ENCODE_UNITS_PER_VALUE: usize = 3
const MAX_ENCODE_UNITS_PER_VALUE: usize = 3
Source§const MAX_DECODE_UNITS_PER_VALUE: usize = 3
const MAX_DECODE_UNITS_PER_VALUE: usize = 3
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§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_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 moreimpl Copy for FormUrlencodedCodec
Source§impl Debug for FormUrlencodedCodec
impl Debug for FormUrlencodedCodec
Source§impl Default for FormUrlencodedCodec
impl Default for FormUrlencodedCodec
impl Eq for FormUrlencodedCodec
Source§impl PartialEq for FormUrlencodedCodec
impl PartialEq for FormUrlencodedCodec
impl StructuralPartialEq for FormUrlencodedCodec
Source§impl ValueDecoder<str> for FormUrlencodedCodec
impl ValueDecoder<str> for FormUrlencodedCodec
Source§type Error = MiscCodecError
type Error = MiscCodecError
Errors produced when the encoded value is malformed or not valid UTF-8.
Source§impl ValueEncoder<str> for FormUrlencodedCodec
impl ValueEncoder<str> for FormUrlencodedCodec
Source§type Error = MiscCodecError
type Error = MiscCodecError
Errors produced while converting an encoded value.
Form URL encoding accepts every UTF-8 string, so this implementation does not produce an error.