是否允许取消弃用 protobuf 字段?

Is un-deprecating a protobuf field allowed?

我们有一个 protobuf 类型,我们在其中添加了一个字段,然后从未使用它实现功能(因此 [deprecated=true] 暗示不应使用它)。几年后,时间到了,现在我们确实毕竟想要使用那个领域。

仅删除 [deprecated=true] 并开始使用该字段是否安全,或者这可能会破坏任何东西吗?

另一个消息中已经存在具有相同类型和语义的字段,因此最好使用我们最初给它起的名称,而不是添加一个新字段并用两个相似的字段来膨胀定义。

编辑:proto3 language guide section on options 是这样说的:

deprecated (field option): If set to true, indicates that the field is deprecated and should not be used by new code. In most languages this has no actual effect. In Java, this becomes a @Deprecated annotation. In the future, other language-specific code generators may generate deprecation annotations on the field's accessors, which will in turn cause a warning to be emitted when compiling code which attempts to use the field. If the field is not used by anyone and you want to prevent new users from using it, consider replacing the field declaration with a reserved statement.

您的客户唯一会 "notice" 的是 Java 中缺少弃用警告,如果他们仍在使用已弃用的字段,他们可能已经习惯了。自 proto3 以来,所有字段都是可选的,因此这不会破坏任何内容。