Skip to main content

encode_all

Function encode_all 

Source
pub fn encode_all(
    commands: &[MacCommand],
    out: &mut [u8],
) -> Result<usize, LorawanError>
Expand description

Writes a run of commands into one buffer.

§Arguments

  • commands - what to write, in the order they go out.
  • out - where to write them.

§Returns

How many bytes were written.

§Errors

LorawanError::PayloadTooLong when they do not fit, and whatever MacCommand::encode refuses.

§Examples

use pamoja_lorawan::mac::{encode_all, MacCommand, MacCommands, FOPTS_MAX};
use pamoja_lorawan::Direction;

// A device asks how well it is heard and what time it is, in one frame's options.
let asked = [MacCommand::LinkCheckReq, MacCommand::DeviceTimeReq];
let mut out = [0u8; FOPTS_MAX];
let written = encode_all(&asked, &mut out).unwrap();

let read: Vec<MacCommand> = MacCommands::new(Direction::Uplink, &out[..written])
    .map(|command| command.unwrap())
    .collect();
assert_eq!(read, asked);