Skip to content

t348575/msgpack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

45 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

#include <iostream>
#include <tuple>
#include <map>
#include <vector>
#include <string>
#include "msgpack.hpp"
int main() {

    msgpack_byte::container dest; // byte container holding the packed bytes

    // data generation

    std::tuple <char, unsigned int, double, string,
    std::vector<unsigned int>, std::map<std::string, uint64_t> > original, unpacked; // an example container to pack
    std::vector<unsigned int> vec{ 1, 2, 3, 4, 5 };
    std::string abc = "test string";
    std::map<string, uint64_t> cde;
    cde.insert(make_pair(string("abc"), 4142342342342343));
    cde.insert(make_pair(string("cde"), 5));
    cde.insert(make_pair(string("def"), 11231233));
    original = std::make_tuple('a', 10, 0.333333333333333, abc, vec, cde);

    msgpack::pack(original, dest); // pass the container to be packed and the byte container
    msgpack::unpack(unpacked, dest); // pass container to parse into and the byte container

    std::cout << msgpack_byte::to_stringstream(dest).str() << std::endl; // return a stringstream of the packed data (in hex)
    std::cout << msgpack_byte::to_string(dest) << std::endl; // return a string
    std::cout << "Packed size: " << dest.size() << std::endl;
    return 0;
}

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

About

A C++ 17 msgpack implementation

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages