HI all

On Sun, Jun 12, 2011 at 11:58 PM, Kavi <targetn...@gmail.com> wrote:

> I have this simple .proto file:
>
> package test;
>
> message Person {
>        required string name = 1;
>        required int32 age = 2;
> }
>
> I have this test file to write contents:
>
> #include <iostream>
> #include <fstream>
> #include <string>
> #include "test.pb.h"
> #include <stdio.h>
> using namespace std;
>
> int main(){
>
>        string data,dummy;
>        test::Person kavi;
>        kavi.set_name("Kavi");
>        kavi.set_age(22);
>        ofstream out;
>        out.open("data.dat");
>
>
>        kavi.SerializeToString(&data);
>        out<<data<<endl;
>        out.close();
>
>        ifstream in;
>        in.open("data.dat");
>        in>>dummy;
>        cout<<dummy<<endl;
>        cout<<data<<endl;
>
>        test::Person second;
>        second.ParseFromString(data);
>        cout<<second.name();
>        cout<<"\n";
>        cout<<second.age();
>        in.close();
>
>
>        return 0;
>        }
>
> When I tried to compile this, it works fine. But when I change the
> line second.ParseFromString(data) to second.ParseFromString(dummy), it
> compiles fine and on executing, it throws the following error:
>
> "libprotobuf ERROR google/protobuf/message_lite.cc:123] Can't parse
> message of type "test.Person" because it is missing required fields:
> name, age"
>
> Basically the strings dummy and data are the same. So why does it
> throw the error?? Somebody please suggest a fix.
>
> Thanks in advance,
> Kavi
>
> --
> You received this message because you are subscribed to the Google Groups
> "Protocol Buffers" group.
> To post to this group, send email to protobuf@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 protobuf@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