lundi 18 mai 2020

c++ Inset and read Map element in protobuf3

Here is the .proto which have one map

map.proto

syntax = "proto3";

package demo;

message Person {

  map<string, int32> family_list = 4;

  }

Now I insert key and value from the Write_impl.cc

auto map = test.mutable_family_list();
string key = "faimly";
int val =20;
(*map)[key] = val;
std::cout<<"map = "<<(*map)[key]<<std::endl;

Below I read the value of key "family" in read_impl.cc

auto test = demo::Person::default_instance();
auto map = test.mutable_family_list();
std::cout<<"map = "<<(*map)["faimly"]<<std::endl;

Problem: I get 0 when reading the value of key "family"

Aucun commentaire:

Enregistrer un commentaire