Sanil P S wrote: > Hi All, > > I am writing a parser for incoming packets > of a protocol. The fields are interpreted > binary. ie; 4 bytes for an int,character single byte, > string values/text > values are parsed until end of string is reached > and so on. > > I used a char* and allocated the incoming size > dynamically, for receiving the incoming packet. > Parsed the byte array using string methods. > I tried using some byte array implementations > like QByteArray of Qt. But it is working just > like a string implementation. taking '\0' > as end of the array. > > I need an implementation or method to parse the > binary incoming packets and interpret them to > values. > > Please help me with any suggestions. At least > pointers to which byte array implementations I should > use or .. how to parse and interpret char* arrays > in a binary way. > > Thank you > Sani.
I don't know if you got a satisfactory answer for this or not, but when working with binary data in C, you have to track the size of the data along with the pointer to the data. A struct can be handy for tracking that information. If I were developing this, I would use BString from Safe C++ Design Principles (free e-book for c-prog members in Links section). BString manages the size internally and is specifically designed to handle binary data. Specifically, it has extraction and conversion tools for things like integers of various binary sizes. Consider implementing this project in C++. -- Thomas Hruska CubicleSoft President Ph: 517-803-4197 *NEW* MyTaskFocus 1.1 Get on task. Stay on task. http://www.CubicleSoft.com/MyTaskFocus/
