This seems like a basic question but i have doubts maybe because i am using 2 different libraries to write and read the data. My Write program is written in c++ which uses google’s protocol buffer library. My reader is implemented in .NET c#.
In write program, i write a file header as follows.
coded_output->WriteLittleEndian32(BIN_START_MAGIC_NUMBER);
coded_output->WriteLittleEndian32(major_version);
coded_output->WriteLittleEndian32(minor_version);
coded_output->WriteVarint32(strlen(_region));
coded_output->WriteRaw(_region, strlen(_region));
coded_output->WriteLittleEndian32(_offset);
What is the corresponding function in C# to read the above fields? I understand how to read the protocol buffer messages but not sure about how to read above data.
Regards,
Alok
That file header is not a valid protobuf sequence, and consequently the standard reading mechanisms in protobuf-net won’t be geared to reading it – indeed, a
ProtoReaderwould not let itself get into a state to read that, since it is invalid. However! To read a little-endian 32-bit number, you can probably use:Assuming that the coded stream is using standard protobuf conventions, the string is written as a varint length-prefix and then UTF-8, so you could use:
I can probably package those more conveniently for you if you really want; they aren’t exposed currently because that isn’t protobuf ;p