Skip to content

Commit

Permalink
Implement NetlinkPayloadRequest/Response for u8
Browse files Browse the repository at this point in the history
  • Loading branch information
gluxon committed May 2, 2022
1 parent 7995ef6 commit 5eac505
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions nldl/src/message/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ use super::utils::nla_get_string;
use super::utils::nla_get_u16;
use super::utils::nla_get_u32;
use super::utils::nla_get_u64;
use super::utils::nla_get_u8;
use super::utils::nla_put_string;
use super::utils::nla_put_u16;
use super::utils::nla_put_u32;
use super::utils::nla_put_u64;
use super::utils::nla_put_u8;
use super::utils::NlaGetStringError;
use super::utils::ParseNlaIntError;
use super::write_to_buf_with_prefixed_u32_len;
Expand Down Expand Up @@ -149,6 +151,12 @@ impl NetlinkPayloadRequest for () {
fn serialize(&self, _buf: &mut Vec<u8>) {}
}

impl NetlinkPayloadRequest for u8 {
fn serialize(&self, buf: &mut Vec<u8>) {
nla_put_u8(buf, *self);
}
}

impl NetlinkPayloadRequest for u16 {
fn serialize(&self, buf: &mut Vec<u8>) {
nla_put_u16(buf, *self);
Expand Down Expand Up @@ -202,6 +210,14 @@ impl NetlinkPayloadResponse for () {
}
}

impl NetlinkPayloadResponse for u8 {
type Error = ParseNlaIntError;

fn deserialize(buf: &[u8]) -> Result<Self, Self::Error> {
nla_get_u8(buf)
}
}

impl NetlinkPayloadResponse for u16 {
type Error = ParseNlaIntError;

Expand Down
1 change: 1 addition & 0 deletions nldl/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ macro_rules! create_nla_put_int {
};
}

create_nla_put_int!(nla_put_u8, u8);
create_nla_put_int!(nla_put_u16, u16);
create_nla_put_int!(nla_put_u32, u32);
create_nla_put_int!(nla_put_u64, u64);
Expand Down

0 comments on commit 5eac505

Please sign in to comment.