开发者

Can I serialize/deserialize JSON from protocol buffers with C++?

开发者 https://www.devze.com 2023-03-11 06:48 出处:网络
There are frameworks for Java and other languages that help connect protocol buffers to JSON, but I have not seen a native solution in C++.

There are frameworks for Java and other languages that help connect protocol buffers to JSON, but I have not seen a native solution in C++.

Is there a library/framework that I can use to connect C++ protocol b开发者_开发技巧uffer objects to JSON?


I'm developing one. I'm using the protobuf's reflection mechanism to parse any generated protobuf. Here http://corbasim.googlecode.com/svn/trunk/protobuf2json_exported.zip you can find an initial implementation of this idea. It currently just parse string fields, but I want to support any type as soon as possible.

For a message Foo:

message Foo {
   optional string text = 1;
}

it can parse instances of Foo by this way:

Foo foo;

const std::string json_foo = "{\"text\": \"Hello world\"}";

protobuf2json::json::parse(foo, json_foo)

By the same way, I want to write a JSON serializer from protobuf generated types.

There is a similar question here:

C++ Protobuf to/from JSON conversion


pb2json is another library that can be used.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号