On Tue, Jul 9, 2013 at 11:36 AM, phreed <phr...@gmail.com> wrote:
>
>
> On Monday, July 8, 2013 12:59:12 PM UTC-5, Ilia Mirkin wrote:
>>
>>
>>
>> If this is not an option, you can write a custom decoder that just
>> skips over fields you don't need to read. This is a little tricky, but
>> if you're not trying to be too generic it shouldn't be that much code.
>
>
> Do you have an example decoder that can be used as a model
> for such a custom decoder?

Sadly, no. Perhaps I can poke the responsible parties for open-sourcing it.

> My situation is a bit different than the original poster.
> I have a set of content sensitive network bridges.
> Each bridge is interested in (potentially) different content and
> as such I would rather not incur parsing costs that are not needed.
>

Well, if your proto looks something like

message {
  optional Foo a = 1;
  optional Bar b = 2;
   ...
}

And each thing just needs either a or b or c etc, then it's fairly
easy. If it's more involved, then it's more difficult :)

The basic idea is that you read the tag, which includes the field
type. If it's a tag you want, you decode it, e.g. by doing
Foo.ParseFromString(). If it's not, you skip it (which you can do
based on the field type, included in the tag). There are helpers in
WireFormatLite for reading tags/skipping things. (At least for C++,
not sure how the Java parsing code is organized.)

  -ilia

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to