The following are the contents of the Google Protocol Buffer (.proto) file
message First
{
required uint32 field1 = 1;
optional MessageType1 request = 2;
}
message MessageType1
{
}
I want to set the MessageType1 field request. But I get this as an error:
AttributeError: Assignment not allowed to composite field "request" in protocol message object.
How to set the value of this empty message in Python?
Got this in the source code of Message class in Proto Buffer.
def SetInParent(self):
"""Mark this as present in the parent.
This normally happens automatically when you assign a field of a
sub-message, but sometimes you want to make the sub-message
present while keeping it empty. If you find yourself using this,
you may want to reconsider your design."""
So the way to set such an empty message is to call this function:
first.request.SetInParent()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With