forked from shafreeck/pb2json
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
#include <jansson.h> | ||
#ifndef PB2JSON_H | ||
#define PB2JSON_H | ||
|
||
#include <string> | ||
#include <google/protobuf/descriptor.h> | ||
#include <google/protobuf/message.h> | ||
using namespace google::protobuf; | ||
char *pb2json(const Message &msg); | ||
char *pb2json(Message *msg,const char *buf,int len); | ||
static json_t *parse_msg(const Message *msg); | ||
static json_t *parse_repeated_field(const Message *msg,const Reflection * ref,const FieldDescriptor *field); | ||
|
||
// Forward declaration | ||
namespace google | ||
{ | ||
namespace protobuf | ||
{ | ||
class Message; | ||
} // namespace protobuf | ||
} // namespace google | ||
|
||
std::string pb2json(const google::protobuf::Message& msg); | ||
|
||
template <typename PbMessageType> | ||
std::string pb2json(const std::string& str) | ||
{ | ||
PbMessageType msg; | ||
msg.ParseFromString(str); | ||
return pb2json(msg); | ||
} | ||
|
||
#endif // PB2JSON_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#include <iostream> | ||
#include <fstream> | ||
|
||
#include "person.pb.h" | ||
|
||
using namespace std; | ||
|