协议缓冲区中的字典 [英] Dictionary in protocol buffers

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

问题描述

有没有办法使用协议缓冲区序列化字典,或者如果需要,我必须使用 Thrift?

Is there any way to serialize a dictionary using protocol buffers, or I'll have to use Thrift if I need that?

推荐答案

Protobuf 规范现在 本机支持字典(地图).

Protobuf specification now supports dictionaries (maps) natively.

人们通常将字典写成键值对列表,然后在另一端重建字典.

People typically write down the dictionary as a list of key-value pairs, and then rebuild the dictionary on the other end.

message Pair {
   string key = 1;
   string value = 2;
}

message Dictionary {
   repeated Pair pairs = 1;
}

这篇关于协议缓冲区中的字典的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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