简体   繁体   English

协议缓冲区中的Java HashMap

[英]Java HashMap in protocol buffer

I am new to the Google protocol buffer. 我是Google协议缓冲区的新手。 The intention is to use proto files to generate java classes that can be sent over network. 目的是使用原型文件生成可通过网络发送的Java类。 Is there a way to have java Maps in the generated classes? 有没有一种方法可以在生成的类中包含Java Maps? Any example code for it will be extremely useful. 任何示例代码将非常有用。 The generated java class should contain a member variable of type Map of key values. 生成的Java类应包含键值Map类型的成员变量。

There is an issue, regarding this in google https://code.google.com/p/protobuf/issues/detail?id=299 google https://code.google.com/p/protobuf/issues/detail?id=299中与此有关的一个问题

The last message from October 9, 2014 来自2014年10月9日的最新消息

Project Member #4 xiaof...@google.com A new syntax for map fields will be introduced to protobuf: message TestMessage { map a_map_field = 1; 项目成员#4 xiaof ... @ google.com将为protobuf引入地图字段的新语法:message TestMessage {map a_map_field = 1; } }

We are currently working on its implementation and it's supposed to be included in the next major release. 我们目前正在研究它的实现,应该将其包含在下一个主要版本中。

So either wait for new release, or implement your own tuples, with appropriate key and value structures. 因此,要么等待新版本发布,要么使用适当的键和值结构实现您自己的元组。

Look at similar question How would you encode a Map<String, Object> using Protocol Buffers? 看看类似的问题,您将如何使用协议缓冲区对Map <String,Object>进行编码?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM