12

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 Answer 1

9

You can try using python dictionary for that:

map1 = {}
obj1 = value_obj()
map1[1] =  obj1
map2 = {}
listOfMaps = list_of_maps(mapObj1=map1, mapObj2=map2)
Sign up to request clarification or add additional context in comments.

2 Comments

what is dat func? list_of_maps(). Should I import it from somewhere?
@mrmailperson It's proto message from the question: message list_of_maps {

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.