Streaming different types of messages
If I understand correctly there is no good way to use proto buffers to stream different types of messages, right? For example if my stream has a mix of several messages of type m1 and m2, I will have to device a scheme outside of proto buffers to separate it into 2 streams and then pass it through parsers for each. In other words is there a way to do event based parsing using proto buffers, or even a way to say don't parse a repetitive field unless needed. --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: Streaming different types of messages
On Mar 27, 1:32 pm, achin...@gmail.com wrote: If I understand correctly there is no good way to use proto buffers to stream different types of messages, right? For example if my stream has a mix of several messages of type m1 and m2, I will have to device a scheme outside of proto buffers to separate it into 2 streams and then pass it through parsers for each. In other words is there a way to do event based parsing using proto buffers, or even a way to say don't parse a repetitive field unless needed. No, you don't have to do it into separate streams. Instead, stream a sequence of messages each of which has either an m1, or an m2, or an m3 etc. This basically ends up being (tag) (message) (tag) (message), where the tag is effectively identifying the type of message. All you need to do is create the wrapper message, and the rest should work fine. Jon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: Streaming different types of messages
Kenton, I don't suppose there'd ever be a way to mark a set of fields as mutually exclusive? -dave On Mar 27, 8:42 am, Jon Skeet sk...@pobox.com sk...@pobox.com wrote: On Mar 27, 1:32 pm, achin...@gmail.com wrote: If I understand correctly there is no good way to use proto buffers to stream different types of messages, right? For example if my stream has a mix of several messages of type m1 and m2, I will have to device a scheme outside of proto buffers to separate it into 2 streams and then pass it through parsers for each. In other words is there a way to do event based parsing using proto buffers, or even a way to say don't parse a repetitive field unless needed. No, you don't have to do it into separate streams. Instead, stream a sequence of messages each of which has either an m1, or an m2, or an m3 etc. This basically ends up being (tag) (message) (tag) (message), where the tag is effectively identifying the type of message. All you need to do is create the wrapper message, and the rest should work fine. Jon --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---
Re: Streaming different types of messages
achin...@gmail.com writes: Thanks. Also how do I know the type of the message? One way would be to check all optional fields (each represent a different type of message) of the wrapper message and then pick the one which is not null. Is that the only way? You can add a (required) field to indicate the intended contents of the message, as described at http://code.google.com/apis/protocolbuffers/docs/techniques.html#union Note that Protocol Buffers will not enforce the business rule that the message's declared type and actual content must match, but it is straightforward to create a wrapper that will do that. Michael Poole --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups Protocol Buffers group. To post to this group, send email to protobuf@googlegroups.com To unsubscribe from this group, send email to protobuf+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/protobuf?hl=en -~--~~~~--~~--~--~---