"Dynamic" messages

120 views
Skip to first unread message

Tomas Kislan

unread,
Jun 3, 2012, 2:56:32 AM6/3/12
to Protocol Buffers
Hello,
i have little problem with "dynamic" messages
as i want to send with required message_type, and according to that
type i want to send different nested message along it

example:

message Message {
required int64 type = 1;

optional NestedMessage = 20;
optional AnotherNestedMessage = 21;
}

now those nested messages have some required fields, but themselves
are optional in message

so lets say if type == 1 i want to send NestedMessage, if type == 2
AnotherNestedMessage
but if i dont fill both messages, i get protobuf fatalexception that
the fields from the nested message, i dont want to use atm, are
missing

and thats kinda unwanted behaviour for me and i ask:
is there a possible solution how to overcome this?
or another way how to do different types of nested messages?
Thank you

Jason Hsueh

unread,
Jun 4, 2012, 6:56:03 PM6/4/12
to Tomas Kislan, Protocol Buffers
Required-field checking is only recursively applied when a message is present. If your top-level Message only contains NestedMessage, the initialization code should not be checking the AnotherNestedMessage field to make sure that that submessage has all required fields populated. Can you provide a reproduction demonstrating the exception?


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Tomas Kislan

unread,
Jun 6, 2012, 5:41:55 AM6/6/12
to prot...@googlegroups.com
Sorry for your time, I had a bug in my code and found it after I revisited it again.
Its working just like you said
Thanks
To unsubscribe from this group, send email to protobuf+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages