2

I am new to the Google protocol buffer. The intention is to use proto files to generate Java classes that can be sent over the network. Is there a way to have Java Maps in the generated classes? Any example code for it will be extremely useful. The generated Java class should contain a member variable of type Map of keys and values.

2
  • No, not in the current version. Commented Oct 27, 2014 at 4:34
  • Thanks for the version. Idea on when it will be available? Commented Oct 27, 2014 at 7:12

2 Answers 2

2

There is an issue, regarding this in google https://code.google.com/p/protobuf/issues/detail?id=299

The last message from October 9, 2014

Project Member #4 [email protected] A new syntax for map fields will be introduced to 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?

Sign up to request clarification or add additional context in comments.

Comments

0

To folks visiting this page looking on how to add Map into protocol buffers. In proto version 3, map has been added and you can use it as demonstrated below:

The Koltin class:

data class Person(
    val name : String,
    val badges : Map<String, String>
)

The .proto file:

syntax = "proto3";

message Person {
  string name = 1;
  map<string, string> badges = 2;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.