Data format compatibility between protobuf versions

末鹿安然 提交于 2019-12-06 02:13:36

问题


I was wondering if protocol buffer's serialized data format remains constant across protobuf compiler and client library versions.

In other words, do I need to use the same compiler version to generate my Python, Java, and C++ classes? And do these clients all need to use the same version of protobuf libraries?

This post sort of addresses my question, but its accepted answer is specific to the OP's protobuf version.


回答1:


Yes, that is pretty much the idea. It shouldn't matter which library you use, as long as it follows the spec. Note that the same data can be represented in slightly different ways, for example field order should not matter to the client, and while it is common for clients to write fields in ascending order, it is explicitly required of clients to process fields in any order. All I'm saying here is that it might not be exactly the same bytes in the same order, but it should work fine from any client.

Note that some implementations might offer additional features (*cough* like mine offers inheritance support), intended for use primarily only within that single client. In that case, I would a: expect those features to be obvious when used, and b: it should always still produce a valid protobuf stream (you might just choose to ignore those fields, or support them as bytes for the purpose of round-trip).



来源:https://stackoverflow.com/questions/6604929/data-format-compatibility-between-protobuf-versions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!