gpt4 book ai didi

java - proto文件的不同版本

转载 作者:行者123 更新时间:2023-12-02 03:26:47 25 4
gpt4 key购买 nike

我有一个这样的原型(prototype):

message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
}

现在我必须向其中添加另一个字段,使其看起来像这样:

message Person {
required string name = 1;
required int32 id = 2;
optional string email = 3;
optional string phone = 4;
}

如果我现在反序列化使用旧版本序列化的 Person,唯一的区别是 hasPhone() 将始终为 false?因此,假设将为所有新人设置电话,我实际上可以通过 hasPhone 为真/假来区分它是否是旧/新版本的原型(prototype)?

最佳答案

是的,这是正确的。

您还可以使用 getPhone() 并检查字符串是否为空,因为空字符串是字符串类型字段的默认值。

关于java - proto文件的不同版本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38737069/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com