identt
ProtoJson.hpp
Go to the documentation of this file.
1 
33 #ifndef _IDENTT_QUERY_PROTOJSON_HPP_
34 #define _IDENTT_QUERY_PROTOJSON_HPP_
35 
36 #include <string>
37 #include <vector>
38 #include <google/protobuf/descriptor.h>
39 #include <google/protobuf/message.h>
40 
41 #include <utils/BaseUtils.hpp>
42 
43 #ifndef IDENTT_ERR_INVALID_ARG
44 #define IDENTT_ERR_INVALID_ARG -1
45 #endif
46 
47 #ifndef IDENTT_ERR_INVALID_PB
48 #define IDENTT_ERR_INVALID_PB -2
49 #endif
50 
51 #ifndef IDENTT_ERR_UNKNOWN_FIELD
52 #define IDENTT_ERR_UNKNOWN_FIELD -3
53 #endif
54 
55 #ifndef IDENTT_ERR_INVALID_JSON
56 #define IDENTT_ERR_INVALID_JSON -4
57 #endif
58 
59 #define RAPIDJSON_HAS_STDSTRING 1
60 #define RAPIDJSON_ASSERT(x) if(!(x)) throw identt::BadJsonException();
61 #include <rapidjson/document.h>
62 
63 #include <query/JsonElem.hpp>
64 
65 namespace identt {
66 namespace query {
67 
80 void pb2json(const google::protobuf::Message* msg, std::string& str);
81 
91 rapidjson::Value* pb2jsonobject(const google::protobuf::Message* msg);
92 
105 rapidjson::Value* pb2jsonobject(const google::protobuf::Message* msg, rapidjson::Value::AllocatorType& allocator);
106 
119 void json2string(const rapidjson::Value* json, std::string& str);
120 
136 int json2pb(const std::string& json, google::protobuf::Message* msg, std::string& err);
137 
153 int jsonobject2pb(const rapidjson::Value* json, google::protobuf::Message* msg, std::string& err);
154 
164 std::string arr2json(std::vector<JsonElem> data);
165 
178 std::string err2json(const std::string errorcode, const std::string error);
179 
180 }
181 }
182 
183 #endif // _IDENTT_QUERY_PROTOJSON_HPP_
rapidjson::Value * pb2jsonobject(const google::protobuf::Message *msg)
pb2jsonobject : Convert protobuf to json object
Definition: ProtoJson.cc:427
Allocator AllocatorType
Allocator type from template parameter.
Definition: document.h:553
void pb2json(const google::protobuf::Message *msg, std::string &str)
pb2json : Convert protobuf to json
Definition: ProtoJson.cc:415
GenericValue< UTF8<> > Value
GenericValue with UTF8 encoding.
Definition: document.h:2060
std::string arr2json(std::vector< JsonElem > data)
arr2json : Generate a Json for array
Definition: CryptoBase.hpp:49
std::string err2json(const std::string errorcode, const std::string error)
err2json : Generate a Json for Error Message
Definition: ProtoJson.cc:511
int json2pb(const std::string &json, google::protobuf::Message *msg, std::string &err)
json2pb : Convert json to protobuf
Definition: ProtoJson.cc:446
int jsonobject2pb(const rapidjson::Value *json, google::protobuf::Message *msg, std::string &err)
jsonobject2pb : Convert json object to protobuf
Definition: ProtoJson.cc:462
void json2string(const rapidjson::Value *json, std::string &str)
json2string : Convert json to string
Definition: ProtoJson.cc:403