Sorry, there's not a reliable way to do this unless you depend the encoder
writing the tags in order, which is not guaranteed.
One thing you could do is instead of placing an enum field inside your
message to identify the type, stick a one-byte tag on the front of the
message instead. You will have to deal with reading and writing this tag
yourself, but then you can rely on it being first byte of the message.
On Thu, Dec 11, 2008 at 8:26 AM, sorent
> I want to use Protocol Buffers in a similar way as described as "Union
> Types" in the page "Techniques" (http://code.google.com/intl/sv/apis/
> . In order to get maximum
> performance I want to check which message is actually coming before
> parsing the full buffer, so that
> I can determine with minimum CPU load if it shall be forwarded,
> discarded or parsed.
> I.e. i'm thinking of peeking into the buffer and check the value of
> the type field, or even skip the
> type field altogether and instead check the field number of the
> Is there any support for such peeking ? Or need it be a hack ... that
> must be updated if the encoding changes.
> BR /Sören
You received this message because you are subscribed to the Google Groups
"Protocol Buffers" group.
To post to this group, send email to email@example.com
To unsubscribe from this group, send email to
For more options, visit this group at