Beispiel #1
0
    def writeVarInt16(self, value: int) -> None:
        """
        Writes a variable 16-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, 2, getBitSizeOfVarInt16(value) // 8, isSigned=True)
Beispiel #2
0
    def bitSizeOf(_bitPosition, value):
        """
        Returns length of Zserio varint16 type stored in the bit stream in bits.

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

        return getBitSizeOfVarInt16(value)
Beispiel #3
0
    def writeVarInt16(self, value):
        """
        Writes a variable 16-bit signed integer value to the underlying storage.

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

        numBytes = getBitSizeOfVarInt16(value) // 8
        self._writeVarNum(abs(value), numBytes, VARINT16_NUM_BITS, sign=(value < 0))
Beispiel #4
0
    def testGetBitSizeOfVarInt16(self):
        self.assertEqual(1 * 8, getBitSizeOfVarInt16(0))

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

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

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

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