协议缓冲区如何处理版本控制? [英] How does protocol buffer handle versioning?

查看:49
本文介绍了协议缓冲区如何处理版本控制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

协议缓冲区如何处理类型版本控制?

How does protocol buffers handle type versioning?

例如,当我需要随时间更改类型定义时?就像添加和删除字段一样.

For example, when I need to change a type definition over time? Like adding and removing fields.

推荐答案

Google 设计的 protobuf 对版本控制非常宽容:

Google designed protobuf to be pretty forgiving with versioning:

  • 意外数据要么存储为扩展"(使其往返安全),要么静默删除,具体取决于实现
  • 新字段一般添加为可选",意味着旧数据可以成功加载

然而:

  • 不要重新编号字段 - 这会破坏现有数据
  • 您通常不应更改任何给定字段的存储方式(即从固定的 32 位 int 到varint")
  • do not renumber fields - that would break existing data
  • you should not normally change the way any given field is stored (i.e. from a fixed-with 32-bit int to a "varint")

一般来说,它会正常工作,而且您无需担心版本控制.

Generally speaking, though - it will just work, and you don't need to worry much about versioning.

这篇关于协议缓冲区如何处理版本控制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