A further question:
Can ProtoBuf do in-place deserialization?

Say I have a packet including a COMMAND field and a big DATA field, and 
I should only deserialize this packet to read COMMAND to decide how to process 
DATA.
The question is: does ProtoBuf copy DATA field when deserializing, and can I 
avoid that?


----- Original Message -----
From: "Henner Zeller" <henner.zel...@googlemail.com>
To: "Ashwin Jayaprakash" <ashwin.jayaprak...@gmail.com>
Cc: "Protocol Buffers" <protobuf@googlegroups.com>
Sent: 2010年 10 月 30日, 星期六 上午 8:19:02 GMT +08:00 Beijing / Chongqing / Hong Kong 
/ Urumqi
Subject: Re: [protobuf] Read selective fields without deserializing the entire 
object?

On Fri, Oct 29, 2010 at 16:13, Ashwin Jayaprakash
<ashwin.jayaprak...@gmail.com> wrote:
> Is there a way to read selective fields without deserializing the
> entire object?
>
> My serialized message is stored in memory as a (Heap)ByteBuffer.
>
> I'm trying to find out if any of the (de-)serialization frameworks
> allow a way to read specific fields without having to deserialize the
> entire message. The message has almost 200 fields - mostly Strings and
> a few long and int fields. Deserialization is expensive and creates
> too much garbage considering the fact that I just need to read 1-2
> fields.

The fields are not 'indexed' in the beginning of the message so that
it is not simple to just jump to a particular field.

What you can do is to direclty use the CodedInputStream to parse
through the message, tag by tag and only read the tags you are
interested in. As soon as you have all fields together, you can stop
reading. So it is a bit manual work involved.
Also, if you want to be faster and skip bigger parts of the message,
make sure to create sub-messages within that message, maybe there is a
logical grouping of your fields ? You can skip a sub-message at once
if you don't need it instead of iterating through all fields in it,
which is faster.

H.



>
> Thanks in advance.
>
> --
> You received this message because you are subscribed to the Google Groups 
> "Protocol Buffers" group.
> To post to this group, send email to proto...@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.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@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.




-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To post to this group, send email to proto...@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.

Reply via email to