65 lines
1.8 KiB
C++
65 lines
1.8 KiB
C++
/**
|
|
* @file include/server/MpackJson.h
|
|
* @brief MPack<>JSON converter
|
|
* @copyright 2015 Dual Inventive Technology Centre B.V.
|
|
*
|
|
* it converts JSON to MPack and MPack to JSON.
|
|
*/
|
|
#ifndef INCLUDE_SERVER_MPACKJSON_H_
|
|
#define INCLUDE_SERVER_MPACKJSON_H_
|
|
|
|
#include <mpack/mpack.h>
|
|
#include <memory>
|
|
#include <di/Buffer.h>
|
|
#include <di/Json.h>
|
|
|
|
/**
|
|
* @class MpackJson
|
|
* it converts JSON to MPack and MPack to JSON
|
|
*/
|
|
class MpackJson {
|
|
private:
|
|
/**
|
|
* Converts an MPack node API object to a Json object
|
|
* @param mp MPack node type object
|
|
* @return Json object
|
|
*/
|
|
static std::shared_ptr<Di::Json> toJsonObject(const mpack_node_t &mp);
|
|
/**
|
|
* Converts an MPack node API array to a Json array
|
|
* @param mp MPack node type array
|
|
* @return Json object
|
|
*/
|
|
static std::shared_ptr<Di::Json> toJsonArray(const mpack_node_t &mp);
|
|
/**
|
|
* Converts a JSON object into an MPack object with the MPack writer API
|
|
* @param writer MPack writer
|
|
* @param mp Incoming Json object
|
|
*/
|
|
static void toMpackObject(mpack_writer_t *writer, std::shared_ptr<Di::Json> mp);
|
|
/**
|
|
* Converts a JSON array into an MPack array with the MPack writer API
|
|
* @param writer MPack writer
|
|
* @param mp Incoming Json array
|
|
*/
|
|
static void toMpackArray(mpack_writer_t *writer, std::shared_ptr<Di::Json> mp);
|
|
|
|
public:
|
|
/**
|
|
* Converts MPack to JSON
|
|
* @param mpack Incoming MPack string
|
|
* @param json Outcoming JSON string
|
|
* @return 0 on success or error code
|
|
*/
|
|
static int mpackToJson(const Di::Buffer &mpack, std::shared_ptr<std::string> *json);
|
|
/**
|
|
* Converts JSON to MPack
|
|
* @param json Incoming JSON string
|
|
* @param mpack Outcoming MPack string
|
|
* @return 0 on success or error code
|
|
*/
|
|
static int jsonToMpack(const std::shared_ptr<std::string> &json, std::shared_ptr<Di::Buffer> mpack);
|
|
};
|
|
|
|
#endif // INCLUDE_SERVER_MPACKJSON_H_
|