给出一个原型定义
message EndpointResult {
int32 endpoint_id = 1;
// property id as key
map<int32, TimeSeries> properties = 2;
}
message TimeSeries {
repeated TimeEntry value = 2;
}
message TimeEntry {
int32 time_unit = 1;
float value = 2;
}
我希望在EndpointResult类中填充映射。我尝试过docs中建议的不同方法,但都给我带来了一个错误。在
设置测试类
^{pr2}$然后尝试不同的方法:
end_point_rslt.properties[0] = ts
ValueError: Direct assignment of submessage not allowed
end_point_rslt.properties[0].submessage_field = ts
AttributeError: Assignment not allowed (no field "submessage_field" in protocol message object).
end_point_rslt.properties.get_or_create(0)
end_point_rslt.properties[0] = ts
ValueError: Direct assignment of submessage not allowed
end_point_rslt.properties.get_or_create(0)
end_point_rslt.properties[0].submessage_field = ts
AttributeError: Assignment not allowed (no field "submessage_field" in protocol message object).
end_point_rslt.properties = {0 : ts}
AttributeError: Assignment not allowed to repeated field "properties" in protocol message object.
end_point_rslt.properties.get_or_create(0)
end_point_rslt.properties = {0 : ts}
TypeError: Can't set composite field
任何在python中使用协议缓冲区映射的例子都将不胜感激!
在看了这些文档之后,我意识到问题是我给字典分配了一个类。在
正确的语法是
相关问题 更多 >
编程相关推荐