Struct netlink_packet_generic::message::GenlMessage
source · [−]pub struct GenlMessage<F> {
pub header: GenlHeader,
pub payload: F,
/* private fields */
}
Expand description
Represent the generic netlink messages
This type can wrap data types F
which represents a generic family payload.
The message can be serialize/deserialize if the type F
implements GenlFamily
,
Emitable
, and ParseableParametrized<[u8], GenlHeader>
.
Fields
header: GenlHeader
payload: F
Implementations
sourceimpl<F> GenlMessage<F> where
F: Debug,
impl<F> GenlMessage<F> where
F: Debug,
sourcepub fn new(header: GenlHeader, payload: F, family_id: u16) -> Self
pub fn new(header: GenlHeader, payload: F, family_id: u16) -> Self
Construct the message
sourcepub fn from_parts(header: GenlHeader, payload: F) -> Self
pub fn from_parts(header: GenlHeader, payload: F) -> Self
Construct the message by the given header and payload
sourcepub fn into_parts(self) -> (GenlHeader, F)
pub fn into_parts(self) -> (GenlHeader, F)
Consume this message and return its header and payload
sourcepub fn resolved_family_id(&self) -> u16
pub fn resolved_family_id(&self) -> u16
Return the previously set resolved family ID in this message.
This value would be used to serialize the message only if
the (GenlFamily::family_id()
) return 0 in the underlying type.
sourcepub fn set_resolved_family_id(&mut self, family_id: u16)
pub fn set_resolved_family_id(&mut self, family_id: u16)
Set the resolved dynamic family ID of the message, if the generic family uses dynamic generated ID by kernel.
This method is a interface to provide other high level library to set the resolved family ID before the message is serialized.
Usage
Normally, you don’t have to call this function directly if you are using library which helps you handle the dynamic family id.
If you are the developer of some high level generic netlink library,
you can call this method to set the family id resolved by your resolver.
Without having to modify the message_type
field of the serialized
netlink packet header before sending it.
sourceimpl<F> GenlMessage<F> where
F: GenlFamily + Debug,
impl<F> GenlMessage<F> where
F: GenlFamily + Debug,
sourcepub fn from_payload(payload: F) -> Self
pub fn from_payload(payload: F) -> Self
Build the message from the payload
This function would automatically fill the header for you. You can directly emit
the message without having to call finalize()
.
sourcepub fn finalize(&mut self)
pub fn finalize(&mut self)
Ensure the header (GenlHeader
) is consistent with the payload (F: GenlFamily
):
- Fill the command and version number into the header
If you are not 100% sure the header is correct, this method should be called before calling
Emitable::emit()
, as it could get error result if the header is inconsistent with the message.
sourcepub fn family_id(&self) -> u16
pub fn family_id(&self) -> u16
Return the resolved family ID which should be filled into the message_type
field in NetlinkHeader
.
The implementation of NetlinkSerializable::message_type()
would use
this function’s result as its the return value. Thus, the family id can
be automatically filled into the message_type
during the call to
NetlinkMessage::finalize()
.
Trait Implementations
sourceimpl<F: Clone> Clone for GenlMessage<F>
impl<F: Clone> Clone for GenlMessage<F>
sourcefn clone(&self) -> GenlMessage<F>
fn clone(&self) -> GenlMessage<F>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<F: Debug> Debug for GenlMessage<F>
impl<F: Debug> Debug for GenlMessage<F>
sourceimpl<F> Emitable for GenlMessage<F> where
F: GenlFamily + Emitable + Debug,
impl<F> Emitable for GenlMessage<F> where
F: GenlFamily + Emitable + Debug,
sourceimpl<F> From<GenlMessage<F>> for NetlinkPayload<GenlMessage<F>> where
F: Debug,
impl<F> From<GenlMessage<F>> for NetlinkPayload<GenlMessage<F>> where
F: Debug,
sourcefn from(message: GenlMessage<F>) -> Self
fn from(message: GenlMessage<F>) -> Self
Converts to this type from the input type.
sourceimpl<F> NetlinkDeserializable for GenlMessage<F> where
F: ParseableParametrized<[u8], GenlHeader> + Debug,
impl<F> NetlinkDeserializable for GenlMessage<F> where
F: ParseableParametrized<[u8], GenlHeader> + Debug,
type Error = DecodeError
sourcefn deserialize(
header: &NetlinkHeader,
payload: &[u8]
) -> Result<Self, Self::Error>
fn deserialize(
header: &NetlinkHeader,
payload: &[u8]
) -> Result<Self, Self::Error>
Deserialize the given buffer into Self
.
sourceimpl<F> NetlinkSerializable for GenlMessage<F> where
F: GenlFamily + Emitable + Debug,
impl<F> NetlinkSerializable for GenlMessage<F> where
F: GenlFamily + Emitable + Debug,
fn message_type(&self) -> u16
sourcefn buffer_len(&self) -> usize
fn buffer_len(&self) -> usize
Return the length of the serialized data. Read more
sourcefn serialize(&self, buffer: &mut [u8])
fn serialize(&self, buffer: &mut [u8])
Serialize this types and write the serialized data into the given buffer.
buffer
’s length is exactly InnerMessage::buffer_len()
.
It means that if InnerMessage::buffer_len()
is buggy and does not return the appropriate length,
bad things can happen: Read more
sourceimpl<F> ParseableParametrized<[u8], u16> for GenlMessage<F> where
F: ParseableParametrized<[u8], GenlHeader> + Debug,
impl<F> ParseableParametrized<[u8], u16> for GenlMessage<F> where
F: ParseableParametrized<[u8], GenlHeader> + Debug,
sourcefn parse_with_param(buf: &[u8], message_type: u16) -> Result<Self, DecodeError>
fn parse_with_param(buf: &[u8], message_type: u16) -> Result<Self, DecodeError>
Deserialize the current type.
sourceimpl<'a, F, T> ParseableParametrized<GenlBuffer<&'a T>, u16> for GenlMessage<F> where
F: ParseableParametrized<[u8], GenlHeader> + Debug,
T: AsRef<[u8]> + ?Sized,
impl<'a, F, T> ParseableParametrized<GenlBuffer<&'a T>, u16> for GenlMessage<F> where
F: ParseableParametrized<[u8], GenlHeader> + Debug,
T: AsRef<[u8]> + ?Sized,
sourcefn parse_with_param(
buf: &GenlBuffer<&'a T>,
message_type: u16
) -> Result<Self, DecodeError>
fn parse_with_param(
buf: &GenlBuffer<&'a T>,
message_type: u16
) -> Result<Self, DecodeError>
Deserialize the current type.
sourceimpl<F: PartialEq> PartialEq<GenlMessage<F>> for GenlMessage<F>
impl<F: PartialEq> PartialEq<GenlMessage<F>> for GenlMessage<F>
sourcefn eq(&self, other: &GenlMessage<F>) -> bool
fn eq(&self, other: &GenlMessage<F>) -> bool
This method tests for self
and other
values to be equal, and is used
by ==
. Read more
sourcefn ne(&self, other: &GenlMessage<F>) -> bool
fn ne(&self, other: &GenlMessage<F>) -> bool
This method tests for !=
.
impl<F: Eq> Eq for GenlMessage<F>
impl<F> StructuralEq for GenlMessage<F>
impl<F> StructuralPartialEq for GenlMessage<F>
Auto Trait Implementations
impl<F> RefUnwindSafe for GenlMessage<F> where
F: RefUnwindSafe,
impl<F> Send for GenlMessage<F> where
F: Send,
impl<F> Sync for GenlMessage<F> where
F: Sync,
impl<F> Unpin for GenlMessage<F> where
F: Unpin,
impl<F> UnwindSafe for GenlMessage<F> where
F: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more