On Wednesday, January 30, 2013 5:57:49 PM UTC+8, Milano Fili wrote: > > Hi, > > I'm a network developer and now I'm using protocol buffer all the times. > But sometimes I should use JSON format. I'm always thinking about how to > have a compiler like protoc to generate/parse JSON data. Protocol buffer > and it's compiler get us a clear way to make the communications between two > softwares. Now how to change it to JSON compiler? I just want to know the > idea that is my start point. > The protocol compiler takes a .proto file and generates an implementation in a certain programming language. It's not coupled with a certain wire-format though. You can make it generate C++ code that parses JSON format, or you can also make it generate python code that parses JSON format. Actually you don't need to change the compiler at all to support a new format, like what protobuf-json<https://code.google.com/p/protobuf-json/> does. With protobuf reflection, you can write a simple library in one of the programming languages that protobuf supports to parse/serialize protobuf messages from/into the new format. JSON is basically another text format. You can refer to textformat.cc<https://code.google.com/p/protobuf/source/browse/trunk/src/google/protobuf/text_format.cc>, TextFormat.java<https://code.google.com/p/protobuf/source/browse/trunk/java/src/main/java/com/google/protobuf/TextFormat.java> or text_format.py<https://code.google.com/p/protobuf/source/browse/trunk/python/google/protobuf/text_format.py> to get an idea of how protobuf reflection is used to support the current text format. Then implementing one to support JSON should be quite straightforward.
> > Caio, > MF > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/protobuf?hl=en. For more options, visit https://groups.google.com/groups/opt_out.
