[protobuf] Re: nested message not read properly. (_has_bits is not set?)

2011-12-21 Thread alok
The issue is resolved now.

Made the same mistake which I did in the past. Forgot to open the file
in the binary mode. It encountered an early eof cuz of text mode. Now
its working fine.

thanks,
Alok

On Dec 22, 11:25 am, alok  wrote:
> On further investigation, looks like the issue could be due to the
> limits.
>
> I have following code
>
> 
>     lim = coded_input->PushLimit(objlen);
>     cMsg.ParseFromCodedStream(coded_input);
>     coded_input->PopLimit(lim);
>     cmsgsize = cMsg.ByteSize();
> 
>
> Above, the value of objlen is 44.
> The length of cMsg should have been 44 bytes (including header
> message) but when I check cMsg.ByteSize(), it returns value 20.
> Its reading only 20 bytes instead of 44 bytes.
>
> inside PushLimit() function,
>
> buffer_end_ += buffer_size_after_limit_;
>
> value of buffer_size_after_limit_ is 0 and buffer_end_ ends after 20
> bytes only reading partial message.
>
> Help me investigate this issue further.
>
> Regards,
> Alok
>
> On Dec 22, 10:49 am, alok  wrote:
>
>
>
>
>
>
>
> > Apologies for incorrect values of _has_bits in my prev message. Those
> > were the addresses of the variable _has_bits.
>
> > But the behvaior of the _has_bits is same. When I initialize the
> > header while writing using cMsg.mutable_header(), it sets the 3rd bit
> > in _has_bits and the value of _has_bits is 7 ( = 0x0111). But when I
> > read the cMsg in my reader program, value of _has_bits is 3 ( =
> > 0x0011) 3rd bit is not set and hence the header message is not read.
>
> > I am further looking into the code to understand why this bit is not
> > set.
>
> > Appreciate it if you could tell me what am I doing wrong in this case.
>
> > Regards,
> > Alok
>
> > On Dec 22, 10:07 am, alok  wrote:
>
> > > Hi,
>
> > >  I have a nested message that i am trying to read using protocol
> > > buffers. Message looks like as below
>
> > > 
>
> > > message HeaderMessage {
> > >   required double timestamp = 1;
> > >   required string ric_code = 2;
> > >   required int32 count = 3;
> > >   required int32 total_message_size = 4;
>
> > > }
>
> > > message CustomMessage {
> > >   required string field_name = 1;
> > >   required double value = 2;
> > >   optional HeaderMessage header = 3;
>
> > > }
>
> > > 
>
> > > Here, I am setting the header field in the CustomMessage and writting
> > > the custom message to binary output file. I know for sure that the
> > > message is written properly to the binary file because I am able to
> > > retrive it properly using the C# library (protobuf-net) to read the
> > > binary file.
>
> > > I am trying to read the same file using C++ protocol buffers library.
> > > But when i read the object from coded_stream
>
> > > cMsg.ParseFromCodedStream(coded_input);
>
> > > I see that the header is not set in the cMsg.
>
> > > I looked inside protocol buffers library. While reading the object, it
> > > checks for if header is set or not using the following function
>
> > > inline bool CustomMessage::has_header() const {
> > >   return (_has_bits_[0] & 0x0004u) != 0;
>
> > > }
>
> > > Above function returns false and header object is not read.
>
> > > When I am writing the object to binary file, value of _has_bits was
> > > 0x00fb6ff8 but when I am reading the custom message from the binary
> > > file, this time the value of _has_bits is unchanged before and after
> > > reading the object. This value is 0x0012fbcc.  For this value,
> > > has_header() function returns false.
>
> > > so when I call ParseFromCodedStream function, _has_bits value is not
> > > read properly causing a problem in reading header object.
>
> > > What am I doing wrong in this case? How to resolve this issue?
>
> > > Thanks for your help.
>
> > > -Alok

-- 
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.



[protobuf] Re: nested message not read properly. (_has_bits is not set?)

2011-12-21 Thread alok
On further investigation, looks like the issue could be due to the
limits.

I have following code


lim = coded_input->PushLimit(objlen);
cMsg.ParseFromCodedStream(coded_input);
coded_input->PopLimit(lim);
cmsgsize = cMsg.ByteSize();


Above, the value of objlen is 44.
The length of cMsg should have been 44 bytes (including header
message) but when I check cMsg.ByteSize(), it returns value 20.
Its reading only 20 bytes instead of 44 bytes.

inside PushLimit() function,

buffer_end_ += buffer_size_after_limit_;

value of buffer_size_after_limit_ is 0 and buffer_end_ ends after 20
bytes only reading partial message.

Help me investigate this issue further.

Regards,
Alok

