本文介绍了JSON和协议缓冲区之间是否存在标准映射?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

摘录自公告博客文章:

精心制作 a 映射可能很简单,但是在两者之间是否有一个单独的明显"映射,任何两个独立的开发团队都会自然地适应?如果两个产品支持PB数据并且因为它们共享相同的.proto规范而可以互操作,我想知道如果它们独立引入相同规范的JSON反射,它们是否仍然可以互操作.可能会做出一些任意决定,例如枚举值应该用字符串(对于人类来说是典型的JSON)还是整数值来表示?

It may be trivial to cook up a mapping, but is there a single "obvious" mapping between the two that any two separate dev teams would naturally settle on? If two products supported PB data and could interoperate because they shared the same .proto spec, I wonder if they would still be able to interoperate if they independently introduced a JSON reflection of the same spec. There might be some arbitrary decisions to be made, e.g. should enum values be represented by a string (to be human-readable a la typical JSON) or by their integer value?

那么是否存在已建立的映射以及用于根据.proto规范生成JSON编码器/解码器的任何开源实现?

So is there an established mapping, and any open source implementations for generating JSON encoder/decoders from .proto specs?

推荐答案

是的,因为那里的协议缓冲区版本3.0.0(2016年7月28日发布)是"JSON中定义明确的编码,可以替代二进制协议编码" ,如发行说明中所述

Yes, since Protocol Buffers version 3.0.0 (released July 28, 2016) thereis "A well-defined encoding in JSON as an alternative to binary protoencoding" as mentioned in the release notes

https://github.com/google/protobuf/releases/tag /v3.0.0

这篇关于JSON和协议缓冲区之间是否存在标准映射?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 14:11
查看更多