[−][src]Struct ieee802154::mac::frame::Header
MAC frame header
Fields
frame_type: FrameType
Frame Type
security: Security
Auxiliary Security header
frame_pending: bool
Frame Pending
ack_request: bool
Acknowledgement Request
pan_id_compress: bool
PAN ID Compress
version: FrameVersion
Frame version
destination: Address
Destination Address
source: Address
Source Address
seq: u8
Sequence Number
Methods
impl Header
[src]
pub fn decode(buf: &[u8]) -> Result<(Self, usize), DecodeError>
[src]
Decodes a header from a byte buffer
This method is used by Frame::decode
to decode the frame header.
Unless you decide to write your own code for decoding frames, there
should be no reason to call this method directly.
Errors
This function returns an error, if the bytes either don't encode a valid
IEEE 802.15.4 frame header, or encode a frame header that is not fully
supported by this implementation. Please refer to DecodeError
for
details.
Example
use ieee802154::mac::{ Address, ShortAddress, FrameType, Header, PanId, Security, }; // Construct a simple header. let bytes = [ 0x01, 0x98, // frame control 0x00, // sequence number 0x12, 0x34, 0x56, 0x78, // PAN identifier and address of destination 0x12, 0x34, 0x9a, 0xbc, // PAN identifier and address of source ]; let (header, num_bytes) = Header::decode(&bytes)?; assert_eq!(num_bytes, bytes.len()); assert_eq!(header.seq, 0x00); assert_eq!(header.frame_type, FrameType::Data); assert_eq!(header.security, Security::None); assert_eq!(header.frame_pending, false); assert_eq!(header.ack_request, false); assert_eq!(header.pan_id_compress, false); assert_eq!( header.destination, Address::Short(PanId(0x3412), ShortAddress(0x7856)) ); assert_eq!( header.source, Address::Short(PanId(0x3412), ShortAddress(0xbc9a)) );
pub fn encode(&self, buf: &mut [u8]) -> usize
[src]
Encodes the header into a buffer
Returns the number of bytes written to the buffer.
Panics
Panics, if the buffer is not long enough to hold the header. If you believe that this behavior is inappropriate, please leave your feedback on the issue tracker. Will also panic if the destination PAN identifier differs from the source PAN identifier when using PAN identifier compress.
The header length depends on the options chosen and varies between 3 and 30 octets.
Example
use ieee802154::mac::{ Address, ShortAddress, FrameType, FrameVersion, Header, PanId, Security, }; let header = Header { seq: 0x00, frame_type: FrameType::Data, security: Security::None, frame_pending: false, ack_request: false, pan_id_compress: false, version: FrameVersion::Ieee802154_2006, destination: Address::Short(PanId(0x1234), ShortAddress(0x5678)), source: Address::Short(PanId(0x1234), ShortAddress(0x9abc)), }; let mut bytes = [0u8; 11]; header.encode(&mut bytes); let expected_bytes = [ 0x01, 0x98, // frame control 0x00, // sequence number 0x34, 0x12, 0x78, 0x56, // PAN identifier and address of destination 0x34, 0x12, 0xbc, 0x9a, // PAN identifier and address of source ]; assert_eq!(bytes[..expected_bytes.len()], expected_bytes[..]);
Trait Implementations
impl PartialEq<Header> for Header
[src]
impl Eq for Header
[src]
impl Clone for Header
[src]
fn clone(&self) -> Header
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Header
[src]
impl Debug for Header
[src]
impl Hash for Header
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> TryFrom for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,