'optional repeated' with google protobuf for Java

陌路散爱 提交于 2020-12-29 02:45:13

问题


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


回答1:


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.




回答2:


The generated file contains method for retrieving count. e.g. int getXXXCount(); One issue is that such method wouldn't be available for generated file corresponding to prior versions of the protoc def.



来源:https://stackoverflow.com/questions/25637687/optional-repeated-with-google-protobuf-for-java

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!