Struct kwap_msg::alloc::Message [−][src]
pub struct Message {
pub id: Id,
pub ty: Type,
pub ver: Version,
pub tkl: TokenLength,
pub token: Token,
pub code: Code,
pub opts: Vec<Opt>,
pub payload: Payload,
}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::alloc::*;
use kwap_msg::no_alloc;
let packet: Vec<u8> = /* bytes! */
// Heap allocated version from `kwap_msg::alloc`
let msg = Message::try_from_bytes(packet.clone()).unwrap();
let mut opts_expected = /* create expected options */
let expected = Message {
id: Id(1),
ty: Type(0),
ver: Version(1),
token: Token(254),
tkl: TokenLength(1),
opts: opts_expected,
code: Code {class: 2, detail: 5},
payload: Payload(b"hello, world!".to_vec()),
};
assert_eq!(msg, expected);
// Stack allocated version from `kwap_msg::no_alloc`
// respective capacities are:
// - the size of the message payload buffer (13)
// - number of options (1)
// - size of option value buffers (16)
let msg = no_alloc::Message::<13, 1, 16>::try_from_bytes(packet).unwrap();
let mut opts_expected = /* create expected options */
let expected = no_alloc::Message::<13, 1, 16> {
id: Id(1),
ty: Type(0),
ver: Version(1),
token: Token(254),
tkl: TokenLength(1),
opts: opts_expected,
code: Code {class: 2, detail: 5},
payload: no_alloc::Payload(b"hello, world!".into_iter().copied().collect()),
};
assert_eq!(msg, expected);See RFC7252 - Message Details for context
Fields
id: Idsee Id for details
ty: Typesee Type for details
ver: Versionsee Version for details
tkl: TokenLengthsee TokenLength for details
token: Tokensee Token for details
code: Codesee Code for details
opts: Vec<Opt>see opt::Opt for details
payload: PayloadSee Payload
Trait Implementations
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
Auto Trait Implementations
impl RefUnwindSafe for Message
impl UnwindSafe for Message
Blanket Implementations
Mutably borrows from an owned value. Read more
