I want a simple method to generate a unique code within a data stream. This code would frame certain data, like packet size. Here is my attempt to do that:
The code would simply be 0x00_01
Now, this code would certainly appear in the data stream natively, so as not to transmit the code where it's not needed, I propose to do this:
If the code 0x00_01 appears in the data stream, I add a byte to make the code 0x00_02_01. The receiver removes the 0x02 byte and recovers the original data.
But, the code 0x00_02 might be in the stream as well, and so I repeat the process and generate: 0x00_03_02.... I repeat this as many times as needed to encode the stream and advoid sending the unique code. For example, if the data stream contains 0x00_03_02_01, then I transmit:
0x00_04_03_03_02_02_01
To decode the data, I slide along the stream testing each byte pair for the condition of decrementing values, until that condition is false, then I save the last value, thus:
If I save all 'F' bytes, I have the original data 0x00030201 -- the lase byte "01" is actually T, but I save it anyway, since it's the last byte.
So, does this make sense? Does anyone spot a flaw in the logic? Is there a better or easier way to accomplish this?
Thanks!
The code would simply be 0x00_01
Now, this code would certainly appear in the data stream natively, so as not to transmit the code where it's not needed, I propose to do this:
If the code 0x00_01 appears in the data stream, I add a byte to make the code 0x00_02_01. The receiver removes the 0x02 byte and recovers the original data.
But, the code 0x00_02 might be in the stream as well, and so I repeat the process and generate: 0x00_03_02.... I repeat this as many times as needed to encode the stream and advoid sending the unique code. For example, if the data stream contains 0x00_03_02_01, then I transmit:
0x00_04_03_03_02_02_01
To decode the data, I slide along the stream testing each byte pair for the condition of decrementing values, until that condition is false, then I save the last value, thus:
Rich (BB code):
0x00_04_03_03_02_02_01
T F T F T
So, does this make sense? Does anyone spot a flaw in the logic? Is there a better or easier way to accomplish this?
Thanks!