pub fn decode(datagram: &[u8]) -> Result<Bvll<'_>, BvllError>Expand description
Decode one datagram as a BVLL message: BvllFrame::decode, then
BvllFrame::message.
use core::net::{Ipv4Addr, SocketAddrV4};
use bacnet_bip_codec::{decode, Bvll, BvllError};
// A Forwarded-NPDU from 192.168.1.20:47808 carrying the NPDU 01 00.
let wire = [0x81, 0x04, 0x00, 0x0C, 192, 168, 1, 20, 0xBA, 0xC0, 0x01, 0x00];
assert_eq!(
decode(&wire)?,
Bvll::ForwardedNpdu {
origin: SocketAddrV4::new(Ipv4Addr::new(192, 168, 1, 20), 47808),
npdu: &[0x01, 0x00],
},
);
// A Register-Foreign-Device needs exactly a 2-octet time-to-live.
assert!(matches!(
decode(&[0x81, 0x05, 0x00, 0x05, 0x3C]),
Err(BvllError::PayloadLength { length: 1, .. }),
));