You can only have one CodedInputStream wrapping a ZeroCopyInputStream at a
time, otherwise they will confuse each other with buffering conflicts.

CodedInputStreams are cheap to construct, so you can just make one on the
stack in a block, like:

  {
    CodedInputStream coded_input(input_stream_p.get());
    success = coded_input.ReadLittleEndian64(&size);
  }

On Tue, Dec 21, 2010 at 6:56 AM, rodrigo benenson <
rodrigo.benen...@gmail.com> wrote:

> Hello all !
> I am trying to save multiple Protocol Buffer messages into a file and then
> reading them back.
> All messages (except the first) have the same type.
>
> My code now works. But I had to use a workaround instead. The code looks as
> follows.
>
>     boost::uint64_t size;
>     const bool read_size_success =
> input_coded_stream_p->ReadLittleEndian64(&size);
>
>     bool read_data_success = false;
>
>     const bool use_zero_copy_stream = false;
>     if(use_zero_copy_stream)
>     {
>         read_data_success =
>
> data.ParseFromBoundedZeroCopyStream(input_stream_p.get(),
> static_cast<int>(size));
>     }
>     else
>     { // work around
>         std::string buffer;
>         input_coded_stream_p->ReadString(&buffer, size);
>         read_data_success = data.ParseFromString(buffer);
>     }
>
>     if (read_size_success == false or read_data_success == false)
>     {
>         throw std::runtime_error("Failed to read a data message during
> DataSequence<DataType>::read");
>     }
>
>
> The code above works fine when using  use_zero_copy_stream == falsehowever 
> when I set
> use_zero_copy_stream to true then the read fails (read_data_success ==
> false).
>
> Obviously input_coded_stream_p was constructed using input_stream_p.
>
> Why is ParseFromBoundedZeroCopyStream not working as expected ? What is
> the proper way of using it ?
>
> Thanks for your answers.
> Best regards,
> rodrigob.
>
>
>
>  --
> 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