osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Most pythonic way to implement byte stuffing algorithm


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.