proro文件
syntax = "proto3";
message TestRequest {
# 修饰符 类型 字段名 序号
repeated int32 ids = 1;
}
ids的类型是int32,然后被repeated修饰,即这个字段是可重复赋值的。
错误示例:
request = TestRequest()
request.ids = [0]
报错
AttributeError: Assignment not allowed to repeated field “ids” in protocol message object.
正确方法:
request = TestRequest()
request.ids.append(1)
将被repeated修饰的字段看作是一个空列表,往里面添加值即可