Struct Builder
struct Builder { ... }
Configure length delimited LengthDelimitedCodecs.
Builder enables constructing configured length delimited codecs. Note
that not all configuration settings apply to both encoding and decoding. See
the documentation for specific methods for more detail.
Note that the if the value of Builder::max_frame_length becomes larger than
what can actually fit in Builder::length_field_length, it will be clipped to
the maximum value that can fit.
Implementations
impl Builder
fn new() -> BuilderCreates a new length delimited codec builder with default configuration values.
Examples
# use AsyncRead; use LengthDelimitedCodec; # #fn big_endian(self: &mut Self) -> &mut SelfRead the length field as a big endian integer
This is the default setting.
This configuration option applies to both encoding and decoding.
Examples
# use AsyncRead; use LengthDelimitedCodec; # #fn little_endian(self: &mut Self) -> &mut SelfRead the length field as a little endian integer
The default setting is big endian.
This configuration option applies to both encoding and decoding.
Examples
# use AsyncRead; use LengthDelimitedCodec; # #fn native_endian(self: &mut Self) -> &mut SelfRead the length field as a native endian integer
The default setting is big endian.
This configuration option applies to both encoding and decoding.
Examples
# use AsyncRead; use LengthDelimitedCodec; # #fn max_frame_length(self: &mut Self, val: usize) -> &mut SelfSets the max frame length in bytes
This configuration option applies to both encoding and decoding. The default value is 8MB.
When decoding, the length field read from the byte stream is checked against this setting before any adjustments are applied. When encoding, the length of the submitted payload is checked against this setting.
When frames exceed the max length, an
io::Errorwith the custom value of theLengthDelimitedCodecErrortype will be returned.Examples
# use AsyncRead; use LengthDelimitedCodec; # #fn length_field_type<T: builder::LengthFieldType>(self: &mut Self) -> &mut SelfSets the unsigned integer type used to represent the length field.
The default type is
u32. The max type isu64(orusizeon 64-bit targets).Examples
# use AsyncRead; use LengthDelimitedCodec; # #Unlike
Builder::length_field_length, this does not fail at runtime and instead produces a compile error:# use tokio::io::AsyncRead; # use tokio_util::codec::LengthDelimitedCodec; # fn bind_read<T: AsyncRead>(io: T) { LengthDelimitedCodec::builder() .length_field_type::<u128>() .new_read(io); # } # pub fn main() {}fn length_field_length(self: &mut Self, val: usize) -> &mut SelfSets the number of bytes used to represent the length field
The default value is
4. The max value is8.This configuration option applies to both encoding and decoding.
Examples
# use AsyncRead; use LengthDelimitedCodec; # #fn length_field_offset(self: &mut Self, val: usize) -> &mut SelfSets the number of bytes in the header before the length field
This configuration option only applies to decoding.
Examples
# use AsyncRead; use LengthDelimitedCodec; # #fn length_adjustment(self: &mut Self, val: isize) -> &mut SelfDelta between the payload length specified in the header and the real payload length
Examples
# use AsyncRead; use LengthDelimitedCodec; # #fn num_skip(self: &mut Self, val: usize) -> &mut SelfSets the number of bytes to skip before reading the payload
Default value is
length_field_len + length_field_offsetThis configuration option only applies to decoding
Examples
# use AsyncRead; use LengthDelimitedCodec; # #fn new_codec(self: &Self) -> LengthDelimitedCodecCreate a configured length delimited
LengthDelimitedCodecExamples
use LengthDelimitedCodec; #fn new_read<T>(self: &Self, upstream: T) -> FramedRead<T, LengthDelimitedCodec> where T: AsyncReadCreate a configured length delimited
FramedReadExamples
# use AsyncRead; use LengthDelimitedCodec; # #fn new_write<T>(self: &Self, inner: T) -> FramedWrite<T, LengthDelimitedCodec> where T: AsyncWriteCreate a configured length delimited
FramedWriteExamples
# use AsyncWrite; # use LengthDelimitedCodec; # #fn new_framed<T>(self: &Self, inner: T) -> Framed<T, LengthDelimitedCodec> where T: AsyncRead + AsyncWriteCreate a configured length delimited
FramedExamples
# use ; # use LengthDelimitedCodec; # #
impl Clone for Builder
fn clone(self: &Self) -> Builder
impl Copy for Builder
impl Debug for Builder
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl Default for Builder
fn default() -> Self
impl Freeze for Builder
impl RefUnwindSafe for Builder
impl Send for Builder
impl Sync for Builder
impl Unpin for Builder
impl UnsafeUnpin for Builder
impl UnwindSafe for Builder
impl<T> Any for Builder
fn type_id(self: &Self) -> TypeId
impl<T> Borrow for Builder
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Builder
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Builder
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> From for Builder
fn from(t: T) -> TReturns the argument unchanged.
impl<T> ToOwned for Builder
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T, U> Into for Builder
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 Builder
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Builder
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>