0

I'm having these two definitions in my .proto:

// all the shards on a server
message ConfigEntry {
  repeated Shard shards = 2;
  string server = 3;
}

// information on all the groups
message QueryResponse {
  repeated ConfigEntry config = 1;
}

And in my c++ file, I have this map that I'm trying to set in QueryResponse:

std::map<std::string, std::vector<shard_t>> servers;

I can't find any way to set the values in my map to config in QueryResponse, any ideas how to do this?

Alrasheed
  • 11
  • 3

1 Answers1

0

It would be something like this:

    for (auto const &item : servers)
  {
    auto c = response->add_config();
    c->set_server(item.first);
    for (auto s : item.second)
    {
      Shard *sh = c->add_shards();
      sh->set_lower(s.lower);
      sh->set_upper(s.upper);
    }
  }

we call add_config() to get a ConfigEntry that we will set its server name, and then loop through the vector and add each shard separately.

Alrasheed
  • 11
  • 3