From: Daniel Karbach Date: Thu, 17 Sep 2015 20:20:00 +0000 (+0200) Subject: more packet introspection from payload X-Git-Url: http://git.localhorst.tv/?a=commitdiff_plain;h=81337cf6dac779222131b5e2843a11ac898bb495;p=blank.git more packet introspection from payload or is that "extrospection"? ^^ --- 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