Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

in protobuf python api how to add element to nested message repeated property?

message items {
    message require {
        optional bool require_sex = 1; //
        repeated int32 fate = 2 [packed = true];
    }
    optional int32 sub_type = 1;
    repeated int32 levels = 2 [packed = true];
}

I tried

raw.require.require_sex = 1
raw.require.fate.append(1)
raw.require.fate.extend([2,3])

got an error AttributeError: 'property' object has no attribute 'append'

but the first level repeated field works fine:

raw = down_pb2.items()
raw.levels.append(4)

is this kind of definition not supported?

like image 636
davyzhang Avatar asked Mar 12 '26 14:03

davyzhang


1 Answers

You need to create a field using that require type and then access that field in the code.

message items {
    message require {
        optional bool require_sex = 1; //
        repeated int32 fate = 2 [packed = true];
    }
    optional int32 sub_type = 1;
    repeated int32 levels = 2 [packed = true];
    required require sub = 3;
}

then

raw.sub.fate.append(1)
like image 127
iny Avatar answered Mar 14 '26 05:03

iny



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!