Python 使用protobuf元素的子属性,使用重复描述的单词

Python 使用protobuf元素的子属性,使用重复描述的单词,python,protocol-buffers,Python,Protocol Buffers,比如说,, 我在proto buf中定义如下: message small{ low_id = 1; high_id = 2; } mesage middle{ repeated small small_id = 1; } message big{ middle middle_id = 1; int32 big_size = 2; } python文件: #init one example: bigExample = big() for i

比如说,, 我在proto buf中定义如下:

message small{
     low_id = 1;
     high_id = 2;
}
mesage middle{
     repeated small small_id = 1;
}
message big{
     middle middle_id = 1;
     int32 big_size = 2;
}

python文件:

#init one example:
bigExample = big()
for i in range(1,10):
    smallExample = bigExample.middle_id.small_id.add()
    smallExample.low_id = i
    smallExample.high_id = i%2

#I want to re-sort the bigExample by high_id and low_id
#but using sorted(bigExample, key=bigExample.middle_id.small_id.high_id) will report error,
#AttributeError: 'RepeatedCompositeFieldContainer' object has no attribute 'high_id'
我该怎么办

我的问题是: 1.无法引用一个重复参数的子元素
2.无论如何,除了自己实现一种排序方法外,还可以通过2个参数对重复实例进行排序?

我尝试了以下方法,似乎效果很好:

sorted(bigExample.middle_id , key=lambda x: (x.small_id.high_id, x.small_id.low_id ))

我的问题2:如何按2个参数排序现在我有了一种方法:我可以在sorted:sorted(例如,key=lambda x:x:(x[0],-x[1])中使用lambda,那么唯一的问题是:如何引用一个重复参数的子元素
bigExample.middle_id.small_id.high_id
似乎不合适。