'optional repeated' with google protobuf for Java

Harikrishnan picture Harikrishnan · Sep 3, 2014 · Viewed 19.1k times · Source

I am using Google Protobuf using java. I wrote a statement like

optional repeated   string  users = 9;

When I tried to compile I am getting an error like

message.proto:39:57: Missing field number.

All I wanted was to create an array of strings.

Can anybody help me to resolve it.

PS: If I avoided optional keyword then it is compiling but in java I am getting a class not found error for com.google.protobuf.ProtocolStringList

Thanks in advance

Answer

Marc Gravell picture Marc Gravell · Sep 3, 2014

All you need is:

repeated string users = 9;

You don't need the optional modifier, and it looks like it is confusing the parser. A repeated field is inherently optional: you just don't add any values.

As for com.google.protobuf.ProtocolStringList: check that the version of the .proto compiler (protoc) you are using is an exact match for the library version you are using.