Skip to content

Commit aae4e6f

Browse files
committed
Added support for MessagePack
The ASIO based network classes can now serialize and deserialize network messages using MessagePack. MessagePack 7.0.0 is included with Core
1 parent 75367f0 commit aae4e6f

5,567 files changed

Lines changed: 419191 additions & 12417 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.vscode/launch.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
"request": "launch",
2222
"program": "${input:unitTestProgramWin}",
2323
"args": [
24-
"--gtest_filter=AsioTest.testCase_TestSimpleSync_Large",
25-
"--gtest_break_on_failure",
26-
"--gtest_catch_exceptions=0"
24+
//"--gtest_filter=",
25+
//"--gtest_break_on_failure",
26+
//"--gtest_catch_exceptions=0"
2727
],
2828
"cwd": "${workspaceFolder}",
2929
"console": "integratedTerminal"
@@ -34,9 +34,9 @@
3434
"request": "launch",
3535
"program": "${input:unitTestProgramLinux}",
3636
"args": [
37-
"--gtest_filter=",
38-
"--gtest_break_on_failure",
39-
"--gtest_catch_exceptions=0"
37+
//"--gtest_filter=",
38+
// "--gtest_break_on_failure",
39+
// "--gtest_catch_exceptions=0"
4040
],
4141
"cwd": "${workspaceFolder}",
4242
"MIMode": "gdb",

Include/Serialization/SerializeToVector.h

Lines changed: 77 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@
3838
#include <span>
3939
#include <boost/throw_exception.hpp>
4040
#include <cereal/types/vector.hpp>
41+
#include <msgpack/msgpack.hpp>
4142
#if defined(USE_FLATBUFFERS)
42-
#include "flatbuffers/flatbuffers.h"
43+
#include <flatbuffers/flatbuffers.h>
4344
#endif
4445

4546
#define SERIALIZE_TO_STREAM_ARCHIVE(osa, o) osa(CEREAL_NVP(o))
@@ -79,6 +80,16 @@ struct CORE_LIBRARY_DLL_SHARED_API protobuf_oarchive
7980
{
8081
};
8182

83+
/*! \brief In archive placeholder struct for serializing MessagePack. */
84+
struct CORE_LIBRARY_DLL_SHARED_API msgpack_iarchive
85+
{
86+
};
87+
88+
/*! \brief Out archive placeholder struct for serializing MessagePack. */
89+
struct CORE_LIBRARY_DLL_SHARED_API msgpack_oarchive
90+
{
91+
};
92+
8293
/*! \brief The archives namespace. */
8394
namespace archives
8495
{
@@ -94,6 +105,8 @@ using out_json_t = cereal::JSONOutputArchive;
94105
using out_raw_t = raw_oarchive;
95106
/*! \brief Typedef to output using Google protocol buffers. */
96107
using out_protobuf_t = protobuf_oarchive;
108+
/*! \brief Typedef to output using MessagePack. */
109+
using out_msgpack_t = msgpack_oarchive;
97110
/*! \brief Typedef to input portable binary archive. */
98111
using in_port_bin_t = cereal::PortableBinaryInputArchive;
99112
/*! \brief Typedef to input binary archive. */
@@ -106,6 +119,8 @@ using in_json_t = cereal::JSONInputArchive;
106119
using in_raw_t = raw_iarchive;
107120
/*! \brief Typedef to input using Google protocol buffers. */
108121
using in_protobuf_t = protobuf_iarchive;
122+
/*! \brief Typedef to input using MessagePack. */
123+
using in_msgpack_t = msgpack_iarchive;
109124

110125
} // namespace archives
111126

@@ -252,6 +267,41 @@ template <typename T> struct ToCharVectorImpl<T, archives::out_protobuf_t>
252267
}
253268
};
254269

270+
/*! \brief Serialization to char vector implementation, specialization for Messagepack bufs. */
271+
template <typename T>
272+
struct ToCharVectorImpl<T, archives::out_msgpack_t>
273+
{
274+
/*!
275+
* \brief Function operator
276+
* \param[in] object - Object to serialize
277+
* \return Char vector containing serialized object
278+
*
279+
* This overload creates new memory.
280+
*/
281+
char_vector_t operator()(const T& object) const
282+
{
283+
msgpack::sbuffer buffer;
284+
msgpack::pack(buffer, object);
285+
286+
return char_vector_t(buffer.data(), buffer.data() + buffer.size());
287+
}
288+
289+
/*!
290+
* \brief Function operator
291+
* \param[in] object - Object to serialize
292+
* \param[out] result - Char vector containing serialized object
293+
*
294+
* This overload uses the memory passed in and resizes if necessary.
295+
*/
296+
void operator()(const T& object, char_vector_t& result) const
297+
{
298+
msgpack::sbuffer buffer;
299+
msgpack::pack(buffer, object);
300+
301+
result.assign(buffer.data(), buffer.data() + buffer.size());
302+
}
303+
};
304+
255305
/*!
256306
* \brief Deserialization to object implementation.
257307
*
@@ -330,6 +380,31 @@ template <typename T> struct ToObjectImpl<T, archives::in_protobuf_t>
330380
}
331381
};
332382

383+
/*! \brief Deserialization to object implementation, specialization for Google protocol buffers. */
384+
template <typename T>
385+
struct ToObjectImpl<T, archives::in_msgpack_t>
386+
{
387+
/*!
388+
* \brief Function operator
389+
* \param[in] charSpan - Char span containing serialized object
390+
* \return Deserialized object
391+
*/
392+
T operator()(char_cspan_buf_t charSpan) const
393+
{
394+
if (charSpan.empty())
395+
{
396+
BOOST_THROW_EXCEPTION(std::runtime_error("Cannot deserialize MessagePack object from empty buffer."));
397+
}
398+
399+
msgpack::object_handle oh = msgpack::unpack(charSpan.data(), charSpan.size());
400+
401+
T object;
402+
oh.get().convert(object);
403+
404+
return object;
405+
}
406+
};
407+
333408
} // namespace impl
334409

