1

Are prototxt file compilable? Are these really the same as the .proto files?

I have read What's the different between .proto and .prototxt file and this corresponding link and also this, however no where does it describe what do with the prototxt file.

Using: protoc --proto_path=. --java_out=. test.proto I get a test.java file.

However, protoc --proto_path=. --java_out=. test.prototxt (a valid test.prototxt file, not just a renamed .proto file) does not compile. What am I missing and why is this not mentioned anywhere?

user8897013
  • 443
  • 4
  • 15

1 Answers1

1

The first call compiles the protocol structure file into a Java class that can read and write the data.

The second call attempts to compile a saved chunk of data, which is probably in the format that the test.proto describes. You can't compile serialized data into a Java class, you use the Java class from the first command to read the test.prototxt file.

Edwin Buck
  • 69,361
  • 7
  • 100
  • 138
  • I'm guessing this can be done using [TextParser](https://developers.google.com/protocol-buffers/docs/reference/java/com/google/protobuf/TextFormat.Parser.html). Also looked at [this](https://stackoverflow.com/questions/18873924/what-does-the-protobuf-text-format-look-like). On the same but different note, does your information conflict with the link in the question above, where it is explained that prototxt and proto files are the same but one is in binary and the other is in textual format? From your answer, it would seem no, in Java, I need both, the proto file in order to read the prototxt. – user8897013 Apr 18 '18 at 16:35