Opt

Struct Opt 

Source
pub struct Opt<C: Array<Item = u8>> {
    pub delta: OptDelta,
    pub value: OptValue<C>,
}
Expand description

§Options

generated from RFC7252 section 5.4

Both requests and responses may include a list of one or more options. For example, the URI in a request is transported in several options, and metadata that would be carried in an HTTP header in HTTP is supplied as options as well.

CoAP defines a single set of options that are used in both requests and responses:

o Content-Format

o ETag

o Location-Path

o Location-Query

o Max-Age

o Proxy-Uri

o Proxy-Scheme

o Uri-Host

o Uri-Path

o Uri-Port

o Uri-Query

o Accept

o If-Match

o If-None-Match

o Size1

The semantics of these options along with their properties are defined in detail in Section 5.10.

Not all options are defined for use with all methods and Response Codes. The possible options for methods and Response Codes are defined in Sections 5.8 and 5.9, respectively. In case an option is not defined for a Method or Response Code, it MUST NOT be included by a sender and MUST be treated like an unrecognized option by a recipient.

RFC7252 Section 3.1 Option binary format ## Option Format [_generated from RFC7252 section 3.1_](https://datatracker.ietf.org/doc/html/rfc7252#section-3.1)

CoAP defines a number of options that can be included in a message. Each option instance in a message specifies the Option Number of the defined CoAP option, the length of the Option Value, and the Option Value itself.

Instead of specifying the Option Number directly, the instances MUST appear in order of their Option Numbers and a delta encoding is used between them: the Option Number for each instance is calculated as the sum of its delta and the Option Number of the preceding instance in the message. For the first instance in a message, a preceding option instance with Option Number zero is assumed. Multiple instances of the same option can be included by using a delta of zero.

Option Numbers are maintained in the “CoAP Option Numbers” registry (Section 12.2). See Section 5.4 for the semantics of the options defined in this document.

  0   1   2   3   4   5   6   7
+---------------+---------------+
|               |               |
|  Option Delta | Option Length |   1 byte
|               |               |
+---------------+---------------+
\                               \
/         Option Delta          /   0-2 bytes
\          (extended)           \
+-------------------------------+
\                               \
/         Option Length         /   0-2 bytes
\          (extended)           \
+-------------------------------+
\                               \
/                               /
\                               \
/         Option Value          /   0 or more bytes
\                               \
/                               /
\                               \
+-------------------------------+

                       Figure 8: Option Format

The fields in an option are defined as follows:

Option Delta: 4-bit unsigned integer. A value between 0 and 12 indicates the Option Delta. Three values are reserved for special constructs:

13: An 8-bit unsigned integer follows the initial byte and indicates the Option Delta minus 13.

14: A 16-bit unsigned integer in network byte order follows the initial byte and indicates the Option Delta minus 269.

15: Reserved for the Payload Marker. If the field is set to this value but the entire byte is not the payload marker, this MUST be processed as a message format error.

The resulting Option Delta is used as the difference between the Option Number of this option and that of the previous option (or zero for the first option). In other words, the Option Number is calculated by simply summing the Option Delta values of this and all previous options before it.

Option Length: 4-bit unsigned integer. A value between 0 and 12 indicates the length of the Option Value, in bytes. Three values are reserved for special constructs:

13: An 8-bit unsigned integer precedes the Option Value and indicates the Option Length minus 13.

14: A 16-bit unsigned integer in network byte order precedes the Option Value and indicates the Option Length minus 269.

15: Reserved for future use. If the field is set to this value, it MUST be processed as a message format error.

Value: A sequence of exactly Option Length bytes. The length and format of the Option Value depend on the respective option, which MAY define variable-length values. See Section 3.2 for the formats used in this document; options defined in other documents MAY make use of other option value formats.

§Opt struct

Low-level representation of a freshly parsed CoAP Option

§Option Numbers

This struct just stores data parsed directly from the message on the wire, and does not compute or store the Option Number.

To get OptNumbers, you can use the iterator extension EnumerateOptNumbers on a collection of Opts.

Fields§

§delta: OptDelta§value: OptValue<C>

Implementations§

Source§

impl<C: Array<Item = u8>> Opt<C>

Source

pub fn extend_bytes(self, bytes: &mut impl Extend<u8>)

Given a collection to Extend and an Opt, add that Opt’s bytes to the collection.

Trait Implementations§

Source§

impl<C: Clone + Array<Item = u8>> Clone for Opt<C>

Source§

fn clone(&self) -> Opt<C>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<C: Debug + Array<Item = u8>> Debug for Opt<C>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<C: Default + Array<Item = u8>> Default for Opt<C>

Source§

fn default() -> Opt<C>

Returns the “default value” for a type. Read more
Source§

impl<C: Array<Item = u8>> GetSize for Opt<C>

Source§

fn get_size(&self) -> usize

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

fn max_size(&self) -> Option<usize>

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

fn size_is_zero(&self) -> bool

Check if the runtime size is zero Read more
Source§

fn is_full(&self) -> bool

Is there no room left in this collection? Read more
Source§

impl<C: PartialEq + Array<Item = u8>> PartialEq for Opt<C>

Source§

fn eq(&self, other: &Opt<C>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<C: PartialOrd + Array<Item = u8>> PartialOrd for Opt<C>

Source§

fn partial_cmp(&self, other: &Opt<C>) -> Option<Ordering>

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

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<C: Array<Item = u8>> StructuralPartialEq for Opt<C>

Auto Trait Implementations§

§

impl<C> Freeze for Opt<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for Opt<C>
where C: RefUnwindSafe,

§

impl<C> Send for Opt<C>
where C: Send,

§

impl<C> Sync for Opt<C>
where C: Sync,

§

impl<C> Unpin for Opt<C>
where C: Unpin,

§

impl<C> UnwindSafe for Opt<C>
where C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<'a, C, I> EnumerateOptNumbers<&'a Opt<C>> for I
where C: Array<Item = u8>, I: Iterator<Item = &'a Opt<C>>,

Source§

fn enumerate_option_numbers(self) -> EnumerateOptNumbersIter<&'a Opt<C>, I>

Creates an iterator which gives the current Opt along with its Number. Read more
Source§

impl<C, I> EnumerateOptNumbers<Opt<C>> for I
where C: Array<Item = u8>, I: Iterator<Item = Opt<C>>,

Source§

fn enumerate_option_numbers(self) -> EnumerateOptNumbersIter<Opt<C>, I>

Creates an iterator which gives the current Opt along with its Number. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.