From db6c7e4c418a5ddc380083fa812f38af2e195cd5 Mon Sep 17 00:00:00 2001 From: Cloaked9000 Date: Tue, 10 Jan 2017 15:21:34 +0000 Subject: [PATCH] Added support for sending and receiving of std::vectors Provided that in std::vector, T is a supported packet type (std::string, uintXX_t, intXX_t....) --- include/frnetlib/Packet.h | 41 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/include/frnetlib/Packet.h b/include/frnetlib/Packet.h index 1689c01..2e82b45 100644 --- a/include/frnetlib/Packet.h +++ b/include/frnetlib/Packet.h @@ -7,6 +7,7 @@ #include #include #include +#include #include "NetworkEncoding.h" namespace fr @@ -46,6 +47,46 @@ namespace fr return buffer; } + + /* + * Adds a vector to a packet + */ + template + inline Packet &operator<<(const std::vector &vec) + { + //First store its length + *this << vec.size(); + + //Now each of the elements + for(const auto &iter : vec) + { + *this << iter; + } + + return *this; + } + + /* + * Extracts a vector from the packet + */ + template + inline Packet &operator>>(std::vector &vec) + { + size_t length; + + //First extract the length + *this >> length; + vec.resize(length); + + //Now take each of the elements out of the packet + for(size_t a = 0; a < length; a++) + { + *this >> vec[a]; + } + + return *this; + } + /* * Adds a boolean variable to the packet */