How to use the s2protocol.compat.byte_to_int function in s2protocol

To help you get started, we’ve selected a few s2protocol examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Blizzard / s2protocol / s2protocol / encoders.py View on Github external
def write_unaligned_bytes(self, data):
        assert isinstance(data, str)
        for c in data:
            self.write_bits(byte_to_int(c), 8)
github Blizzard / s2protocol / s2protocol / decoders.py View on Github external
def __str__(self):
        s = '{:02x}'.format(byte_to_int(self._data[self._used])) \
            if self._used < len(self._data) else '--'
        return 'buffer({0:02x}/{1:d},[{2:d}]={3:s})'.format(
            self._nextbits and self._next or 0,
            self._nextbits,
            self._used,
            s
        )
github Blizzard / s2protocol / s2protocol / decoders.py View on Github external
def read_bits(self, bits):
        result = 0
        resultbits = 0
        while resultbits != bits:
            if self._nextbits == 0:
                if self.done():
                    raise TruncatedError(self)
                self._next = byte_to_int(self._data[self._used])
                self._used += 1
                self._nextbits = 8
            copybits = min(bits - resultbits, self._nextbits)
            copy = (self._next & ((1 << copybits) - 1))
            if self._bigendian:
                result |= copy << (bits - resultbits - copybits)
            else:
                result |= copy << resultbits
            self._next >>= copybits
            self._nextbits -= copybits
            resultbits += copybits
        return result