ngl_server 1.0
基于 Actor 模型的 C++ 服务器框架
ngl::njson Class Reference

可变参数JSON批量读写前端。 More...

#include <njson.h>

Static Public Member Functions

template<typename ... TARGS>
static bool pop (ncjson &ajson, const std::array< const char *, sizeof...(TARGS)> &akeys, TARGS &... aargs)
 从ncjson文档批量读取多个字段。
template<typename ... TARGS>
static bool pop (rapidjson::Value &ajson, const std::array< const char *, sizeof...(TARGS)> &akeys, TARGS &... aargs)
 从rapidjson::Value批量读取多个字段。
template<typename ... TARGS>
static bool push (ncjson &ajson, const std::array< const char *, sizeof...(TARGS)> &akeys, const TARGS &... aargs)
 向ncjson文档批量写入多个字段。
template<typename ... TARGS>
static bool push (rapidjson::Value &ajson, rapidjson::Document::AllocatorType *aallocator, const std::array< const char *, sizeof...(TARGS)> &akeys, const TARGS &... aargs)
 向rapidjson::Value批量写入多个字段。

Detailed Description

可变参数JSON批量读写前端。

将并行的字段名数组映射到对应的值,利用折叠表达式实现批量序列化/反序列化。 支持从ncjson文档或rapidjson::Value中读写。

// 批量读取
ncjson doc(json_str);
int id; std::string name;
njson::pop(doc, {"id", "name"}, id, name);

Member Function Documentation

◆ pop() [1/2]

template<typename ... TARGS>
bool ngl::njson::pop ( ncjson & ajson,
const std::array< const char *, sizeof...(TARGS)> & akeys,
TARGS &... aargs )
inlinestatic

从ncjson文档批量读取多个字段。

Template Parameters
TARGS值类型包
Parameters
ajsonJSON文档
akeys字段名数组
aargs输出参数(与akeys一一对应)
Returns
true 全部读取成功
false 任一字段读取失败

◆ pop() [2/2]

template<typename ... TARGS>
bool ngl::njson::pop ( rapidjson::Value & ajson,
const std::array< const char *, sizeof...(TARGS)> & akeys,
TARGS &... aargs )
inlinestatic

从rapidjson::Value批量读取多个字段。

Template Parameters
TARGS值类型包
Parameters
ajsonJSON值对象
akeys字段名数组
aargs输出参数
Returns
true 全部读取成功
false 任一字段读取失败

◆ push() [1/2]

template<typename ... TARGS>
bool ngl::njson::push ( ncjson & ajson,
const std::array< const char *, sizeof...(TARGS)> & akeys,
const TARGS &... aargs )
inlinestatic

向ncjson文档批量写入多个字段。

自动将文档设为Object类型。

Template Parameters
TARGS值类型包
Parameters
ajsonJSON文档
akeys字段名数组
aargs要写入的值(与akeys一一对应)
Returns
true 全部写入成功
false 任一字段写入失败

◆ push() [2/2]

template<typename ... TARGS>
bool ngl::njson::push ( rapidjson::Value & ajson,
rapidjson::Document::AllocatorType * aallocator,
const std::array< const char *, sizeof...(TARGS)> & akeys,
const TARGS &... aargs )
inlinestatic

向rapidjson::Value批量写入多个字段。

Template Parameters
TARGS值类型包
Parameters
ajsonJSON值对象
aallocator内存分配器
akeys字段名数组
aargs要写入的值
Returns
true 全部写入成功
false 任一字段写入失败

The documentation for this class was generated from the following file: