使用 google protobuf for Java 的“可选重复" [英] 'optional repeated' with google protobuf for Java
问题描述
我正在使用 Java 使用 Google Protobuf.我写了一个像
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.
谁能帮我解决一下.
PS:如果我避免了可选关键字,那么它正在编译,但在 Java 中,我收到 com.google.protobuf.ProtocolStringList
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
提前致谢
推荐答案
您只需要:
repeated string users = 9;
您不需要 optional
修饰符,它看起来像混淆了解析器.repeated
字段本质上是optional
:您只是不添加任何值.
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.
至于 com.google.protobuf.ProtocolStringList
:检查您使用的 .proto 编译器 (protoc) 的版本是否与您使用的库版本完全匹配.
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.
这篇关于使用 google protobuf for Java 的“可选重复"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!