netlink_packet_generic::message

Struct 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§

Source§

impl<F> GenlMessage<F>
where F: Debug,

Source

pub fn new(header: GenlHeader, payload: F, family_id: u16) -> Self

Construct the message

Source

pub fn from_parts(header: GenlHeader, payload: F) -> Self

Construct the message by the given header and payload

Source

pub fn into_parts(self) -> (GenlHeader, F)

Consume this message and return its header and payload

Source

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.

Source

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.

Source§

impl<F> GenlMessage<F>
where F: GenlFamily + Debug,

Source

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

Source

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.

Source

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§

Source§

impl<F: Clone> Clone for GenlMessage<F>

Source§

fn clone(&self) -> GenlMessage<F>

Returns a copy of the value. Read more
1.0.0 · Source§

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

Performs copy-assignment from source. Read more
Source§

impl<F: Debug> Debug for GenlMessage<F>

Source§

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

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

impl<F> Emitable for GenlMessage<F>
where F: GenlFamily + Emitable + Debug,

Source§

fn buffer_len(&self) -> usize

Return the length of the serialized data.
Source§

fn emit(&self, buffer: &mut [u8])

Serialize this types and write the serialized data into the given buffer. Read more
Source§

impl<F> From<GenlMessage<F>> for NetlinkPayload<GenlMessage<F>>
where F: Debug,

Source§

fn from(message: GenlMessage<F>) -> Self

Converts to this type from the input type.
Source§

impl<F> NetlinkDeserializable for GenlMessage<F>
where F: ParseableParametrized<[u8], GenlHeader> + Debug, F::Error: Into<DecodeError>,

Source§

type Error = DecodeError

Source§

fn deserialize( header: &NetlinkHeader, payload: &[u8], ) -> Result<Self, Self::Error>

Deserialize the given buffer into Self.
Source§

impl<F> NetlinkSerializable for GenlMessage<F>
where F: GenlFamily + Emitable + Debug,

Source§

fn message_type(&self) -> u16

Source§

fn buffer_len(&self) -> usize

Return the length of the serialized data. Read more
Source§

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

impl<'a, F, T> ParseableParametrized<GenlBuffer<&'a T>, u16> for GenlMessage<F>
where F: ParseableParametrized<[u8], GenlHeader> + Debug, T: AsRef<[u8]> + ?Sized, F::Error: Into<DecodeError>,

Source§

type Error = DecodeError

Source§

fn parse_with_param( buf: &GenlBuffer<&'a T>, message_type: u16, ) -> Result<Self, DecodeError>

Deserialize the current type.
Source§

impl<F: PartialEq> PartialEq for GenlMessage<F>

Source§

fn eq(&self, other: &GenlMessage<F>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<F: Eq> Eq for GenlMessage<F>

Source§

impl<F> StructuralPartialEq for GenlMessage<F>

Auto Trait Implementations§

§

impl<F> Freeze for GenlMessage<F>
where F: Freeze,

§

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§

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, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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 = 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.