0

I have stream of bytes and I need to form these bytes as a frame when I get particular Header. Example:

Header:    ABC  
Source:    DFDFDFDF'ABC'IEJENFAREABCOEKRERIERE

If ABC is detected, rest of the bytes 'IE' in a string and 'JEN' in a string and 'FARE' in a String and again ABC is detected, hence 'OE' in a string... likewise my byte stream has to be processed.

Is there any efficient way to process it ?

sathish
  • 1
  • 2

1 Answers1

1

If you have more than 1 header, I'd suggest using Finite State Machines. However, if there is only one, simple pattern matching will suffice.

All you have to do is store characters starting from previously created frame. Whenever you read a character, update your state. If the end of a header is found, you've got your frame. If not, you can append the character to your incomplete frame.

Mateusz
  • 3,038
  • 4
  • 27
  • 41