CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2004
    Posts
    133

    Parsing through data...

    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

  2. #2
    Join Date
    Jun 2002
    Posts
    1,417

    Re: Parsing through data...

    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.

  3. #3
    Join Date
    Aug 2004
    Posts
    133

    Re: Parsing through data...

    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.

  4. #4
    Join Date
    Jun 2002
    Posts
    1,417

    Re: Parsing through data...

    Another problem you might encounter is Endian order if the data is transferred from one type of computer to another, such as between MS-Windows and IBM AIX unix.

  5. #5
    Join Date
    Apr 2005
    Posts
    62

    Re: Parsing through data...

    Yes, before memcpy'ing make sure byte ordering in the stream allows you to.

  6. #6
    Join Date
    Aug 2004
    Posts
    133

    Re: Parsing through data...

    Both sides are little endian.

    Thanks people.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured