예제 #1
0
    def writeVarUInt32(self, value: int) -> None:
        """
        Writes a variable 32-bit unsigned 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, getBitSizeOfVarUInt32(value) // 8, isSigned=False)
예제 #2
0
    def writeVarUInt32(self, value):
        """
        Writes a variable 32-bit unsigned integer value to the underlying storage.

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

        numBytes = getBitSizeOfVarUInt32(value) // 8
        self._writeVarNum(value, numBytes, VARUINT32_NUM_BITS)
예제 #3
0
파일: array.py 프로젝트: chenpeihua/zserio
    def bitSizeOf(_bitPosition, value):
        """
        Returns length of Zserio varuint32 type stored in the bit stream in bits.

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

        return getBitSizeOfVarUInt32(value)
예제 #4
0
    def testGetBitSizeOfVarUInt32(self):
        self.assertEqual(1 * 8, getBitSizeOfVarUInt32(0))

        self.assertEqual(1 * 8, getBitSizeOfVarUInt32(1 << (0)))
        self.assertEqual(1 * 8, getBitSizeOfVarUInt32((1 << (7)) - 1))

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

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

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

        with self.assertRaises(PythonRuntimeException):
            getBitSizeOfVarUInt32(-1)  # below the lower bound

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