Yes, this behavior is normal. The wire format is not self delimiting, so
there's no way to tell when one message ends and another starts.
http://code.google.com/apis/protocolbuffers/docs/techniques.html#streaming
As you mentioned, you can use ParseFromBoundedZeroCopyStream to restrict the
number of bytes read.

On Fri, Sep 24, 2010 at 5:42 AM, Greg Burri <greg.bu...@gmail.com> wrote:

> Re,
>
> Ok, I tried with the default implementation
> 'google::protobuf::io::FileInputStream' and the result is the same, so
> I think the described behavior in my first email is correct... but I
> don't understand why!?
>
> /Greg
>
> On Sep 24, 2:32 pm, Greg Burri <greg.bu...@gmail.com> wrote:
> > Hi everyone,
> >
> > I wrote my own 'ZeroCopyInputStream' class and did some tests :
> >
> > I serialize two protocol buffer messages in a file and then I read
> > them (usually it's not a file, it's a special device but for the tests
> > it is).
> >
> > Here is my proto file :
> >    message Hash {
> >       optional bytes hash = 1; // Always 20 bytes.
> >    }
> >
> > The first hash is "2C 58 3D 41 4E 4A 9E B9 56 22 82 09 B3 67 E4 8F 59
> > 07 8A 4B"
> > My second one is "5C 9C 37 41 BD ED 23 1F 84 B8 A8 20 0E AF 3E 30 A9
> > C0 A9 51"
> >
> > The serialization process is correct and my file look-like :
> > 0a 14 2c 58 3d 41 4e 4a 9e b9 56 22 82 09 b3 67 e4 8f 59 07 8a 4b 0a
> > 14 5c 9c 37 41 bd ed 23 1f 84 b8 a8 20 0e af 3e 30 a9 c0 a9
> >
> > Then, I try to read back my first hash with 'ParseFromZeroCopyStream'.
> > 'Next(const void** data, int* size)' from my own class will be called
> > and a buffer to the data will be returned with a size of 44 (the
> > entire file), everything fine until now.
> > The issue is the hash returned is not the first but the last :  "5C 9C
> > 37 41 BD ED 23 1F 84 B8 A8 20 0E AF 3E 30 A9 C0 A9 51" and there is no
> > call at all to 'BackUp(int count)'!
> >
> > Is this behavior is normal ? Do I have to use
> > 'ParseFromBoundedZeroCopyStream' instead ?
> >
> > The documentation[1] says "If successful, the entire input will be
> > consumed." but with no more details, why ?
> >
> > [1] :
> http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google...
> >
> > /Greg
>
> --
> 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<protobuf%2bunsubscr...@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