Trait coap_message::MinimalWritableMessage[][src]

pub trait MinimalWritableMessage {
    type Code: Code;
    type OptionNumber: OptionNumber;
    fn set_code(&mut self, code: Self::Code);
fn add_option(&mut self, number: Self::OptionNumber, value: &[u8]);
fn set_payload(&mut self, data: &[u8]); fn set_from_message<'m, M>(&mut self, msg: &'m M)
    where
        M: ReadableMessage<'m>
, { ... }
fn add_option_str(&mut self, number: Self::OptionNumber, value: &str) { ... }
fn add_option_uint<U: Ux>(&mut self, number: Self::OptionNumber, value: U) { ... } }

A message that needs to have its code, any options in ascending order and its payload set in that very sequence.

This is the bare minimum a message needs to provide to be populated as a request or response by a generic program; it is up to the program to ensure the valid sequence of operations, as failure to do so may incur panics (FIXME: or errors).

Associated Types

Loading content...

Required methods

fn set_code(&mut self, code: Self::Code)[src]

fn add_option(&mut self, number: Self::OptionNumber, value: &[u8])[src]

Add an option to the message

Calls to this method need to happen in ascending numeric sequence.

This works on option values as they are encoded in messages. Under the aspect of option value formats, this adds opaque options (but may just as well be used for adding options in another format when they are pre-encoded).

fn set_payload(&mut self, data: &[u8])[src]

Loading content...

Provided methods

fn set_from_message<'m, M>(&mut self, msg: &'m M) where
    M: ReadableMessage<'m>, 
[src]

Copy code, options and payload in from a readable message

Implementations can override this for cases where it can be done more efficiently than iterating over the options and appending them.

fn add_option_str(&mut self, number: Self::OptionNumber, value: &str)[src]

Shortcut for add_option(self, number, value.as_bytes()).

Implementations with type checked options can provide more efficient implementations (ie. ones that don't need to UTF-8-check when they feed the resulting bytes back into a string field), but must still accept string options via the generic add_option() method.

fn add_option_uint<U: Ux>(&mut self, number: Self::OptionNumber, value: U)[src]

Shortcut for add_option on a buffer containing the uint encoded value

Implementations with type checked options can provide more efficient implementations (ie. ones that don't need to decode the uint when reading it into a uint field), but must still accept integer options via the generic add_option() method.

While the trait under U is hidden (pending the use of a more generic one num-types based one), own implementations are not possible.

Loading content...

Implementors

impl MinimalWritableMessage for HeapMessage[src]

type Code = u8

type OptionNumber = u16

Loading content...