Struct ppp::v2::Header

source · []
pub struct Header<'a> {
    pub header: Cow<'a, [u8]>,
    pub version: Version,
    pub command: Command,
    pub protocol: Protocol,
    pub addresses: Addresses,
}
Expand description

A proxy protocol version 2 header.

Examples

use ppp::v2::{Addresses, AddressFamily, Command, Header, IPv4, ParseError, Protocol, PROTOCOL_PREFIX, Type, TypeLengthValue, Version};
let mut header = Vec::from(PROTOCOL_PREFIX);
header.extend([
   0x21, 0x12, 0, 16, 127, 0, 0, 1, 192, 168, 1, 1, 0, 80, 1, 187, 4, 0, 1, 42
]);

let addresses: Addresses = IPv4::new([127, 0, 0, 1], [192, 168, 1, 1], 80, 443).into();
let expected = Header {
   header: header.as_slice().into(),
   version: Version::Two,
   command: Command::Proxy,
   protocol: Protocol::Datagram,
   addresses
};
let actual = Header::try_from(header.as_slice()).unwrap();

assert_eq!(actual, expected);
assert_eq!(actual.tlvs().collect::<Vec<Result<TypeLengthValue<'_>, ParseError>>>(), vec![Ok(TypeLengthValue::new(Type::NoOp, &[42]))]);

Fields

header: Cow<'a, [u8]>version: Versioncommand: Commandprotocol: Protocoladdresses: Addresses

Implementations

Creates an owned clone of this Header.

The length of this Header’s payload in bytes.

The total length of this Header in bytes.

Tests whether this Header’s underlying byte slice is empty.

The AddressFamily of this Header.

The bytes of the address portion of the payload.

The bytes of the TypeLengthValue portion of the payload.

An Iterator of TypeLengthValues.

The underlying byte slice this Header is built on.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

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

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.