On Tue, Jul 9, 2013 at 4:36 PM, phreed <[email protected]> wrote:
> On Tuesday, July 9, 2013 1:51:51 PM UTC-5, Ilia Mirkin wrote:
>> On Tue, Jul 9, 2013 at 11:36 AM, phreed <[email protected]> wrote:
>> > 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.)
>
>
> https://code.google.com/p/protobuf/source/browse/trunk/java/src/main/java/com/google/protobuf/WireFormat.java?r=349
> Looks like the thing I need for java.
> Thanks

You may also want to glance at AbstractMessage.mergeFrom and
mergeFieldFrom. Basically you'd only call the mergeFieldFrom logic for
fields you care about, and just skip over the correct number of bytes
for the ones you don't care about (for which you still need
mergeFieldFrom-style logic, of course).

  -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 [email protected].
To post to this group, send email to [email protected].
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