pub struct FrameHeader { /* private fields */ }Expand description
A frame read only as far as its unencrypted header.
§Examples
use pamoja_lorawan::{FrameHeader, MessageType, Session, Uplink};
let session = Session::new(0x2601_1BDA, [0x2B; 16], [0x99; 16]);
let frame = session.encode_uplink(&Uplink::new(42, 1, b"temp=4.8"))?;
// A gateway reads the address out of the frame to find the right session.
let header = FrameHeader::parse(frame.as_bytes())?;
assert_eq!(header.message_type(), MessageType::UnconfirmedUp);
assert_eq!(header.dev_addr(), Some(0x2601_1BDA));
assert_eq!(header.fcnt(), Some(42));
assert_eq!(header.fport(), Some(1));
// Only then can it verify and decrypt.
let rx = session.decode(frame.as_bytes(), 42)?;
assert_eq!(rx.payload(), b"temp=4.8");Implementations§
Source§impl FrameHeader
impl FrameHeader
Sourcepub fn parse(bytes: &[u8]) -> Result<FrameHeader, LorawanError>
pub fn parse(bytes: &[u8]) -> Result<FrameHeader, LorawanError>
Reads a frame far enough to route it, without any key.
§Arguments
bytes- the raw frame as it came off the radio.
§Returns
What the header says the frame is.
§Errors
Returns LorawanError::FrameTooShort if the frame is empty or shorter than the
header and MIC a data frame needs, LorawanError::UnsupportedMType if the message
type is one this crate does not read, or LorawanError::MalformedFrame if the
frame options run past the end of the frame.
Sourcepub fn message_type(&self) -> MessageType
pub fn message_type(&self) -> MessageType
Sourcepub fn payload_len(&self) -> usize
pub fn payload_len(&self) -> usize
Returns the length of the still-encrypted payload.
§Returns
The payload length in bytes, which is 0 when the frame carries only options.
Trait Implementations§
Source§impl Clone for FrameHeader
impl Clone for FrameHeader
Source§fn clone(&self) -> FrameHeader
fn clone(&self) -> FrameHeader
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for FrameHeader
Source§impl Debug for FrameHeader
impl Debug for FrameHeader
impl Eq for FrameHeader
Source§impl PartialEq for FrameHeader
impl PartialEq for FrameHeader
impl StructuralPartialEq for FrameHeader
Auto Trait Implementations§
impl Freeze for FrameHeader
impl RefUnwindSafe for FrameHeader
impl Send for FrameHeader
impl Sync for FrameHeader
impl Unpin for FrameHeader
impl UnsafeUnpin for FrameHeader
impl UnwindSafe for FrameHeader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more