今天刚开始学习protobuf。
在学到repeadted的时候出了问题。现在将问题总结如下,以作备录。
package xmty;
option java_package = "comtwo.xmty.java";
option java_outer_classname = "PeopleTest";
message Peoples{
required int32 id = 1;
optional string sex = 2;
repeated string ppp = 3;
}
转成JAVA,后JAVA调用代码如下:
public static void main(String[] args) {
// TODO Auto-generated method stub
PeopleTest.Peoples.Builder b = PeopleTest.Peoples.newBuilder();
b.setId(1);
b.setSex(PeopleTest.Peoples.SexType.MALE.toString());
for (int i = 0; i < 10; i++) {
b.setPpp(i, "zms"+i);
}
Peoples p = b.build();
System.out.println(p);
}
时,出现错误:
Exception in thread "main" java.lang.UnsupportedOperationException
at java.util.AbstractList.set(Unknown Source)
at comtwo.xmty.java.PeopleTest$Peoples$Builder.setPpp(PeopleTest.java:692)
at comtwo.xmty.java.Test2.main(Test2.java:26)
按JAVA编程的习惯,正常的要设置某个的值时,都是使用的set来设置值。
但是,在protobu中的repeated的这个属性,要设置值,要用add。
正常代码如下:
public static void main(String[] args) {
// TODO Auto-generated method stub
PeopleTest.Peoples.Builder b = PeopleTest.Peoples.newBuilder();
b.setId(1);
b.setSex(PeopleTest.Peoples.SexType.MALE.toString());
for (int i = 0; i < 10; i++) {
b.addPpp("zms"+i);
}
Peoples p = b.build();
System.out.println(p);
}
也就是说,如果使用了set的话,就等于重写对应index的值。
因这个问题,卡了我好久的时候。且记之。
分享到:
相关推荐
SPSS Repeated measures ANOVA
博客中测试代码 【Protocol Buffer】Protocol Buffer入门教程(五):repeated限定修饰符 博客网址:https://blog.csdn.net/dengjin20104042056/article/details/102465638
repeated限定修饰符的使用,相关教程:http://blog.csdn.net/tennysonsky/article/details/73921025
Repeated Games and Reputation+Game Theor y: Analysis of Conflict+Game Theory for Applied Economists:北大光华学习资料,翁盒老师主讲 高级微观经 济专题 北大光华 翁翕老师主讲 Topics in Advanced Micro ...
Solve the following recurrence relation by repeated substitution T(n) = 2T(n/2) + n^3, T(1) = 1
测试用例
spss数据分析常用数据集:repeated.sav 统计分析及模型构建中常用的数据集; 学习软件的时候,会苦于没有数据进行实操,而其实一般分析软件都会自带数据,现在介绍如何获取SPSS软件自带的数据。 纽约时报的一篇文章...
在.stylelint.yml配置中导入插件并设置规则: plugins: - stylelint-no-repeated-nesting 规则 将blinkist/no-repeated-nesting设置为true以启用该插件。 rules: blinkist/no-repeated-nesting: true 该插件将...
Building hierarchical structures for 3D scenes with repeated elements
反复的弦乐游戏 克隆仓库后,您应该安装依赖项 npm install 你可以通过运行看到问题 npm start 在code/index.js编写您的代码 您可以在运行完成后运行测试 npm test 祝你好运
最长非重复子串没有重复字符的最长子串的长度( )
为求得类似仿真函数的黑箱函数优化问题的全部局部极值点,提出了...通过对比FRSR法与传统的均匀分配初始点法以及其他现有方法,验证了FRSR法能够以较少的初始点得到全部局部极值,在速度上和解的质量上都优于传统方法。
iReport分组报表 利用Print Repeated Values属性以及加边框实现
修剪重复修剪连续重复的子字符串: foo--bar---baz → foo-bar-baz安装$ npm install trim-repeated用法import trimRepeated from 'trim-repeated' ;trimRepeated ( 'foo--bar---baz' , '-' ) ;//=> 'foo-bar-baz'...
安装 : npm install retext-repeated-words用假设我们有以下文件example.txt : Well, it it doesn’t have to to be. Like a fish in thethe sea.…我们的脚本example.js如下所示: var vfile = require ( 'to-...
matlab程序,使用压缩感知的方法,在长期纵向的MRI中利用之前扫描结果的相似性快速成像
Planning Repeated Degradation Testing for Products With Three-Source Variability
定义protobuf文件(包含enum,message,required,optional,repeated, 结构体定义中引用另一个结构体), 生成java文件,能够构建java对象,并转化为字节byte或者流,能够将流或字节转化为对象
Defending Against Man-In-The-Middle Attack in Repeated Games
matlab开发-RepeatedMeasuresANOVA。单因素重复测量一个或多个样本的方差分析。