coap_message_implementations::option_extension

Function encode_extensions

Source
pub fn encode_extensions(delta: u16, length: u16) -> impl AsRef<[u8]>
Expand description

Encode delta and length into a small returned buffer

This function performs all of the option encoding steps except handling the actual data value.

ยงTypical use


let mut last_option = 11u16;
let mut buffer = heapless::Vec::<u8, 20>::new();

let option = 11u16;
let delta = option - last_option;
let last_option = option;
let data = b"core";

buffer.extend_from_slice(encode_extensions(
        delta,
        data.len().try_into().expect("Too long to express"),
        ).as_ref()).expect("Buffer too short");
buffer.extend_from_slice(data).expect("Buffer too short");

assert!(buffer == b"\x04core");