【发布时间】:2020-02-03 15:16:07
【问题描述】:
我收到以下消息:
message Message {
int64 id = 1;
google.protobuf.FloatValue weight = 2;
google.protobuf.FloatValue override_weight = 3;
}
我希望将重量和 override_weight(可选字段)的类型更改为 google.protobuf.DoubleValue,所以我所做的是以下内容:
message Message {
int64 id = 1;
oneof weight_oneof {
google.protobuf.FloatValue weight = 2 [deprecated=true];
google.protobuf.DoubleValue double_weight = 4;
}
oneof override_weight_oneof {
google.protobuf.FloatValue override_weight = 3 [deprecated=true];
google.protobuf.DoubleValue double_override_weight = 5;
}
}
我的问题是,假设我有旧消息是由以前的 protobuff 消息编译器为旧消息编译的,我能否将它们解析为新消息? 文档对此非常模糊:
“将可选字段移入或移出 oneof:在消息被序列化和解析后,您可能会丢失一些信息(某些字段将被清除)。但是,您可以安全地将单个字段移入新的 oneof 和如果知道只设置了一个字段,则可以移动多个字段。”
以前有人试过吗?这种情况的最佳做法是什么?
【问题讨论】:
标签: python-3.x protocol-buffers proto