Struct kwap_msg::Message[][src]

pub struct Message<PayloadC: Collection<u8>, OptC: Collection<u8> + 'static, Opts: Collection<Opt<OptC>>> where
    for<'a> &'a PayloadC: IntoIterator<Item = &'a u8>,
    for<'a> &'a OptC: IntoIterator<Item = &'a u8>,
    for<'a> &'a Opts: IntoIterator<Item = &'a Opt<OptC>>, 
{ pub id: Id, pub ty: Type, pub ver: Version, pub token: Token, pub code: Code, pub opts: Opts, pub payload: Payload<PayloadC>, pub __optc: PhantomData<OptC>, }
Expand description

Low-level representation of a message that has been parsed from a byte array

To convert an iterator of bytes into a Message, there is a provided trait crate::TryFromBytes.

use kwap_msg::TryFromBytes;
use kwap_msg::*;
let packet: Vec<u8> = /* bytes! */

// `VecMessage` uses `Vec` as the backing structure for byte buffers
let msg = VecMessage::try_from_bytes(packet.clone()).unwrap();
let mut opts_expected = /* create expected options */

let expected = VecMessage {
  id: Id(1),
  ty: Type(0),
  ver: Version(1),
  token: Token(tinyvec::array_vec!([u8; 8] => 254)),
  opts: opts_expected,
  code: Code {class: 2, detail: 5},
  payload: Payload(b"hello, world!".to_vec()),
  __optc: Default::default(),
};

assert_eq!(msg, expected);

See RFC7252 - Message Details for context

Fields

id: Id

see Id for details

ty: Type

see Type for details

ver: Version

see Version for details

token: Token

see Token for details

code: Code

see Code for details

opts: Opts

see opt::Opt for details

payload: Payload<PayloadC>

see Payload

__optc: PhantomData<OptC>

empty field using the Opt internal byte collection type

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

Get the runtime size (in bytes) of a struct Read more

Get the max size that this data structure can acommodate. Read more

Check if the runtime size is zero Read more

Is there no room left in this collection?

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

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Error type yielded if conversion fails

Try to convert from some sequence of bytes T into Self Read more

Error type yielded if conversion fails

Try to convert from some sequence of bytes T into Self Read more

Try to convert into a collection of bytes Read more

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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

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

Uses borrowed data to replace owned data, usually by cloning. 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.