On Dec 22, 10:49 am, alok  wrote:
> Apologies for incorrect values of _has_bits in my prev message. Those
> were the addresses of the variable _has_bits.
>
> But the behvaior of the _has_bits is same. When I initialize the
> header while writing using cMsg.mutable_header(), it sets the 3rd bit
> in _has_bits and the value of _has_bits is 7 ( = 0x0111). But when I
> read the cMsg in my reader program, value of _has_bits is 3 ( =
> 0x0011) 3rd bit is not set and hence the header message is not read.
>
> I am further looking into the code to understand why this bit is not
> set.
>
> Appreciate it if you could tell me what am I doing wrong in this case.
>
> Regards,
> Alok
>
> On Dec 22, 10:07 am, alok  wrote:
>
>
>
>
>
>
>
> > Hi,
>
> >  I have a nested message that i am trying to read using protocol
> > buffers. Message looks like as below
>
> > 
>
> > message HeaderMessage {
> >   required double timestamp = 1;
> >   required string ric_code = 2;
> >   required int32 count = 3;
> >   required int32 total_message_size = 4;
>
> > }
>
> > message CustomMessage {
> >   required string field_name = 1;
> >   required double value = 2;
> >   optional HeaderMessage header = 3;
>
> > }
>
> > 
>
> > Here, I am setting the header field in the CustomMessage and writting
> > the custom message to binary output file. I know for sure that the
> > message is written properly to the binary file because I am able to
> > retrive it properly using the C# library (protobuf-net) to read the
> > binary file.
>
> > I am trying to read the same file using C++ protocol buffers library.
> > But when i read the object from coded_stream
>
> > cMsg.ParseFromCodedStream(coded_input);
>
> > I see that the header is not set in the cMsg.
>
> > I looked inside protocol buffers library. While reading the object, it
> > checks for if header is set or not using the following function
>
> > inline bool CustomMessage::has_header() const {
> >   return (_has_bits_[0] & 0x0004u) != 0;
>
> > }
>
> > Above function returns false and header object is not read.
>
> > When I am writing the object to binary file, value of _has_bits was
> > 0x00fb6ff8 but when I am reading the custom message from the binary
> > file, this time the value of _has_bits is unchanged before and after
> > reading the object. This value is 0x0012fbcc.  For this value,
> > has_header() function returns false.
>
> > so when I call ParseFromCodedStream function, _has_bits value is not
> > read properly causing a problem in reading header object.
>
> > What am I doing wrong in this case? How to resolve this issue?
>
> > Thanks for your help.
>
> > -Alok

-- 
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.



[protobuf] Re: nested message not read properly. (_has_bits is not set?)

2011-12-21 Thread alok
Apologies for incorrect values of _has_bits in my prev message. Those
were the addresses of the variable _has_bits.

But the behvaior of the _has_bits is same. When I initialize the
header while writing using cMsg.mutable_header(), it sets the 3rd bit
in _has_bits and the value of _has_bits is 7 ( = 0x0111). But when I
read the cMsg in my reader program, value of _has_bits is 3 ( =
0x0011) 3rd bit is not set and hence the header message is not read.

I am further looking into the code to understand why this bit is not
set.

Appreciate it if you could tell me what am I doing wrong in this case.

Regards,
Alok


On Dec 22, 10:07 am, alok  wrote:
> Hi,
>
>  I have a nested message that i am trying to read using protocol
> buffers. Message looks like as below
>
> 
>
> message HeaderMessage {
>   required double timestamp = 1;
>   required string ric_code = 2;
>   required int32 count = 3;
>   required int32 total_message_size = 4;
>
> }
>
> message CustomMessage {
>   required string field_name = 1;
>   required double value = 2;
>   optional HeaderMessage header = 3;
>
> }
>
> 
>
> Here, I am setting the header field in the CustomMessage and writting
> the custom message to binary output file. I know for sure that the
> message is written properly to the binary file because I am able to
> retrive it properly using the C# library (protobuf-net) to read the
> binary file.
>
> I am trying to read the same file using C++ protocol buffers library.
> But when i read the object from coded_stream
>
> cMsg.ParseFromCodedStream(coded_input);
>
> I see that the header is not set in the cMsg.
>
> I looked inside protocol buffers library. While reading the object, it
> checks for if header is set or not using the following function
>
> inline bool CustomMessage::has_header() const {
>   return (_has_bits_[0] & 0x0004u) != 0;
>
> }
>
> Above function returns false and header object is not read.
>
> When I am writing the object to binary file, value of _has_bits was
> 0x00fb6ff8 but when I am reading the custom message from the binary
> file, this time the value of _has_bits is unchanged before and after
> reading the object. This value is 0x0012fbcc.  For this value,
> has_header() function returns false.
>
> so when I call ParseFromCodedStream function, _has_bits value is not
> read properly causing a problem in reading header object.
>
> What am I doing wrong in this case? How to resolve this issue?
>
> Thanks for your help.
>
> -Alok

-- 
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.