为什么 protobuf 需要对消息中的类型信息进行编码?
Why protobuf needs to encode the type info in the message?
我正在阅读官方 protobuf encoding 文档。它声明 protobuf 消息对消息中每个字段的类型进行编码。但是,我认为客户端也有模式 class 文件,所以客户端应该已经知道类型了。为什么 protobuf 还要发送客户端已经知道的类型信息?
它在您的链接文档中说:
When the message is being decoded, the parser needs to be able to skip fields that it doesn't recognize. This way, new fields can be added to a message without breaking old programs that do not know about them. To this end, the "key" for each pair in a wire-format message is actually two values – the field number from your .proto file, plus a wire type that provides just enough information to find the length of the following value.
(强调我的)
我正在阅读官方 protobuf encoding 文档。它声明 protobuf 消息对消息中每个字段的类型进行编码。但是,我认为客户端也有模式 class 文件,所以客户端应该已经知道类型了。为什么 protobuf 还要发送客户端已经知道的类型信息?
它在您的链接文档中说:
When the message is being decoded, the parser needs to be able to skip fields that it doesn't recognize. This way, new fields can be added to a message without breaking old programs that do not know about them. To this end, the "key" for each pair in a wire-format message is actually two values – the field number from your .proto file, plus a wire type that provides just enough information to find the length of the following value.
(强调我的)