Skip to main content

PvaPacket

Struct PvaPacket 

Source
pub struct PvaPacket {
    pub header: PvaHeader,
    pub payload: Vec<u8>,
}

Fields§

§header: PvaHeader§payload: Vec<u8>

Implementations§

Source§

impl PvaPacket

Source

pub fn new(raw: &[u8]) -> Self

Examples found in repository?
examples/decode_packet.rs (line 16)
3fn main() {
4    // A minimal PVA Connection Validation packet (little-endian):
5    //   Header  (8 bytes): magic=0xCA, version=2, flags=0x00 (LE, app, client), command=1
6    //   Payload (9 bytes): buffer_size=16384(u32) + introspection_registry_size=0x7fff(u16) + qos=0(u16) + authz=""
7    let raw: &[u8] = &[
8        0xCA, 0x02, 0x00, 0x01, // header: magic, version, flags (LE), command 1
9        0x09, 0x00, 0x00, 0x00, // payload length = 9
10        0x00, 0x40, 0x00, 0x00, // buffer_size = 16384
11        0xFF, 0x7F, // introspection_registry_size = 32767
12        0x00, 0x00, // qos = 0
13        0x00, // authz = "" (empty string, size=0)
14    ];
15
16    let mut packet = PvaPacket::new(raw);
17
18    println!("Header:");
19    println!("  magic:   0x{:02X}", packet.header.magic);
20    println!("  version: {}", packet.header.version);
21    println!("  command: {}", packet.header.command);
22    println!("  payload: {} bytes", packet.header.payload_length);
23    println!("  endian:  {}", if packet.header.flags.is_msb { "big" } else { "little" });
24
25    if let Some(cmd) = packet.decode_payload() {
26        match cmd {
27            PvaPacketCommand::ConnectionValidation(cv) => {
28                println!("\nConnectionValidation:");
29                println!("  buffer_size:  {}", cv.buffer_size);
30                println!("  intro_reg:    {}", cv.introspection_registry_size);
31                println!("  qos:          {}", cv.qos);
32                println!("  authz:        {:?}", cv.authz);
33            }
34            other => println!("Decoded: {other:?}"),
35        }
36    } else {
37        eprintln!("Failed to decode payload");
38    }
39}
Source

pub fn decode_payload(&mut self) -> Option<PvaPacketCommand>

Examples found in repository?
examples/decode_packet.rs (line 25)
3fn main() {
4    // A minimal PVA Connection Validation packet (little-endian):
5    //   Header  (8 bytes): magic=0xCA, version=2, flags=0x00 (LE, app, client), command=1
6    //   Payload (9 bytes): buffer_size=16384(u32) + introspection_registry_size=0x7fff(u16) + qos=0(u16) + authz=""
7    let raw: &[u8] = &[
8        0xCA, 0x02, 0x00, 0x01, // header: magic, version, flags (LE), command 1
9        0x09, 0x00, 0x00, 0x00, // payload length = 9
10        0x00, 0x40, 0x00, 0x00, // buffer_size = 16384
11        0xFF, 0x7F, // introspection_registry_size = 32767
12        0x00, 0x00, // qos = 0
13        0x00, // authz = "" (empty string, size=0)
14    ];
15
16    let mut packet = PvaPacket::new(raw);
17
18    println!("Header:");
19    println!("  magic:   0x{:02X}", packet.header.magic);
20    println!("  version: {}", packet.header.version);
21    println!("  command: {}", packet.header.command);
22    println!("  payload: {} bytes", packet.header.payload_length);
23    println!("  endian:  {}", if packet.header.flags.is_msb { "big" } else { "little" });
24
25    if let Some(cmd) = packet.decode_payload() {
26        match cmd {
27            PvaPacketCommand::ConnectionValidation(cv) => {
28                println!("\nConnectionValidation:");
29                println!("  buffer_size:  {}", cv.buffer_size);
30                println!("  intro_reg:    {}", cv.introspection_registry_size);
31                println!("  qos:          {}", cv.qos);
32                println!("  authz:        {:?}", cv.authz);
33            }
34            other => println!("Decoded: {other:?}"),
35        }
36    } else {
37        eprintln!("Failed to decode payload");
38    }
39}
Source

pub fn is_valid(&self) -> bool

Trait Implementations§

Source§

impl Debug for PvaPacket

Source§

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

Formats the value using the given formatter. Read more

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

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more