# tokio_util::codec::length_delimited::Builder - Rust
API documentation for the Rust `Builder` struct in crate `tokio_util`.
Keywords: rust, rustlang, rust-lang, Builder

# Struct tokio_util::codec::length_delimited::Builder [−] [src]

    pub struct Builder { /* fields omitted */ }

Configure length delimited `LengthDelimitedCodec`s.

`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.

## Implementations

### `impl Builder` [src]

#### `pub fn new() -> Builder` [src]

Creates a new length delimited codec builder with default configuration values.

# Examples

    use tokio_util::codec::LengthDelimitedCodec;

    LengthDelimitedCodec::builder()
        .length_field_offset(0)
        .length_field_length(2)
        .length_adjustment(0)
        .num_skip(0)
        .new_read(io);

#### `pub fn big_endian(&mut self) -> &mut Self` [src]

Read the length field as a big endian integer

This is the default setting.

This configuration option applies to both encoding and decoding.

# Examples

    use tokio_util::codec::LengthDelimitedCodec;

    LengthDelimitedCodec::builder()
        .big_endian()
        .new_read(io);

#### `pub fn little_endian(&mut self) -> &mut Self` [src]

Read 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 tokio_util::codec::LengthDelimitedCodec;

    LengthDelimitedCodec::builder()
        .little_endian()
        .new_read(io);

#### `pub fn native_endian(&mut self) -> &mut Self` [src]

Read 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 tokio_util::codec::LengthDelimitedCodec;

    LengthDelimitedCodec::builder()
        .native_endian()
        .new_read(io);

#### `pub fn max_frame_length(&mut self, val: usize) -> &mut Self` [src]

Sets the max frame length

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::Error` with the custom value of the `LengthDelimitedCodecError` type will be returned.

# Examples

    use tokio_util::codec::LengthDelimitedCodec;

    LengthDelimitedCodec::builder()
        .max_frame_length(8 * 1024)
        .new_read(io);

#### `pub fn length_field_length(&mut self, val: usize) -> &mut Self` [src]

Sets the number of bytes used to represent the length field

The default value is `4`. The max value is `8`.

This configuration option applies to both encoding and decoding.

# Examples

    use tokio_util::codec::LengthDelimitedCodec;

    LengthDelimitedCodec::builder()
        .length_field_length(4)
        .new_read(io);

#### `pub fn length_field_offset(&mut self, val: usize) -> &mut Self` [src]

Sets the number of bytes in the header before the length field

This configuration option only applies to decoding.

# Examples

    use tokio_util::codec::LengthDelimitedCodec;

    LengthDelimitedCodec::builder()
        .length_field_offset(1)
        .new_read(io);

#### `pub fn length_adjustment(&mut self, val: isize) -> &mut Self` [src]

Delta between the payload length specified in the header and the real payload length

# Examples

    use tokio_util::codec::LengthDelimitedCodec;

    LengthDelimitedCodec::builder()
        .length_adjustment(-2)
        .new_read(io);

#### `pub fn num_skip(&mut self, val: usize) -> &mut Self` [src]

Sets the number of bytes to skip before reading the payload

Default value is `length_field_len + length_field_offset`

This configuration option only applies to decoding

# Examples

    use tokio_util::codec::LengthDelimitedCodec;

    LengthDelimitedCodec::builder()
        .num_skip(4)
        .new_read(io);

#### `pub fn new_codec(&self) -> LengthDelimitedCodec` [src]

Create a configured length delimited `LengthDelimitedCodec`

# Examples

    use tokio_util::codec::LengthDelimitedCodec;
    LengthDelimitedCodec::builder()
        .length_field_offset(0)
        .length_field_length(2)
        .length_adjustment(0)
        .num_skip(0)
        .new_codec();

#### `pub fn new_read<T>(&self, upstream: T) -> FramedRead<T, LengthDelimitedCodec> where
T: AsyncRead,` [src]

Create a configured length delimited `FramedRead`

# Examples

    use tokio_util::codec::LengthDelimitedCodec;

    LengthDelimitedCodec::builder()
        .length_field_offset(0)
        .length_field_length(2)
        .length_adjustment(0)
        .num_skip(0)
        .new_read(io);

#### `pub fn new_write<T>(&self, inner: T) -> FramedWrite<T, LengthDelimitedCodec> where
T: AsyncWrite,` [src]

Create a configured length delimited `FramedWrite`

# Examples

    LengthDelimitedCodec::builder()
        .length_field_length(2)
        .new_write(io);

#### `pub fn new_framed<T>(&self, inner: T) -> Framed<T, LengthDelimitedCodec> where
T: AsyncRead + AsyncWrite,` [src]

Create a configured length delimited `Framed`

# Examples

    LengthDelimitedCodec::builder()
        .length_field_length(2)
        .new_framed(io);

## Trait Implementations

### `impl Clone for Builder` [src]

#### `fn clone(&self) -> Builder` [src]

Returns a copy of the value. Read more

#### `pub fn clone_from(&mut self, source: &Self)`1.0.0 [src]

Performs copy-assignment from `source`. Read more

### `impl Copy for Builder` [src]

### `impl Debug for Builder` [src]

#### `fn fmt(&self, f: &mut Formatter<'_>) -> Result` [src]

Formats the value using the given formatter. Read more

### `impl Default for Builder` [src]

#### `fn default() -> Self` [src]

Returns the "default value" for a type. Read more

## Auto Trait Implementations

### `impl RefUnwindSafe for Builder` [src]

### `impl Send for Builder` [src]

### `impl Sync for Builder` [src]

### `impl Unpin for Builder` [src]

### `impl UnwindSafe for Builder` [src]

## Blanket Implementations

### `impl<T> Any for T where
T: 'static + ?Sized,` [src]

#### `pub fn type_id(&self) -> TypeId` [src]

Gets the `TypeId` of `self`. Read more

### `impl<T> Borrow<T> for T where
T: ?Sized,` [src]

#### `pub fn borrow(&self) -> &T` [src]

Immutably borrows from an owned value. Read more

### `impl<T> BorrowMut<T> for T where
T: ?Sized,` [src]

#### `pub fn borrow_mut(&mut self) -> &mut T` [src]

Mutably borrows from an owned value. Read more

### `impl<T> From<T> for T` [src]

#### `pub fn from(t: T) -> T` [src]

Performs the conversion.

### `impl<T, U> Into<U> for T where
U: From<T>,` [src]

#### `pub fn into(self) -> U` [src]

Performs the conversion.

### `impl<T> ToOwned for T where
T: Clone,` [src]

#### `type Owned = T`

The resulting type after obtaining ownership.

#### `pub fn to_owned(&self) -> T` [src]

Creates owned data from borrowed data, usually by cloning. Read more

#### `pub fn clone_into(&self, target: &mut T)` [src]

🔬 This is a nightly-only experimental API. (`toowned_clone_into`)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

### `impl<T, U> TryFrom<U> for T where
U: Into<T>,` [src]

#### `type Error = Infallible`

The type returned in the event of a conversion error.

#### `pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>` [src]

Performs the conversion.

### `impl<T, U> TryInto<U> for T where
U: TryFrom<T>,` [src]

#### `type Error = <U as TryFrom<T>>::Error`

The type returned in the event of a conversion error.

#### `pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>` [src]

Performs the conversion.