pub enum Bvll<'a> {
BvlcResult(BvlcResultCode),
WriteBroadcastDistributionTable(BdtEntries<'a>),
ReadBroadcastDistributionTable,
ReadBroadcastDistributionTableAck(BdtEntries<'a>),
ForwardedNpdu {
origin: SocketAddrV4,
npdu: &'a [u8],
},
RegisterForeignDevice {
ttl: u16,
},
ReadForeignDeviceTable,
ReadForeignDeviceTableAck(FdtEntries<'a>),
DeleteForeignDeviceTableEntry(SocketAddrV4),
DistributeBroadcastToNetwork(&'a [u8]),
OriginalUnicastNpdu(&'a [u8]),
OriginalBroadcastNpdu(&'a [u8]),
}Expand description
One B/IP BVLL message (Annex J.2), borrowing its NPDU or table.
decode produces one from a datagram, and
encode_into or
encode_to_sink writes one. Each variant holds
what its function’s format clause lays out after the header.
Variants§
BvlcResult(BvlcResultCode)
BVLC-Result (J.2.1).
WriteBroadcastDistributionTable(BdtEntries<'a>)
Write-Broadcast-Distribution-Table (J.2.2).
ReadBroadcastDistributionTable
Read-Broadcast-Distribution-Table (J.2.3).
ReadBroadcastDistributionTableAck(BdtEntries<'a>)
Read-Broadcast-Distribution-Table-Ack (J.2.4).
ForwardedNpdu
Forwarded-NPDU (J.2.5).
Fields
origin: SocketAddrV4Where the NPDU started: its originator’s B/IP address. A receiver takes it as the NPDU’s source when it differs from the sender’s address (J.2.5).
RegisterForeignDevice
Register-Foreign-Device (J.2.6).
ReadForeignDeviceTable
Read-Foreign-Device-Table (J.2.7).
ReadForeignDeviceTableAck(FdtEntries<'a>)
Read-Foreign-Device-Table-Ack (J.2.8).
DeleteForeignDeviceTableEntry(SocketAddrV4)
Delete-Foreign-Device-Table-Entry (J.2.9), naming the entry’s B/IP address.
DistributeBroadcastToNetwork(&'a [u8])
Distribute-Broadcast-To-Network (J.2.10), carrying an NPDU.
OriginalUnicastNpdu(&'a [u8])
Original-Unicast-NPDU (J.2.11), carrying an NPDU.
OriginalBroadcastNpdu(&'a [u8])
Original-Broadcast-NPDU (J.2.12), carrying an NPDU.
Implementations§
Source§impl<'a> Bvll<'a>
impl<'a> Bvll<'a>
Sourcepub const fn function(&self) -> BvlcFunction
pub const fn function(&self) -> BvlcFunction
The message’s function code.
Sourcepub const fn origin(&self) -> Option<SocketAddrV4>
pub const fn origin(&self) -> Option<SocketAddrV4>
A Forwarded-NPDU’s originating address.
Sourcepub fn encoded_len(&self) -> Result<usize, BvllError>
pub fn encoded_len(&self) -> Result<usize, BvllError>
Check the message and return its wire length, header included.
Encoding refuses two things: a message too long for the 16-bit Length
field (BvllError::TooLong), and a BVLC-Result whose code Annex
J.2.1.1 doesn’t define (BvllError::UndefinedResultCode). Every
other shape the standard forbids can’t be built: each variant holds
exactly its function’s fields.
Sourcepub fn encode_into(&self, output: &mut [u8]) -> Result<usize, BvllError>
pub fn encode_into(&self, output: &mut [u8]) -> Result<usize, BvllError>
Encode the message at the start of output and return its wire
length. Nothing is written unless it passes the checks of
Bvll::encoded_len and fits.
use bacnet_bip_codec::{Bvll, BvlcResultCode, BvllError};
let mut wire = [0u8; 6];
let nak = Bvll::BvlcResult(BvlcResultCode::REGISTER_FOREIGN_DEVICE_NAK);
assert_eq!(nak.encode_into(&mut wire)?, 6);
assert_eq!(wire, [0x81, 0x00, 0x00, 0x06, 0x00, 0x30]);
// 0x0070 is not a result code Annex J defines.
assert_eq!(
Bvll::BvlcResult(BvlcResultCode::from_raw(0x0070)).encode_into(&mut wire),
Err(BvllError::UndefinedResultCode { code: 0x0070 }),
);Sourcepub fn encode_to_sink<S: BvllSink + ?Sized>(
&self,
sink: &mut S,
) -> Result<usize, BvllError>
pub fn encode_to_sink<S: BvllSink + ?Sized>( &self, sink: &mut S, ) -> Result<usize, BvllError>
Encode the message into sink and return its wire length.
The checks are those of Bvll::encoded_len. When the sink reports
a fixed capacity, a message that does not fit fails before anything
is written. A growable sink is written directly, so if one of its
writes fails, the octets written before it stay in the sink; see
BvllSink.