How would you encode a Map using Protocol Buffers?

后端 未结 1 1687
难免孤独
难免孤独 2021-02-13 03:09

I\'m trying to use Protocol Buffers for message serialization.

My message format should contain Map< String, Object > entries ... but how do I write the .proto defini

相关标签:
1条回答
  • 2021-02-13 04:07

    I'd model a tuple with a key and a value (probably one value field per type that the value could be). Then just have a repeated list of that tuple type. You'd need to build the map itself in code.

    When you say you can't specify the types - what sort of types are you talking about? If you have an optional field of each type in the tuple, then that would cope for all the primitives - and you could map messages by serializing them into a byte string.

    It sounds like the level of "unstructure" you have may not be a good fit for PB though.

    0 讨论(0)
提交回复
热议问题