Skip to main content

KeyFrame

Struct KeyFrame 

Source
pub struct KeyFrame {
    pub id: DataSetId,
    pub sequence: u16,
    pub fields: Vec<Field>,
}
Expand description

Complete key frame. Field order follows the publisher’s configured dataset.

Fields§

§id: DataSetId

Routing identifiers to match against the subscriber configuration.

§sequence: u16

DataSetMessage sequence, incremented modulo 65536 by the publisher.

§fields: Vec<Field>

One to MAX_FIELDS scalar values in the agreed field order.

Implementations§

Source§

impl KeyFrame

Source

pub fn encode(&self) -> Result<Vec<u8>, FrameError>

Encode header and fields as a single UADP NetworkMessage.

Examples found in repository?
examples/uadp.rs (line 31)
11fn main() -> Result<(), Box<dyn Error>> {
12    let arg = std::env::args()
13        .nth(1)
14        .ok_or("expected loopback UDP peer port")?;
15    let port: NonZeroU16 = arg.parse()?;
16    let peer = SocketAddrV4::new(Ipv4Addr::LOCALHOST, port.get());
17    let socket = UdpSocket::bind((Ipv4Addr::LOCALHOST, 0))?;
18    socket.connect(peer)?;
19    socket.set_read_timeout(Some(Duration::from_secs(3)))?;
20
21    let id = DataSetId {
22        publisher: NonZeroU16::new(12).unwrap(),
23        writer_group: NonZeroU16::new(34).unwrap(),
24        writer: NonZeroU16::new(56).unwrap(),
25    };
26    let reading = KeyFrame {
27        id,
28        sequence: u16::MAX,
29        fields: vec![Field::UInt64(9_007_199_254_740_993), Field::Boolean(true)],
30    };
31    socket.send(&reading.encode()?)?;
32    // A buffer larger than the accepted wire maximum also distinguishes oversized datagrams.
33    let mut bytes = [0_u8; 1024];
34    let count = socket.recv(&mut bytes)?;
35    let reply = KeyFrame::decode(&bytes[..count])?;
36    if reply.id != id || reply.sequence != reading.sequence.wrapping_add(1) {
37        return Err("unexpected dataset identity or sequence".into());
38    }
39    let [Field::UInt64(total), Field::Boolean(running)] = reply.fields.as_slice() else {
40        return Err("unexpected field layout".into());
41    };
42    println!("parts={total} running={running}");
43    Ok(())
44}
Source

pub fn decode(input: &[u8]) -> Result<Self, FrameError>

Decode a complete datagram. Unsupported flags, signed messages, unknown types, truncated fields and trailing data fail as a whole.

Examples found in repository?
examples/uadp.rs (line 35)
11fn main() -> Result<(), Box<dyn Error>> {
12    let arg = std::env::args()
13        .nth(1)
14        .ok_or("expected loopback UDP peer port")?;
15    let port: NonZeroU16 = arg.parse()?;
16    let peer = SocketAddrV4::new(Ipv4Addr::LOCALHOST, port.get());
17    let socket = UdpSocket::bind((Ipv4Addr::LOCALHOST, 0))?;
18    socket.connect(peer)?;
19    socket.set_read_timeout(Some(Duration::from_secs(3)))?;
20
21    let id = DataSetId {
22        publisher: NonZeroU16::new(12).unwrap(),
23        writer_group: NonZeroU16::new(34).unwrap(),
24        writer: NonZeroU16::new(56).unwrap(),
25    };
26    let reading = KeyFrame {
27        id,
28        sequence: u16::MAX,
29        fields: vec![Field::UInt64(9_007_199_254_740_993), Field::Boolean(true)],
30    };
31    socket.send(&reading.encode()?)?;
32    // A buffer larger than the accepted wire maximum also distinguishes oversized datagrams.
33    let mut bytes = [0_u8; 1024];
34    let count = socket.recv(&mut bytes)?;
35    let reply = KeyFrame::decode(&bytes[..count])?;
36    if reply.id != id || reply.sequence != reading.sequence.wrapping_add(1) {
37        return Err("unexpected dataset identity or sequence".into());
38    }
39    let [Field::UInt64(total), Field::Boolean(running)] = reply.fields.as_slice() else {
40        return Err("unexpected field layout".into());
41    };
42    println!("parts={total} running={running}");
43    Ok(())
44}

Trait Implementations§

Source§

impl Clone for KeyFrame

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 Debug for KeyFrame

Source§

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

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

impl PartialEq for KeyFrame

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 StructuralPartialEq for KeyFrame

Auto Trait Implementations§

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Same for T

Source§

type Output = T

Should always be Self
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.