netlink: Add common function for extracting payload
Change-Id: I809bd17d50ccb8a8f624b6117c088193f55e79de
Signed-off-by: William A. Kennington III <wak@google.com>
diff --git a/src/netlink.hpp b/src/netlink.hpp
index 1260f8e..754b4b4 100644
--- a/src/netlink.hpp
+++ b/src/netlink.hpp
@@ -3,6 +3,7 @@
#include <linux/rtnetlink.h>
#include <function2/function2.hpp>
+#include <stdplus/raw.hpp>
#include <string_view>
#include <tuple>
#include <type_traits>
@@ -35,6 +36,20 @@
*/
void receive(int sock, ReceiveCallback cb);
+/* @brief Call on an rtnetlink payload
+ * Updates the input to remove the attr parsed out.
+ *
+ * @param[in,out] data - The buffer holding rtpayload to parse
+ * @return The payload for the rt msg
+ */
+template <typename T>
+constexpr const T& extractRtData(std::string_view& data)
+{
+ const T& ret = stdplus::raw::refFrom<T, stdplus::raw::Aligned>(data);
+ data.remove_prefix(NLMSG_ALIGN(sizeof(T)));
+ return ret;
+}
+
/* @brief Call on a block of rtattrs to parse a single one out
* Updates the input to remove the attr parsed out.
*