Thanks a lot. I got it. In my case, I will always read the compressed byte 
array back from KV store, decompress and then read fields. So, in this 
case, "random access" means Cap'N will only create the object of that field 
from unpacked message without creating the temp objects of other fields, in 
other word, all other fields will still be the flat bytes without any 
managed objects created. Is that correct?
Moreover, another question is how to write message in packed format to a 
byte array. Because I have to allocate a ByteBuffer will enough capacity to 
store the message. But it is not possible to know the packed message size 
without packing it first. Currently, I have to allocate with its unpacked 
size (computeSerializedSizeInWords * 8), then use a tricky way to trim the 
tailing zeros. Do you know if there is any better way to do this?

Thanks,
Tao

On Tuesday, December 5, 2017 at 10:53:26 AM UTC-8, Tao Wang wrote:
>
> Hi,
>
> I am working on a project which is using protobuf to encode/decode 
> messages. I am evaluating if it is worth to migrate to Cap'N proto. I am 
> using the Java implementation of Cap'N. 
> https://github.com/capnproto/capnproto-java
>
> From the documentation, https://capnproto.org/index.html, Random access 
> is mentioned as a key feature. But I am not able to find any piece of code 
> example to demonstrate this feature. Am I misunderstanding it? Does "random 
> access" simply means we can access any field without "deserializing" the 
> whole message (it actually not serialized at all if not packed)?
>
> What I thought about "random access" is Cap'N is able to read any field 
> back from disk without loading the whole bunch of message data to memory. 
> But from the java API implementation (the source code), it seems that it 
> always read the whole message back to byte buffer, getRoot and then access 
> any field. So, I guess my understanding is wrong, isn't it?
>
> Our scenario:
> Our current protobuf message schema has many fields (~100) with embedded 
> other messages. The serialized message size varies from hundreds bytes to 
> tens of kilobytes and a few large messages may over 1 megabytes. We store 
> the messages in term of compressed byte array to underlying KV store and 
> read back from KV store, uncompress and then parse to protobuf object. 
>
> In this case, do you think it is worth to migrate from protobuf to cap'N ? 
> If so, how can I benefit from "random access" feature?
>
>
> Thanks,
> Tao
>

-- 
You received this message because you are subscribed to the Google Groups 
"Cap'n Proto" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
Visit this group at https://groups.google.com/group/capnproto.

Reply via email to