SWI-Prolog / contrib-protobufs

An interface to Google Protocol Buffers (protobuf)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Map" has no special support

kamahen opened this issue · comments

"Map" has no special support. You can do "map" fields, but it's a bit klunky; instead of something like this:

'.MapMessage'{number_ints: _{one:1, two:2}}

you need to do

'.MapMessage'{number_ints:[
    '.MapMessage.NumberIntsEntry'{key:"two",value:2},
    '.MapMessage.NumberIntsEntry'{key:"one",value:1}]}

There are a few reasons for not supporting "map" right now. The biggest one is: what representation should be done for the map?

  • dict
  • library(pairs) - key-value list
  • library(assoc)
  • library(rbtrees)
  • others?

"Dict" only allows atoms and integers for the keys (and the current library(protobufs) code doesn't convert between atoms and string). The other choices have different APIs and performance characteristics. Also, library(pairs) raises the question of ordering and whether it's significant.

For the short term, the best solution is probably a "helper" predicate that translates between the various representations and the protobuf "map". This shouldn't be difficult to write, but I don't feel like doing it until it's actually needed.

Partial support added with a4f806c