Most pythonic way to implement byte stuffing algorithm

MRAB python at mrabarnett.plus.com
Tue Apr 17 14:15:28 EDT 2018


On 2018-04-17 17:02, Travis Griggs wrote:
> I posted this on SO, but… yeah…
> 
> I'm doing some serial protocol stuff and want to implement a basic byte stuffing algorithm in python. Though really what this really generalizes to is “what is the most pythonic way to transform one sequence of bytes where some bytes are passed through 1:1, but others are transformed to longer subsequences of bytes?” I’m pretty sure this rules out the use of transform() which expects a 1:1 mapping.
> 
[snip]
There are only 256 possible input bytes, so just put them into a dict 
and look them up.


More information about the Python-list mailing list