簡體   English   中英

在protobuf python api中如何將元素添加到嵌套消息重復屬性?

[英]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];
}

我試過了

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

得到一個錯誤AttributeError:'property'對象沒有屬性'append'

但第一級重復現場工作正常:

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

是不是支持這種定義?

您需要使用該require類型創建一個字段,然后在代碼中訪問該字段。

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;
}

然后

raw.sub.fate.append(1)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM