Esempio n. 1
0
    def fill(self, byte):
        """
        fill: byte -> None

        Adds the given byte to this LinkFrame. If this byte is an escape
        byte, the next byte in a call to fill() will be unescaped.
        """
        if self._unescape_next_byte:
            byte = intToByte(byteToInt(byte) ^ 0x20)
            self._unescape_next_byte = False
        elif byte == LinkFrame.ESCAPE_BYTE:
            self._unescape_next_byte = True
            return

        self.raw_data += intToByte(byteToInt(byte))
Esempio n. 2
0
    def escape(data):
        """
        escape: byte string -> byte string

        When the 'special' byte is found in the data string,
        it must be preceded by an escape byte and XOR'd with 0x20
        """

        escaped_data = b""
        for byte in data:
            if intToByte(byteToInt(byte)) in LinkFrame.ESCAPE_BYTES:
                escaped_data += LinkFrame.ESCAPE_BYTE
                escaped_data += intToByte(0x20 ^ byteToInt(byte))
            else:
                escaped_data += intToByte(byteToInt(byte))

        return escaped_data