riot_wrappers/coap_message/
mod.rsmod impl_0_3;
use crate::gcoap::{PacketBuffer, PacketBufferOptIter};
pub struct MessageOption<'a> {
number: u16,
value: &'a [u8],
}
pub struct OptionsIterator<'a, 'b>(PacketBufferOptIter<'a, 'b>);
impl<'a, 'b> Iterator for OptionsIterator<'a, 'b> {
type Item = MessageOption<'a>;
fn next(&mut self) -> Option<Self::Item> {
let (opt_num, slice) = self.0.next()?;
Some(MessageOption {
number: opt_num,
value: slice,
})
}
}
pub struct ResponseMessage<'b> {
message: PacketBuffer<'b>,
payload_written: Option<usize>,
}
impl<'b> ResponseMessage<'b> {
pub fn new(mut buf: PacketBuffer<'b>) -> Self {
buf.resp_init(5 << 5).unwrap();
ResponseMessage {
message: buf,
payload_written: None,
}
}
pub(crate) fn rewind(&mut self) {
self.message.resp_init(5 << 5).unwrap();
}
pub fn finish(&self) -> isize {
self.message.get_length(match self.payload_written {
None => 0,
Some(x) => x + 1,
}) as isize
}
}