5
votes

I am using protobuf and grpc as interface between a client and server. The server is written in C and the client uses python to communicate to the server.

I have a message created in protobuf like below.

message value_obj {
    uint32 code = 1;
    uint32 value = 2;
}

message list_of_maps {    
    map<uint32, value_obj> mapObj1 = 1;    
    map<uint32, value_obj> mapObj2 = 2; 
}

I tried creating objects in Python like below:

obj = list_of_maps()
mapObjToStore = value_obj()
mapObjToStore.code = 10
obj.mapObj1[1].CopyFrom(mapObjToStore)

When I try to receive the message in server, I get wrong values (huge numbers!). Any help on this will be greatly appreciated.

1

1 Answers

6
votes

You can try using python dictionary for that:

map1 = {}
obj1 = value_obj()
map1[1] =  obj1
map2 = {}
listOfMaps = list_of_maps(mapObj1=map1, mapObj2=map2)