On 2/18/26 17:21, B 9 wrote:
Uses Stephen's encoding with some tweaks. (Main difference is that the
end of data flag is changed to be an invalid sequence, "//", so that DEL
can be encoded).
I had the same initial thought about /255 as I was converting co2ba.sh
to use Steve's method.
"/ÿ" (/255) does not mean that you can't have an actual 255 in the payload.
First, a /255 in the encoded data doesn't conflict with anything in the
payload because the payload only ever has /0+64 to /34+64 and /47+64 (/@
to /b and /o).
No other byte values will have a / in the first place.
Also, the decoder always subtracts 64 from the value to undo the fact
that the encoder added it to turn a control byte into a safe byte.
So even if a /255 were meant to be an encoded byte of payload, /ÿ would
decode to 255-64=191, but real 191 bytes are not encoded in the first
place. Nor are real 255 bytes.
So it's no risk or conflict to treat /255 (or /anything other than
0-31,34,47) for some other special purpose like end-of-data.
In my case, I'm using ! (33) as the escape char instead of / (47), and
just converting everything from 0-34 instead of adding a special cases
for " and /.
If I want the least encoder code, say for running on the 100 in the
smallest possible routine, I can just encode everything from 0-34 and
accept that 32's are encoded when they wouldn't need to be. Or if I want
the smallest output I can add that one extra step in the encoder to
exclude 32.
It simplifies both the encoder and decoder slightly.
Also in my case I'm dispensing with the /255 eof mechanism altogether
because we always know the length and can just as easily write the
length in the output as write an eof mark. Most of the time the data
will be a CO file which needs the length info in it's header anyway, but
even for arbitrary binary data without a CO header, it's still both a
simpler and more robust loop to just count from start value to end value
instead of count forever and perform a check on every byte along the way
to see if we got an eof, (and hope we actually do always get one!).
Similarly I also write a checksum along with the length.
--
bkw