def _encode(cls, payload):
""" Protects a stream of data with escape characters
The payload should be a bytestring
"""
out = b''
for byte in payload:
if byte >= cls.ESCAPE:
out += bytearray([cls.ESCAPE])
byte = ctypes.c_uint8(byte - cls.ESCAPE).value
out += bytearray([byte])
return out
评论列表
文章目录