更改原型字段编号的安全性
Safeness of changing proto field number
例如,如果我从:
message Request {
int foo = 1;
}
到
message Request {
int bar = 1;
int foo = 2;
}
将 foo
从 1 更改为 2 安全吗? Docs 说不要:These numbers are used to identify your fields in the message binary format, and should not be changed once your message type is in use.
,但我想知道为什么。
如果您有第一个版本生成的消息的序列化版本,您将无法使用第二个版本的消息进行反序列化。
如果您使用 protobuf 生成模型以存储在数据库中或发布在 Apache Kafka 等代理中,则需要遵循约定。如果您使用 proto buffer 生成模型和服务供在线使用,您应该不要破坏任何东西(如果您将重新生成所有模型)
另见 reserved keyword in order to do not reuse an old numer. Further reading also here
例如,如果我从:
message Request {
int foo = 1;
}
到
message Request {
int bar = 1;
int foo = 2;
}
将 foo
从 1 更改为 2 安全吗? Docs 说不要:These numbers are used to identify your fields in the message binary format, and should not be changed once your message type is in use.
,但我想知道为什么。
如果您有第一个版本生成的消息的序列化版本,您将无法使用第二个版本的消息进行反序列化。 如果您使用 protobuf 生成模型以存储在数据库中或发布在 Apache Kafka 等代理中,则需要遵循约定。如果您使用 proto buffer 生成模型和服务供在线使用,您应该不要破坏任何东西(如果您将重新生成所有模型)
另见 reserved keyword in order to do not reuse an old numer. Further reading also here