Struct netlink_packet_core::NetlinkMessage
source · #[non_exhaustive]pub struct NetlinkMessage<I> {
pub header: NetlinkHeader,
pub payload: NetlinkPayload<I>,
}
Expand description
Represent a netlink message.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. }
syntax; cannot be matched against without a wildcard ..
; and struct update syntax will not work.header: NetlinkHeader
Message header (this is common to all the netlink protocols)
payload: NetlinkPayload<I>
Inner message, which depends on the netlink protocol being used.
Implementations§
source§impl<I> NetlinkMessage<I>
impl<I> NetlinkMessage<I>
sourcepub fn new(header: NetlinkHeader, payload: NetlinkPayload<I>) -> Self
pub fn new(header: NetlinkHeader, payload: NetlinkPayload<I>) -> Self
Create a new netlink message from the given header and payload
sourcepub fn into_parts(self) -> (NetlinkHeader, NetlinkPayload<I>)
pub fn into_parts(self) -> (NetlinkHeader, NetlinkPayload<I>)
Consume this message and return its header and payload
source§impl<I> NetlinkMessage<I>where
I: NetlinkDeserializable,
impl<I> NetlinkMessage<I>where I: NetlinkDeserializable,
sourcepub fn deserialize(buffer: &[u8]) -> Result<Self, DecodeError>
pub fn deserialize(buffer: &[u8]) -> Result<Self, DecodeError>
Parse the given buffer as a netlink message
source§impl<I> NetlinkMessage<I>where
I: NetlinkSerializable,
impl<I> NetlinkMessage<I>where I: NetlinkSerializable,
sourcepub fn buffer_len(&self) -> usize
pub fn buffer_len(&self) -> usize
Return the length of this message in bytes
sourcepub fn serialize(&self, buffer: &mut [u8])
pub fn serialize(&self, buffer: &mut [u8])
Serialize this message and write the serialized data into the
given buffer. buffer
must big large enough for the whole
message to fit, otherwise, this method will panic. To know how
big the serialized message is, call buffer_len()
.
Panic
This method panics if the buffer is not big enough.
sourcepub fn finalize(&mut self)
pub fn finalize(&mut self)
Ensure the header (NetlinkHeader
) is consistent with the payload
(NetlinkPayload
):
- compute the payload length and set the header’s length field
- check the payload type and set the header’s message type field accordingly
If you are not 100% sure the header is correct, this method should be
called before calling Emitable::emit()
(trait.Emitable.html#
tymethod.emit), as it could panic if the header is inconsistent with
the rest of the message.
Trait Implementations§
source§impl<I: Clone> Clone for NetlinkMessage<I>
impl<I: Clone> Clone for NetlinkMessage<I>
source§fn clone(&self) -> NetlinkMessage<I>
fn clone(&self) -> NetlinkMessage<I>
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl<I: Debug> Debug for NetlinkMessage<I>
impl<I: Debug> Debug for NetlinkMessage<I>
source§impl<I> Emitable for NetlinkMessage<I>where
I: NetlinkSerializable,
impl<I> Emitable for NetlinkMessage<I>where I: NetlinkSerializable,
source§impl<T> From<T> for NetlinkMessage<T>where
T: Into<NetlinkPayload<T>>,
impl<T> From<T> for NetlinkMessage<T>where T: Into<NetlinkPayload<T>>,
source§impl<'buffer, B, I> Parseable<NetlinkBuffer<&'buffer B>> for NetlinkMessage<I>where
B: AsRef<[u8]> + 'buffer,
I: NetlinkDeserializable,
impl<'buffer, B, I> Parseable<NetlinkBuffer<&'buffer B>> for NetlinkMessage<I>where B: AsRef<[u8]> + 'buffer, I: NetlinkDeserializable,
source§fn parse(buf: &NetlinkBuffer<&'buffer B>) -> Result<Self, DecodeError>
fn parse(buf: &NetlinkBuffer<&'buffer B>) -> Result<Self, DecodeError>
source§impl<I: PartialEq> PartialEq<NetlinkMessage<I>> for NetlinkMessage<I>
impl<I: PartialEq> PartialEq<NetlinkMessage<I>> for NetlinkMessage<I>
source§fn eq(&self, other: &NetlinkMessage<I>) -> bool
fn eq(&self, other: &NetlinkMessage<I>) -> bool
self
and other
values to be equal, and is used
by ==
.