I created a binary file using a c++ program using protocol buffers. I
had issues reading the binary file in my C# program, so I decided to
write a small c++ program to test the reading.

My proto file is as follows

message TradeMessage {
required double timestamp = 1;
required string ric_code = 2;
required double price = 3;
required int64 size = 4;
required int64 AccumulatedVolume = 5;

When writing to protocol buffer, I first write the object type, then
object length and the object itself.

coded_output->WriteLittleEndian32((int) ObjectType_Trade);

Now, when I am trying to read the same file in my c++ program i see
strange behavior.

My reading code is as follows:

cout << "Expected Size = " << objlen << endl;
cout<<" Trade message received for: "<< tMsg.ric_code() << endl;
cout << "TradeMessage Size = " << tMsg.ByteSize() << endl;

In this case, i get following output

Expected Size = 33
Trade message received for: .CSAP0104
TradeMessage Size = 42

When I write to file, I write trade.ByteSize() as 33 bytes, but when I
read the same object, the object ByteSize() is 42 bytes i.e. it is
trying to read 42 bytes. But it should be trying to read 33 bytes.
This affects the rest of the fiel reading. I am not sure what is wrong
in this. Please advice.

just to double check.. I compared the protocol buffer generated files
in my reader and writer projects. The generated files are identical.
So I guess, the file coding is different for some reason. I do not
understand why it is different.


Regards, 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 
For more options, visit this group at 

Reply via email to