Function coap_message_utils::option_extension::take_extension[][src]

pub fn take_extension(
    value: &mut u16,
    slice: &mut &[u8]
) -> Result<(), ExtensionError>

Decode an extended value.

Given a value that was initially extracted from an Option Delta or Option Length nibble of an option, read up to 2 extended bytes from the slice that contains the remaining data, and advance the slice by that amount.

This returns Some(()) on success, or None to indicate any error condition (which may be exhaustion of the slice, the presence of the value 15, or an overflow induced by an almost-maximum value in the 2-byte extension

Typical use

let data = b"\xbd\x01long-path-name\xff";

let nibble = data[0];
let mut delta = (nibble >> 4).into();
let mut length = (nibble & 0x0f).into();

let mut view = &data[1..];
// Delta is 11; this does not modify anything
take_extension(&mut delta, &mut view).unwrap();
// Length is 13 + 1; this takes one byte off view
take_extension(&mut length, &mut view).unwrap();

assert!(delta == 11);
assert!(length == 14);
assert!(&view[..14] == b"long-path-name");