I have .proto and .pb files. I need to parse .pb file using Java. I don't about how to use this .pb files. Please can anybody help me to parse .pb files?
Asked
Active
Viewed 6,233 times
0
-
I assume these a Google Protocol Buffer files? It would really help if you'd say so. Are the .pb files binary versions of the .proto files? Again, please specify... – Jon Skeet May 24 '12 at 12:48
-
Yes it is Google Protocol Buffer files. I dnt knw which version it has. I want to parse *.pb files to read the contents. – Deepu May 24 '12 at 12:58
1 Answers
1
Assuming that the *.pb file is a file whose content adheres to the *.proto specification, you can generate readers for the *.pb file using the protocol buffer code Google provides: http://code.google.com/p/protobuf/
There is a tutorial provided specific for Java, on how to generate the readers and deserialize the message. Have a look at https://developers.google.com/protocol-buffers/docs/javatutorial for more details.

cello
- 5,356
- 3
- 23
- 28
-
Hi Cello thanks for ur reply. But I dont how to use *.proto and *.pb What is the process to parse *.pb files to read the contents? – Deepu May 24 '12 at 13:04
-
Hi, my 2nd link above to the java tutorial give's you all the information. When you download protobuf from google, you'll get a kind of compiler which takes your .proto file and generates java classes from it. The generated classes should also offer a `parseFrom` method which takes a FileInputStream to read it all in into Java objects. – cello May 24 '12 at 16:20