identt
Macros | Functions
ProtoJson.hpp File Reference

identt More...

#include <string>
#include <vector>
#include <google/protobuf/descriptor.h>
#include <google/protobuf/message.h>
#include <utils/BaseUtils.hpp>
#include <rapidjson/document.h>
#include <query/JsonElem.hpp>

Go to the source code of this file.

Macros

#define IDENTT_ERR_INVALID_ARG   -1
 
#define IDENTT_ERR_INVALID_PB   -2
 
#define IDENTT_ERR_UNKNOWN_FIELD   -3
 
#define IDENTT_ERR_INVALID_JSON   -4
 
#define RAPIDJSON_HAS_STDSTRING   1
 
#define RAPIDJSON_ASSERT(x)   if(!(x)) throw identt::BadJsonException();
 

Functions

void identt::query::pb2json (const google::protobuf::Message *msg, std::string &str)
 pb2json : Convert protobuf to json More...
 
rapidjson::Valueidentt::query::pb2jsonobject (const google::protobuf::Message *msg)
 pb2jsonobject : Convert protobuf to json object More...
 
rapidjson::Valueidentt::query::pb2jsonobject (const google::protobuf::Message *msg, rapidjson::Value::AllocatorType &allocator)
 pb2jsonobject : Convert protobuf to json object More...
 
void identt::query::json2string (const rapidjson::Value *json, std::string &str)
 json2string : Convert json to string More...
 
int identt::query::json2pb (const std::string &json, google::protobuf::Message *msg, std::string &err)
 json2pb : Convert json to protobuf More...
 
int identt::query::jsonobject2pb (const rapidjson::Value *json, google::protobuf::Message *msg, std::string &err)
 jsonobject2pb : Convert json object to protobuf More...
 
std::string identt::query::arr2json (std::vector< JsonElem > data)
 arr2json : Generate a Json for array More...
 
std::string identt::query::err2json (const std::string errorcode, const std::string error)
 err2json : Generate a Json for Error Message More...
 

Detailed Description

identt

Author
S Roychowdhury <sroycode at="" gmail="" dot="" com>="">
Version
1.0.0

LICENSE

Copyright (c) 2017 S Roychowdhury.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

DESCRIPTION

ProtoJson.hpp : Headers for Protobuf<->Json implementation (modified from https://github.com/yinqiwen/pbjson )

Function Documentation

§ arr2json()

std::string identt::query::arr2json ( std::vector< JsonElem data)

arr2json : Generate a Json for array

Parameters
datastd::vector< JsonElem > data
Returns
str::string

§ err2json()

std::string identt::query::err2json ( const std::string  errorcode,
const std::string  error 
)

err2json : Generate a Json for Error Message

Parameters
errorcodestd::string error code string
errorstd::string& error string
Returns
str::string

§ json2pb()

int identt::query::json2pb ( const std::string &  json,
google::protobuf::Message *  msg,
std::string &  err 
)

json2pb : Convert json to protobuf

Parameters
jsonstd::string& from string
msggoogle::protobuf::Message* to msg pointer
errstd::string& error string
Returns
int

§ json2string()

void identt::query::json2string ( const rapidjson::Value json,
std::string &  str 
)

json2string : Convert json to string

Parameters
jsonconst rapidjson::Value* input json object
strstd::string& to string
Returns
none

§ jsonobject2pb()

int identt::query::jsonobject2pb ( const rapidjson::Value json,
google::protobuf::Message *  msg,
std::string &  err 
)

jsonobject2pb : Convert json object to protobuf

Parameters
jsonrapidjson::Value* input json object
msgconst google::protobuf::Message* to msg pointer
errstd::string& error string
Returns
int

§ pb2json()

void identt::query::pb2json ( const google::protobuf::Message *  msg,
std::string &  str 
)

pb2json : Convert protobuf to json

Parameters
msgconst google::protobuf::Message* from msg pointer
strstd::string& to string
Returns
none

§ pb2jsonobject() [1/2]

rapidjson::Value * identt::query::pb2jsonobject ( const google::protobuf::Message *  msg)

pb2jsonobject : Convert protobuf to json object

Parameters
msgconst google::protobuf::Message* from msg pointer
Returns
rapidjson::Value*

§ pb2jsonobject() [2/2]

rapidjson::Value * identt::query::pb2jsonobject ( const google::protobuf::Message *  msg,
rapidjson::Value::AllocatorType allocator 
)

pb2jsonobject : Convert protobuf to json object

Parameters
msgconst google::protobuf::Message* from msg pointer
allocatorrapidjson::Value::AllocatorType& allocator to use
Returns
rapidjson::Value*