Struct AnyDelimiterCodec
struct AnyDelimiterCodec { ... }
A simple Decoder and Encoder implementation that splits up data into chunks based on any character in the given delimiter string.
Example
Decode string of bytes containing various different delimiters.
use ;
use ;
#
#
# async
Implementations
impl AnyDelimiterCodec
fn new(seek_delimiters: Vec<u8>, sequence_writer: Vec<u8>) -> AnyDelimiterCodecReturns a
AnyDelimiterCodecfor splitting up data into chunks.Note
The returned
AnyDelimiterCodecwill not have an upper bound on the length of a buffered chunk. See the documentation fornew_with_max_lengthfor information on why this could be a potential security risk.fn new_with_max_length(seek_delimiters: Vec<u8>, sequence_writer: Vec<u8>, max_length: usize) -> SelfReturns a
AnyDelimiterCodecwith a maximum chunk length limit.If this is set, calls to
AnyDelimiterCodec::decodewill return aAnyDelimiterCodecErrorwhen a chunk exceeds the length limit. Subsequent calls will discard up tolimitbytes from that chunk until a delimiter character is reached, returningNoneuntil the delimiter over the limit has been fully discarded. After that point, calls todecodewill function as normal.Note
Setting a length limit is highly recommended for any
AnyDelimiterCodecwhich will be exposed to untrusted input. Otherwise, the size of the buffer that holds the chunk currently being read is unbounded. An attacker could exploit this unbounded buffer by sending an unbounded amount of input without any delimiter characters, causing unbounded memory consumption.fn max_length(self: &Self) -> usizeReturns the maximum chunk length when decoding.
use usize; use AnyDelimiterCodec; let codec = new; assert_eq!;use AnyDelimiterCodec; let codec = new_with_max_length; assert_eq!;
impl Clone for AnyDelimiterCodec
fn clone(self: &Self) -> AnyDelimiterCodec
impl Debug for AnyDelimiterCodec
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Decoder for AnyDelimiterCodec
fn decode(self: &mut Self, buf: &mut BytesMut) -> Result<Option<Bytes>, AnyDelimiterCodecError>fn decode_eof(self: &mut Self, buf: &mut BytesMut) -> Result<Option<Bytes>, AnyDelimiterCodecError>
impl Default for AnyDelimiterCodec
fn default() -> Self
impl Eq for AnyDelimiterCodec
impl Freeze for AnyDelimiterCodec
impl Hash for AnyDelimiterCodec
fn hash<__H: $crate::hash::Hasher>(self: &Self, state: &mut __H)
impl Ord for AnyDelimiterCodec
fn cmp(self: &Self, other: &AnyDelimiterCodec) -> Ordering
impl PartialEq for AnyDelimiterCodec
fn eq(self: &Self, other: &AnyDelimiterCodec) -> bool
impl PartialOrd for AnyDelimiterCodec
fn partial_cmp(self: &Self, other: &AnyDelimiterCodec) -> Option<Ordering>
impl RefUnwindSafe for AnyDelimiterCodec
impl Send for AnyDelimiterCodec
impl StructuralPartialEq for AnyDelimiterCodec
impl Sync for AnyDelimiterCodec
impl Unpin for AnyDelimiterCodec
impl UnsafeUnpin for AnyDelimiterCodec
impl UnwindSafe for AnyDelimiterCodec
impl<T> Any for AnyDelimiterCodec
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for AnyDelimiterCodec
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for AnyDelimiterCodec
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for AnyDelimiterCodec
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> Encoder for AnyDelimiterCodec
fn encode(self: &mut Self, chunk: T, buf: &mut BytesMut) -> Result<(), AnyDelimiterCodecError>
impl<T> From for AnyDelimiterCodec
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for AnyDelimiterCodec
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for AnyDelimiterCodec
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for AnyDelimiterCodec
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for AnyDelimiterCodec
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>