Your version of RLE is not what I'm used to. Older versions of RLE such as in PCX files relied on some magical value to turn encoding on and off. Newer versions simply rely on character repeat counts to turn encoding on and off.
would be this logically:
A A 7 B C C 1 D D 2 E E 2 F F 8
And this in RLE byte form:
65 65 07 66 67 67 01 68 68 02 69 69 02 70 70 08
Most systems will only allow at max 255 characters to be RLE because this is the max value for a byte or unsigned char.
You can do spanning RLEs but you must place some extra logic in the code. You can determine when to turn RLE decode off by simply looking at the run length. Whenever the run length is < FF you know the byte following is a literal character and not a run length. The only time a run length can continue on is if the length is FF. So this is a long RLE byte stream:
65 65 FF FF FF FF FF FF 7F 68 68 4F
The RLE is turned off at 7F. Then 68 is interpreted as a literal character. Then 68 is encountered again and RLE mode is turned on and 4F is then interpreted as a run length.
There is one special case you must handle. Look at this byte stream:
65 65 FF FF FF FF FF FF FF 68 68 4F
RLE is turned off at 68, however 68 is interpreted as a run length. Then the next 68 is interpreted as a literal and the 4F is interpreted as another literal. This is clearly incorrect. The fix:
65 65 FF FF FF FF FF FF FF 00 68 68 4F
RLE is turned off at 00, 68 is literal, next 68 turns RLE on, 4F is run length for 68...which is correct.
If the RLE terminates and the length is exactly FF then a 00 or some magic value must follow the RLE byte. This will turn off RLE. So now if the byte following FF is 00 then you take the FF and then turn RLE off and grab the next byte. Both your encoder and decoder must understand this logic to function correctly.