Example #1
0
    def _get_flags(data: bytes) -> typing.Tuple[int, int]:
        """Decode the flags from the data returning the bytes consumed and
        flags.

        """
        bytes_consumed, flags, flagword_index = 0, 0, 0
        while True:
            consumed, partial_flags = decode.short_int(data)
            bytes_consumed += consumed
            flags |= (partial_flags << (flagword_index * 16))
            if not partial_flags & 1:  # pragma: nocover
                break
            flagword_index += 1  # pragma: nocover
        return bytes_consumed, flags
Example #2
0
    def _get_flags(self, data):
        """Decode the flags from the data returning the bytes consumed and
        flags

        :param bytes data: The data to pull flags out of
        :rtype: int, int

        """
        # Defaults
        bytes_consumed, flags, flagword_index = 0, 0, 0

        # Read until we don't have a value pulled out of the flags
        while True:
            consumed, partial_flags = decode.short_int(data)
            bytes_consumed += consumed
            flags |= (partial_flags << (flagword_index * 16))
            if not partial_flags & 1:
                break
            flagword_index += 1

        # Return the bytes consumed and the flags
        return bytes_consumed, flags
Example #3
0
 def test_decode_short_int_value(self):
     value = b'\x7f\xff'
     self.assertEqual(decode.short_int(value)[1], 32767)
Example #4
0
 def test_decode_short_int_data_type(self):
     value = b'\x7f\xff'
     self.assertIsInstance(decode.short_int(value)[0], int)
Example #5
0
 def test_decode_short_int_bytes_consumed(self):
     value = b'\x7f\xff'
     self.assertEqual(decode.short_int(value)[0], 2)