From 5eac505674a06d729c1b505fb4a9b1b1f9862ed8 Mon Sep 17 00:00:00 2001 From: Brandon Cheng Date: Mon, 2 May 2022 00:48:46 -0400 Subject: [PATCH] Implement NetlinkPayloadRequest/Response for u8 --- nldl/src/message/mod.rs | 16 ++++++++++++++++ nldl/src/utils.rs | 1 + 2 files changed, 17 insertions(+) diff --git a/nldl/src/message/mod.rs b/nldl/src/message/mod.rs index 907a3c2..5c686ec 100644 --- a/nldl/src/message/mod.rs +++ b/nldl/src/message/mod.rs @@ -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; @@ -149,6 +151,12 @@ impl NetlinkPayloadRequest for () { fn serialize(&self, _buf: &mut Vec) {} } +impl NetlinkPayloadRequest for u8 { + fn serialize(&self, buf: &mut Vec) { + nla_put_u8(buf, *self); + } +} + impl NetlinkPayloadRequest for u16 { fn serialize(&self, buf: &mut Vec) { nla_put_u16(buf, *self); @@ -202,6 +210,14 @@ impl NetlinkPayloadResponse for () { } } +impl NetlinkPayloadResponse for u8 { + type Error = ParseNlaIntError; + + fn deserialize(buf: &[u8]) -> Result { + nla_get_u8(buf) + } +} + impl NetlinkPayloadResponse for u16 { type Error = ParseNlaIntError; diff --git a/nldl/src/utils.rs b/nldl/src/utils.rs index f49839a..ae97bb6 100644 --- a/nldl/src/utils.rs +++ b/nldl/src/utils.rs @@ -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);