项目作者: t348575

项目描述 :
A C++ 17 msgpack implementation
高级语言: C++
项目地址: git://github.com/t348575/msgpack.git
创建时间: 2020-12-26T18:46:52Z
项目社区:https://github.com/t348575/msgpack

开源协议:MIT License

下载


" class="reference-link">msgpack Visits

A simple C++17 (only) compatible msgpack implementation.

Note: Still in development

References:

Data structures added so far:

  • vector
  • map
  • tuple
  • list
  • queue
  • deque
  • Primitive types
    • All integers (int8, int16, int32, int64) signed and unsigned
    • Float, Double
    • String (char, char *, std::string)
    • nullptr or void *

Data structures to be added

  • list
  • set
  • multimap, unordered map, etc.
  • user defined structures & classes

Features to be added

  • Iterable in memory msgpack (ie. stored as msgpack but iterable)
  • Write to streams instead of stringstream or string

Current performance

  • ~ 2GB of randomly generated data (not fixed sized vectors, maps, tuple and std::string, double, int, char) packed in 6.56 seconds on an i7-7700HQ
  • Memory allocation could be better optimized

Instructions

  1. Copy msgpack.hpp, formats.hpp, and the containers folder
  2. Include msgpack.hpp

Hello World

Compile and run test.cpp to run a sample benchmark ~ 100 - 250 MB, or run the hello world below.

  1. #include <iostream>
  2. #include <tuple>
  3. #include <map>
  4. #include <vector>
  5. #include <string>
  6. #include "msgpack.hpp"
  7. int main() {
  8. msgpack_byte::container dest; // byte container holding the packed bytes
  9. // data generation
  10. std::tuple <char, unsigned int, double, string,
  11. std::vector<unsigned int>, std::map<std::string, uint64_t> > original, unpacked; // an example container to pack
  12. std::vector<unsigned int> vec{ 1, 2, 3, 4, 5 };
  13. std::string abc = "test string";
  14. std::map<string, uint64_t> cde;
  15. cde.insert(make_pair(string("abc"), 4142342342342343));
  16. cde.insert(make_pair(string("cde"), 5));
  17. cde.insert(make_pair(string("def"), 11231233));
  18. original = std::make_tuple('a', 10, 0.333333333333333, abc, vec, cde);
  19. msgpack::pack(original, dest); // pass the container to be packed and the byte container
  20. msgpack::unpack(unpacked, dest); // pass container to parse into and the byte container
  21. std::cout << msgpack_byte::to_stringstream(dest).str() << std::endl; // return a stringstream of the packed data (in hex)
  22. std::cout << msgpack_byte::to_string(dest) << std::endl; // return a string
  23. std::cout << "Packed size: " << dest.size() << std::endl;
  24. return 0;
  25. }

Compile time defines

Compile with different #define values to change performance

  • #define lenient_size an integer value after which garbage collection trims extra memory for msgpack_byte::container default 1000
  • #define compression_percent a float value to with which memory preallocation is adjust (to accomodate msgpack’s formatting) default 1.1
  • #define doubling_strategy define this without value to opt for doubling of byte container instead of growing by factor of 1.1