335410
/*!
@@ -416,7 +491,7 @@ char_vector_t ToCharVectorFlatBuf(const T& object, PackFunc packFunc)
416491

417492
/*!
418493
* \brief Function to serialize object via flatbuffers
419-
* \param[in] builder - A falttbuffer builder already initialised with the message fields.
494+
* \param[in] builder - A flatbuffer builder already initialised with the message fields.
420495
* \return Char vector containing serialized object
421496
*
422497
* This overload creates new memory but has best performance regarding creating a message view object

Include/msgpack/msgpack.hpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// MessagePack for C++
3+
//
4+
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
5+
//
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
//
10+
#include "msgpack/object.hpp"
11+
#include "msgpack/iterator.hpp"
12+
#include "msgpack/zone.hpp"
13+
#include "msgpack/pack.hpp"
14+
#include "msgpack/null_visitor.hpp"
15+
#include "msgpack/parse.hpp"
16+
#include "msgpack/unpack.hpp"
17+
#include "msgpack/x3_parse.hpp"
18+
#include "msgpack/x3_unpack.hpp"
19+
#include "msgpack/sbuffer.hpp"
20+
#include "msgpack/vrefbuffer.hpp"
21+
#include "msgpack/version.hpp"
22+
#include "msgpack/type.hpp"
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// MessagePack for C++ static resolution routine
3+
//
4+
// Copyright (C) 2015-2016 KONDO Takatoshi
5+
//
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
//
10+
#ifndef MSGPACK_ADAPTOR_BASE_HPP
11+
#define MSGPACK_ADAPTOR_BASE_HPP
12+
13+
#include "msgpack/adaptor/adaptor_base_decl.hpp"
14+
15+
#include "msgpack/v1/adaptor/adaptor_base.hpp"
16+
#include "msgpack/v2/adaptor/adaptor_base.hpp"
17+
#include "msgpack/v3/adaptor/adaptor_base.hpp"
18+
19+
#endif // MSGPACK_ADAPTOR_BASE_HPP
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// MessagePack for C++ static resolution routine
3+
//
4+
// Copyright (C) 2016 KONDO Takatoshi
5+
//
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
//
10+
#ifndef MSGPACK_ADAPTOR_BASE_DECL_HPP
11+
#define MSGPACK_ADAPTOR_BASE_DECL_HPP
12+
13+
#include "msgpack/v1/adaptor/adaptor_base_decl.hpp"
14+
#include "msgpack/v2/adaptor/adaptor_base_decl.hpp"
15+
#include "msgpack/v3/adaptor/adaptor_base_decl.hpp"
16+
17+
#endif // MSGPACK_ADAPTOR_BASE_DECL_HPP
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// MessagePack for C++ static resolution routine
3+
//
4+
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
5+
//
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
//
10+
#ifndef MSGPACK_TYPE_ARRAY_REF_HPP
11+
#define MSGPACK_TYPE_ARRAY_REF_HPP
12+
13+
#include "msgpack/adaptor/array_ref_decl.hpp"
14+
15+
#include "msgpack/v1/adaptor/array_ref.hpp"
16+
17+
#endif // MSGPACK_TYPE_ARRAY_REFL_HPP
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// MessagePack for C++ static resolution routine
3+
//
4+
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
5+
//
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
//
10+
#ifndef MSGPACK_TYPE_ARRAY_REF_DECL_HPP
11+
#define MSGPACK_TYPE_ARRAY_REF_DECL_HPP
12+
13+
#include "msgpack/v1/adaptor/array_ref_decl.hpp"
14+
#include "msgpack/v2/adaptor/array_ref_decl.hpp"
15+
#include "msgpack/v3/adaptor/array_ref_decl.hpp"
16+
17+
#endif // MSGPACK_TYPE_ARRAY_REF_DECL_HPP
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// MessagePack for C++ static resolution routine
3+
//
4+
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
5+
//
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
//
10+
#ifndef MSGPACK_TYPE_BOOL_HPP
11+
#define MSGPACK_TYPE_BOOL_HPP
12+
13+
#include "msgpack/v1/adaptor/bool.hpp"
14+
15+
#endif // MSGPACK_TYPE_BOOL_HPP
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// MessagePack for C++ static resolution routine
3+
//
4+
// Copyright (C) 2015 KONDO Takatoshi
5+
//
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
//
10+
#ifndef MSGPACK_TYPE_BOOST_FUSION_HPP
11+
#define MSGPACK_TYPE_BOOST_FUSION_HPP
12+
13+
#include "msgpack/v1/adaptor/boost/fusion.hpp"
14+
15+
#endif // MSGPACK_TYPE_BOOST_FUSION_HPP
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
//
2+
// MessagePack for C++ static resolution routine
3+
//
4+
// Copyright (C) 2015-2016 KONDO Takatoshi
5+
//
6+
// Distributed under the Boost Software License, Version 1.0.
7+
// (See accompanying file LICENSE_1_0.txt or copy at
8+
// http://www.boost.org/LICENSE_1_0.txt)
9+
//
10+
#ifndef MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP
11+
#define MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP
12+
13+
#include "msgpack/adaptor/boost/msgpack_variant_decl.hpp"
14+
15+
#include "msgpack/v1/adaptor/boost/msgpack_variant.hpp"
16+
//#include "msgpack/v2/adaptor/boost/msgpack_variant.hpp"
17+
18+
#endif // MSGPACK_TYPE_BOOST_MSGPACK_VARIANT_HPP

0 commit comments

Comments
 (0)