Exemplo n.º 1
0
    def writeVarInt32(self, value: int) -> None:
        """
        Writes a variable 32-bit signed integer value to the underlying storage.

        :param value: Value to write.
        :raises PythonRuntimeException: If the value is out of the range.
        """

        self._writeVarNum(value, 4, getBitSizeOfVarInt32(value) // 8, isSigned=True)
Exemplo n.º 2
0
    def bitSizeOf(_bitPosition, value):
        """
        Returns length of Zserio varint32 type stored in the bit stream in bits.

        :param _bitPosition: Not used.
        :param value: Zserio varint32 type value.
        :returns: Length of given Zserio varint32 type in bits.
        """

        return getBitSizeOfVarInt32(value)
Exemplo n.º 3
0
    def writeVarInt32(self, value):
        """
        Writes a variable 32-bit signed integer value to the underlying storage.

        :param value: Value to write.
        :raises PythonRuntimeException: If the value is out of the range.
        """

        numBytes = getBitSizeOfVarInt32(value) // 8
        self._writeVarNum(abs(value), numBytes, VARINT32_NUM_BITS, sign=(value < 0))
Exemplo n.º 4
0
    def testGetBitSizeOfVarInt32(self):
        self.assertEqual(1 * 8, getBitSizeOfVarInt32(0))

        self.assertEqual(1 * 8, getBitSizeOfVarInt32(1 << (0)))
        self.assertEqual(1 * 8, getBitSizeOfVarInt32(-(1 << (0))))
        self.assertEqual(1 * 8, getBitSizeOfVarInt32((1 << (6)) - 1))
        self.assertEqual(1 * 8, getBitSizeOfVarInt32(-((1 << (6)) - 1)))

        self.assertEqual(2 * 8, getBitSizeOfVarInt32(1 << (6)))
        self.assertEqual(2 * 8, getBitSizeOfVarInt32(-(1 << (6))))
        self.assertEqual(2 * 8, getBitSizeOfVarInt32((1 << (6 + 7)) - 1))
        self.assertEqual(2 * 8, getBitSizeOfVarInt32(-((1 << (6 + 7)) - 1)))

        self.assertEqual(3 * 8, getBitSizeOfVarInt32(1 << (6 + 7)))
        self.assertEqual(3 * 8, getBitSizeOfVarInt32(-(1 << (6 + 7))))
        self.assertEqual(3 * 8, getBitSizeOfVarInt32((1 << (6 + 7 + 7)) - 1))
        self.assertEqual(3 * 8,
                         getBitSizeOfVarInt32(-((1 << (6 + 7 + 7)) - 1)))

        self.assertEqual(4 * 8, getBitSizeOfVarInt32(1 << (6 + 7 + 7)))
        self.assertEqual(4 * 8, getBitSizeOfVarInt32(-(1 << (6 + 7 + 7))))
        self.assertEqual(4 * 8,
                         getBitSizeOfVarInt32((1 << (6 + 7 + 7 + 8)) - 1))
        self.assertEqual(4 * 8,
                         getBitSizeOfVarInt32(-((1 << (6 + 7 + 7 + 8)) - 1)))

        with self.assertRaises(PythonRuntimeException):
            getBitSizeOfVarInt32(-(1 <<
                                   (6 + 7 + 7 + 8)))  # below the lower bound

        with self.assertRaises(PythonRuntimeException):
            getBitSizeOfVarInt32(1 << (6 + 7 + 7 + 8))  # above the upper bound