]> git.localhorst.tv Git - blank.git/commitdiff
more packet introspection from payload
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 17 Sep 2015 20:20:00 +0000 (22:20 +0200)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Thu, 17 Sep 2015 20:20:00 +0000 (22:20 +0200)
or is that "extrospection"? ^^

src/net/Packet.hpp

index ba078585c0c06dae4ed5ad488b9123dfd7ecbaef..09db0dfd1b0ceb4c69d23eae752d58af8f55a10d 100644 (file)
@@ -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<const Packet *>(data - sizeof(Header));
+               }
+               const Header &GetHeader() const noexcept {
+                       return GetPacket().header;
+               }
                std::uint16_t Seq() const noexcept {
-                       return reinterpret_cast<const Packet *>(data - sizeof(Header))->header.ctrl.seq;
+                       return GetHeader().ctrl.seq;
                }
 
                template<class T>