Click to See Complete Forum and Search --> : Parsing through data...
polus
July 13th, 2005, 04:53 AM
I have a buffer from an RS232 component that will be full of strings and 2 - 4 Byte numbers. Whats the best way to parse through this data, I was going to check that the data is valid (255 bytes of it) and have a pointer to the buffer which I will increment as I go checking the values and feeding them into a structure.... But Im not sure if Im heading for the best technique?
Does anyone know of a good way of doing this or perhaps a good article on something similar?
Thanks in advance for any tips ;)
stober
July 13th, 2005, 05:14 AM
depends on the structure and how the sender put the package together. Is the buffer you received a complete immage of the structure? If yes, and the structure does not contain any c++ class objects (like std::string) then just memcpy the buffer into the structure.
polus
July 13th, 2005, 05:39 AM
The buffer is a complete image once all the data has been collected but I also need to verify this. The only types that are in the packet are bool, int and float and a few strings (no objects).
Im not exactly sure how Im going to tell the difference between many packets coming in and when they start / end.... They have a start and end charateur and the packets a fixed length so shouldnt be difficult.
Thanks Stober.
stober
July 13th, 2005, 06:23 AM
Another problem you might encounter is Endian order (http://www.cs.umass.edu/~verts/cs32/endian.html) if the data is transferred from one type of computer to another, such as between MS-Windows and IBM AIX unix.
naddad
July 13th, 2005, 07:46 AM
Yes, before memcpy'ing make sure byte ordering in the stream allows you to.
polus
July 13th, 2005, 08:49 AM
Both sides are little endian.
Thanks people.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.