"<header><MsgLen><Msg><header><MsgLen><Msg>..." is the standard form of
protobuf "repeated" data. A header value of 10 is the standard form for a
length-prefixed field with key 1. If you want to read all the objects
together, then write a wrapper message, i.e.

message animals {
    repeated animal items = 1;
}

and treat it as a single "animals" instance. If this is already what your
"animalList" is (sorry, you don't show the .proto), then you can just read
the entire stream into "animalList" - you don't need to limit it at all.

Does that help?

Marc


On 13 May 2013 19:00, <vic.li...@gmail.com> wrote:

> I have c# code which serialize an objects (using protobuf-net) and I am
> able to deserialize it in c++ using protocol buffer.
> The serialize data is the form as
> <header><MsgLen><Msg><header><MsgLen><Msg>.
> I extract it using code below
>
> OOGLE_PROTOBUF_VERIFY_VERSION; string fpath = "animal.bin";
>
> fstream input(fpath, ios::in | ios::binary);if (!input){
>     cerr << "failed to open " << fpath << endl;
>     return false;}ZeroCopyInputStream *raw_in = new 
> IstreamInputStream(&input);CodedInputStream *coded_in = new 
> CodedInputStream(raw_in);
> google::protobuf::uint32 n;
> std::string tmpStr;
> animal::animalInfo animalList;
>
> coded_in->ReadVarint32(&n);
> cout << "# " << n << endl;  //output: #10
> coded_in->ReadRaw(&tmpStr,n); //tmpStr shows data like >>1..Rat..Ch
> animalList.ParseFromArray(&tmpStr,1); //Get serialized data to animalList
>
>
> While it does the job.
>
> I am wondering what is the recommended way for doing this in protocol
> buffer. Specially I will like not to have to directly read Varint32 etc
> from "<header><MsgLen><Msg>"  to get 1 message @ a time.
> Also more importantly, how can I extract all the objects together ?
>
> Any advice here will be helpful.
> Thanks
>
>
>
>  --
> 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 protobuf+unsubscr...@googlegroups.com.
> To post to this group, send email to protobuf@googlegroups.com.
> Visit this group at http://groups.google.com/group/protobuf?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>



-- 
Regards,

Marc

-- 
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 protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at http://groups.google.com/group/protobuf?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to