JSON和协议缓冲区之间是否存在标准映射? [英] Is there a standard mapping between JSON and Protocol Buffers?

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

问题描述

摘录自公告博客文章:

关于JSON:JSON是结构化的 与协议缓冲区类似,但是 协议缓冲区二进制格式仍然是 更小,更快的编码. JSON格式 为 协议缓冲区-虽然 编写编码器/解码器很简单 转换任意协议 使用来往于JSON的消息 原虫反射.这很好 与AJAX应用进行通信的方式, 因为使用户下载完整 他们访问您时的protobuf解码器 页面可能太多.

Regarding JSON: JSON is structured similarly to Protocol Buffers, but protocol buffer binary format is still smaller and faster to encode. JSON makes a great text encoding for protocol buffers, though -- it's trivial to write an encoder/decoder that converts arbitrary protocol messages to and from JSON, using protobuf reflection. This is a good way to communicate with AJAX apps, since making the user download a full protobuf decoder when they visit your page might be too much.

精心制作 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) there is "A well-defined encoding in JSON as an alternative to binary proto encoding" as mentioned in the release notes

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

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

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