I'm writing a Python app for serializing and sending protobuf3
messages. I'd like to make some sort of interactive UI that allows to choose a message and assign it on the fly. I've got a pretty big set of those messages, thus I don't want to make a get
function for every message, but make one that will work with all of them.
To get
all message fields, I can simply get all the message's attributes and choose those that are its fields, which is easy. Then, to know what type is the attribute, I use type(getattr(my_message, current_field))
. And now there is the problem. Suppose those are my messages:
message myMess1 {
//some fields
}
message myMess2 {
string some_string = 1
repeated myMess1 myMess1Field = 2
}
Now, there is no problem with assigning some_string field.
type(getattr(myMess2Instance, someStringFieldName))
returns string
, so I know to feed it with string.
But what to do with the repeated myMess1 field?
type(getattr(MyMess2Instance, myMess1FieldName))
actually returns google.protobuf.pyext._message.RepeatedCompositeContainer
, which says nothing about what type is contained in it. How can I get it?