Skip to content

Problem encoding map<string, struct> #547

@nikunjy

Description

@nikunjy

This is the proto file

syntax = "proto3";
package benchmark;

message KeyStringArrMessage {
  string key = 1;
  repeated string values = 2;
}

message MyMapStringArrayMessage {
  map<string, KeyStringArrMessage> value = 1;
};

I made the struct like this

    var mapLength = 10;
    var arrayLength = 20;
    var myMap = new Object();
    for (var len = 0; len < mapLength; len++) {
      // generating again so that not be fixed
      var arrVal = generateStringArray(arrayLength, 20);
      var subMessage = KeyStringArrayMessage.create({
        key: randomString(20), values: arrVal
      });
      // fixed key
      myMap[randomString(20)] = subMessage;
    }
    // Create a new message
    var message = MyMapStringArrayMessage.create({
      value: myMap
    });
    // Encode a message
    fs.writeFileSync(my_map_string_array.binary, MyMapStringArrayMessage.encode(message).finish());

I am loading this file in golang but I don't get the same struct. Which is odd because this approach works fine for other data types. Worked for regular datatypes, string array, and well defined structs.

This leads me to believe that there is something wrong with map<> in the encoding ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions