Skip to main content

Bvll

Enum Bvll 

Source
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: SocketAddrV4

Where 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).

§npdu: &'a [u8]

The NPDU.

§

RegisterForeignDevice

Register-Foreign-Device (J.2.6).

Fields

§ttl: u16

Seconds within which the device will register again.

§

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>

Source

pub const fn function(&self) -> BvlcFunction

The message’s function code.

Source

pub const fn npdu(&self) -> Option<&'a [u8]>

The NPDU, for the four functions that carry one.

Source

pub const fn origin(&self) -> Option<SocketAddrV4>

A Forwarded-NPDU’s originating address.

Source

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.

Source

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 }),
);
Source

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.

Trait Implementations§

Source§

impl<'a> Clone for Bvll<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for Bvll<'a>

Source§

impl<'a> Debug for Bvll<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for Bvll<'a>

Source§

impl<'a> PartialEq for Bvll<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for Bvll<'a>

Auto Trait Implementations§

§

impl<'a> Freeze for Bvll<'a>

§

impl<'a> RefUnwindSafe for Bvll<'a>

§

impl<'a> Send for Bvll<'a>

§

impl<'a> Sync for Bvll<'a>

§

impl<'a> Unpin for Bvll<'a>

§

impl<'a> UnsafeUnpin for Bvll<'a>

§

impl<'a> UnwindSafe for Bvll<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.