Function coap_message_utils::option_extension::push_extensions[][src]

pub fn push_extensions(target: &mut impl Extend<u8>, value: u16) -> u8
👎 Deprecated since 0.0.2:

Use encode_extensions again

Write an extended option delta or length value into a vector.

The resulting nibble then needs to be shifted and stored in the respective half the previously pushed value.

While this can be used to push the extension data into a heapless::Vec, beware that heapless indicates its error condition by panicking. Before calling push_extensions on such a target, the caller may want to check whether 2 more bytes (the maximum this function appends) are still free.

Typical use

let mut options = Vec::new();

let delta = 11;
let length = 14;

let nibbles_index = options.len();
options.push(0);
let delta = push_extensions(&mut options, delta);
let length = push_extensions(&mut options, length);
options[nibbles_index] = (delta << 4) | length;

assert!(options == b"\xbd\x01");

Deprecation

Using this is needlessly complex; use encode_extensions instead and rely on the compiler to see through the stack allocation and put the data right into place.