From 81337cf6dac779222131b5e2843a11ac898bb495 Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Thu, 17 Sep 2015 22:20:00 +0200 Subject: [PATCH] more packet introspection from payload or is that "extrospection"? ^^ --- src/net/Packet.hpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/net/Packet.hpp b/src/net/Packet.hpp index ba07858..09db0df 100644 --- a/src/net/Packet.hpp +++ b/src/net/Packet.hpp @@ -55,8 +55,16 @@ struct Packet { std::size_t length; std::uint8_t *data; + /// WARNING: do not use these if the data doesn not + /// point into a real packet's payload + const Packet &GetPacket() const noexcept { + return *reinterpret_cast(data - sizeof(Header)); + } + const Header &GetHeader() const noexcept { + return GetPacket().header; + } std::uint16_t Seq() const noexcept { - return reinterpret_cast(data - sizeof(Header))->header.ctrl.seq; + return GetHeader().ctrl.seq; } template -- 2.39.2