|
Zakero's C++ Header Libraries
A collection of reusable C++ libraries
|
Zakero MessagePack. More...

Go to the source code of this file.
Classes | |
| class | zakero::MessagePack |
| Object and Data Serialization. More... | |
Macros | |
| #define | ZAKERO_DISABLE_IMPLICIT_CASTS(func_name_) |
| Don't allow implicit parameter conversion. More... | |
| #define | ZAKERO_MESSAGEPACK_IMPLEMENTATION |
| Activate the implementation code. More... | |
Format Value Masks | |
| #define | X(type_, id_, mask_, text_) |
| Convert ZAKERO_MESSAGEPACK__FORMAT_DATA into code. | |
| #define | X(type_, id_, mask_, text_) |
| Convert ZAKERO_MESSAGEPACK__FORMAT_DATA into code. | |
| #define | X(type_, id_, mask_, text_) |
| Convert ZAKERO_MESSAGEPACK__FORMAT_DATA into code. | |
| API | Dependencies | TL;DR | What Is It? | Why Use It? | How To Use It? | Version |
The Zakero_MessagePack will serialize and deserialize data using the MessagePack specification.
This library makes it very easy to use the MessagePack data format.
To use:
There are many libraries available to do the same thing, however the Zakero_MessagePack library offers the following:
Benefits
Draw Backs
Instead of attempting to interface with other libraries or provide a dynamic interface, basic C++ types are used. It is expected that this approach will make using the library with other code bases easier and less volatile.
Step 0
Your compiler must support at least the C++20 standard. The location of the Zakero_*.h header files must be in your compiler's include path.
Step 1
The first step is to select which C++ source code file will contain the Zakero MessagePack implementation. Once the location has been determined, add the following to that file:
The macro ZAKERO_MESSAGEPACK_IMPLEMENTATION tells the header file to include the implementation of the MessagePack.
In all other files that will use the MessagePack, they need to include the header.
Step 2
After creating an instance of MessagePack, it needs to be populated with data. There are two options to do this:
Add data manually
Deserialize data
The data in the MessagePack can be modified:
Then the MessagePack can be (re)serialized:
| #define ZAKERO_DISABLE_IMPLICIT_CASTS | ( | func_name_ | ) |
When passing a value to a function's parameter which does not have a matching type, the compiler will try to inject code to convert the value into the function's expected type. Usually, this is fine. But in some instances can lead to very subtle bugs. Placing the function name in this macro will prevent the compiler from doing this automatic type conversion.
| func_name_ | The name of the function. |
| #define ZAKERO_MESSAGEPACK_IMPLEMENTATION |
Defining this macro will cause the zakero::MessagePack implementation to be included. This should only be done once, since compiler and/or linker errors will typically be generated if more than a single implementation is found.