You could use a length-delimited stream of google.protobuf.Any messages. The Any message has a URL that encodes the fully-qualified type of the message and then also the bytes of the corresponding serialized proto. When I say length-delimited, I mean prefix each message with a varint-encoded length (or fixed 32-bit length would work, too). That is a common way to define a stream of protos, and there is some library support -- at least in Java -- for the varint-encoded delimited streams.
---- *Josh Humphries* [email protected] On Sat, Apr 28, 2018 at 12:02 PM, Stefan Seefeld <[email protected]> wrote: > Hello, > > I'm trying to use protocol buffers as a means to stream data, where an > application would iteratively read messages from some input source. > Messages have different types, so to be able to call > `m.ParseFromIstream(input)` with an object `m` of appropriate type, I need > to read ahead to identify the type of the next message so I can instantiate > it. Do the IO APIs provide such a feature (I'm most interested into C++ and > Python) ? I read about different ways to handle this (using `extend` to > mimic polymorphism, mostly), I find that quite cumbersome and inefficient. > > So what's the best way to approach this ? > > Thanks, > Stefan > > -- > You received this message because you are subscribed to the Google Groups > "Protocol Buffers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at https://groups.google.com/group/protobuf. > For more options, visit https://groups.google.com/d/optout. > -- You received this message because you are subscribed to the Google Groups "Protocol Buffers" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
