117#ifndef ASYNC_MSG_INCLUDED
118#define ASYNC_MSG_INCLUDED
193#define ASYNC_MSG_DERIVED_FROM(BASE_CLASS) \
194 bool packParent(std::ostream& os) const \
196 return BASE_CLASS::pack(os); \
198 size_t packedSizeParent(void) const \
200 return BASE_CLASS::packedSize(); \
202 bool unpackParent(std::istream& is) \
204 return BASE_CLASS::unpack(is); \
214#define ASYNC_MSG_MEMBERS(...) \
215 bool pack(std::ostream& os) const override \
217 return packParent(os) && Msg::pack(os, __VA_ARGS__); \
219 size_t packedSize(void) const override \
221 return packedSizeParent() + Msg::packedSize(__VA_ARGS__); \
223 bool unpack(std::istream& is) override \
225 return unpackParent(is) && Msg::unpack(is, __VA_ARGS__); \
233#define ASYNC_MSG_NO_MEMBERS \
234 bool pack(std::ostream& os) const override \
236 return packParent(os); \
238 size_t packedSize(void) const override { return packedSizeParent(); } \
239 bool unpack(std::istream& is) override \
241 return unpackParent(is); \
263 static bool pack(std::ostream& os,
const T& val) {
return val.pack(os); }
264 static size_t packedSize(
const T& val) {
return val.packedSize(); }
265 static bool unpack(std::istream& is, T& val) {
return val.unpack(is); }
272 static bool pack(std::ostream& os,
char val)
275 return os.write(&val, 1).good();
277 static size_t packedSize(
const char& val) {
return sizeof(char); }
278 static bool unpack(std::istream& is,
char& val)
290 static bool pack(std::ostream& os,
const T& val)
295 o.uval = htobe64(o.uval);
296 return os.write(o.buf,
sizeof(T)).good();
299 static bool unpack(std::istream& is, T& val)
302 is.read(o.buf,
sizeof(T));
303 o.uval = be64toh(o.uval);
324 static bool pack(std::ostream& os,
const T& val)
329 o.uval = htobe32(o.uval);
330 return os.write(o.buf,
sizeof(T)).good();
333 static bool unpack(std::istream& is, T& val)
336 is.read(o.buf,
sizeof(T));
337 o.uval = be32toh(o.uval);
358 static bool pack(std::ostream& os,
const T& val)
363 o.uval = htobe16(o.uval);
364 return os.write(o.buf,
sizeof(T)).good();
367 static bool unpack(std::istream& is, T& val)
370 is.read(o.buf,
sizeof(T));
371 o.uval = be16toh(o.uval);
391 static bool pack(std::ostream& os,
const T& val)
394 return os.write(
reinterpret_cast<const char*
>(&val),
sizeof(T)).good();
397 static bool unpack(std::istream& is, T& val)
399 is.read(
reinterpret_cast<char*
>(&val),
sizeof(T));
411 static bool pack(std::ostream& os,
const std::string& val)
414 if (val.size() > std::numeric_limits<uint16_t>::max())
418 uint16_t str_len(val.size());
420 os.write(val.c_str(), val.size());
424 return sizeof(uint16_t) + val.size();
426 static bool unpack(std::istream& is, std::string& val)
431 if (str_len > std::numeric_limits<uint16_t>::max())
436 if (is.read(buf, str_len))
438 val.assign(buf, str_len);
451 static bool pack(std::ostream& os,
const std::vector<I>& vec)
454 if (vec.size() > std::numeric_limits<uint16_t>::max())
459 for (
const auto& item : vec)
470 size_t size =
sizeof(uint16_t);
471 for (
const auto& item : vec)
477 static bool unpack(std::istream& is, std::vector<I>& vec)
481 if (vec_size > std::numeric_limits<uint16_t>::max())
486 vec.resize(vec_size);
487 for (
auto& item : vec)
502 static bool pack(std::ostream& os,
const std::set<I>& s)
505 if (s.size() > std::numeric_limits<uint16_t>::max())
513 for (
const auto& item : s)
524 size_t size =
sizeof(uint16_t);
525 for (
const auto& item : s)
531 static bool unpack(std::istream& is, std::set<I>& s)
538 if (set_size > std::numeric_limits<uint16_t>::max())
544 for (
int i=0; i<set_size; ++i)
557template <
typename Tag,
typename Value>
561 static bool pack(std::ostream& os,
const std::map<Tag, Value>& m)
564 if (m.size() > std::numeric_limits<uint16_t>::max())
569 for (
const auto& item : m)
578 size_t size =
sizeof(uint16_t);
579 for (
const auto& item : m)
586 static bool unpack(std::istream& is, std::map<Tag,Value>& m)
590 if (map_size > std::numeric_limits<uint16_t>::max())
596 for (
int i=0; i<map_size; ++i)
608template <
typename T,
size_t N>
612 static bool pack(std::ostream& os,
const std::array<T, N>& vec)
614 for (
const auto& item : vec)
626 for (
const auto& item : vec)
632 static bool unpack(std::istream& is, std::array<T, N>& vec)
634 for (
auto& item : vec)
648 static bool pack(std::ostream& os,
const T (&vec)[N])
650 for (
const auto& item : vec)
662 for (
const auto& item : vec)
668 static bool unpack(std::istream& is, T (&vec)[N])
670 for (
auto& item : vec)
696 virtual bool pack(std::ostream&)
const {
return true; }
698 virtual bool unpack(std::istream&) {
return true; }
700 template <
typename T>
701 bool pack(std::ostream& os,
const T& val)
const
705 template <
typename T>
710 template <
typename T>
711 bool unpack(std::istream& is, T& val)
const
716 template <
typename T1,
typename T2,
typename... Args>
717 bool pack(std::ostream& os,
const T1& v1,
const T2& v2,
718 const Args&... args)
const
720 return pack(os, v1) &&
pack(os, v2, args...);
722 template <
typename T1,
typename T2,
typename... Args>
723 size_t packedSize(
const T1& v1,
const T2& v2,
const Args&... args)
const
727 template <
typename T1,
typename T2,
typename... Args>
728 bool unpack(std::istream& is, T1& v1, T2& v2, Args&... args)
static bool pack(std::ostream &os, const T(&vec)[N])
static size_t packedSize(const T(&vec)[N])
static bool unpack(std::istream &is, T(&vec)[N])
static bool pack(std::ostream &os, char val)
static bool unpack(std::istream &is, char &val)
static size_t packedSize(const char &val)
static size_t packedSize(const std::array< T, N > &vec)
static bool unpack(std::istream &is, std::array< T, N > &vec)
static bool pack(std::ostream &os, const std::array< T, N > &vec)
static bool pack(std::ostream &os, const std::map< Tag, Value > &m)
static bool unpack(std::istream &is, std::map< Tag, Value > &m)
static size_t packedSize(const std::map< Tag, Value > &m)
static bool unpack(std::istream &is, std::set< I > &s)
static size_t packedSize(const std::set< I > &s)
static bool pack(std::ostream &os, const std::set< I > &s)
static bool unpack(std::istream &is, std::string &val)
static size_t packedSize(const std::string &val)
static bool pack(std::ostream &os, const std::string &val)
static bool unpack(std::istream &is, std::vector< I > &vec)
static size_t packedSize(const std::vector< I > &vec)
static bool pack(std::ostream &os, const std::vector< I > &vec)
static bool unpack(std::istream &is, T &val)
static bool pack(std::ostream &os, const T &val)
static size_t packedSize(const T &val)
Base class for all messages.
size_t packedSize(const T1 &v1, const T2 &v2, const Args &... args) const
size_t packedSize(const T &val) const
bool unpack(std::istream &is, T &val) const
bool pack(std::ostream &os, const T1 &v1, const T2 &v2, const Args &... args) const
bool unpack(std::istream &is, T1 &v1, T2 &v2, Args &... args)
bool pack(std::ostream &os, const T &val) const
bool packParent(std::ostream &) const
size_t packedSizeParent(void) const
virtual size_t packedSize(void) const
virtual bool unpack(std::istream &)
bool unpackParent(std::istream &)
virtual bool pack(std::ostream &) const
static bool unpack(std::istream &is, T &val)
static size_t packedSize(const T &val)
static bool pack(std::ostream &os, const T &val)
static bool unpack(std::istream &is, T &val)
static bool pack(std::ostream &os, const T &val)
static size_t packedSize(const T &val)
static bool pack(std::ostream &os, const T &val)
static size_t packedSize(const T &val)
static bool unpack(std::istream &is, T &val)
static bool unpack(std::istream &is, T &val)
static bool pack(std::ostream &os, const T &val)
static size_t packedSize(const T &val)
Namespace for the asynchronous programming classes.