Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

protoc producing invalid java code

I've been using protobuf to generate intra-backend messages but when I moved to a new laptop and set up protoc again it seems it doesn't generate working java code anymore.

I'm on the latest Ubuntu 16.04 and have downloaded the latest protoc

$ protoc --version
libprotoc 3.5.1

Building it, without errors or warnings, with

protoc --java_out=<javapath> --python_out=<pythonpath> messages.proto

The messages shown by Eclipse / maven are these:

The method parseUnknownFieldProto3(CodedInputStream, UnknownFieldSet.Builder, ExtensionRegistryLite, int) is undefined for the type MessageA.Request    Messages.java   ...path, line etc...

snip, more of the same for other messages

Messages.Shutdown   Messages.java   ...path...
The method setUnknownFieldsProto3(UnknownFieldSet) is undefined for the type GeneratedMessageV3.Builder<Messages.Request.Builder>   Messages.java   ...path, line etc...

snip, more of the same

If I manually rename parseUnknownFieldProtoc3 to parseUnknownField and same for SetUnknownFields the error goes away but that feels like the wrong solution.

What am I missing?

like image 697
dutt Avatar asked Jan 26 '18 08:01

dutt


People also ask

How do I create a Java proto file?

The protocol buffer compiler produces Java output when invoked with the --java_out= command-line flag. The parameter to the --java_out= option is the directory where you want the compiler to write your Java output. For each . proto file input, the compiler creates a wrapper .

What is .proto file in Java?

proto file are simple: you add a message for each data structure you want to serialize, then specify a name and a type for each field in the message. Here is the . proto file that defines your messages, addressbook. proto .

What does protoc compiler do?

proto files), the code that the proto compiler generates to interface with data, language-specific runtime libraries, and the serialization format for data that is written to a file (or sent across a network connection).

What is protoc file?

protoc is a compiler for protocol buffers definitions files. It can can generate C++, Java and Python source code for the classes defined in PROTO_FILE.


1 Answers

It sounds like you're using mismatched generated code and library code. If you're using protoc 3.5.1 you need the library code from 3.5.1; alternatively, if you're using library 3.3.0 - you need the protoc from 3.3.0.

All the releases are here, with 3.5.1 and 3.3.0

like image 152
Marc Gravell Avatar answered Oct 01 '22 22:10

Marc Gravell