Added support for sending and receiving of std::vectors
Provided that in std::vector<T>, T is a supported packet type (std::string, uintXX_t, intXX_t....)
This commit is contained in:
parent
02ab3634c4
commit
db6c7e4c41
@ -7,6 +7,7 @@
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include "NetworkEncoding.h"
|
||||
|
||||
namespace fr
|
||||
@ -46,6 +47,46 @@ namespace fr
|
||||
return buffer;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Adds a vector to a packet
|
||||
*/
|
||||
template<typename T>
|
||||
inline Packet &operator<<(const std::vector<T> &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<typename T>
|
||||
inline Packet &operator>>(std::vector<T> &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
|
||||
*/
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user