def writeVarUInt(self, value: int) -> None: """ Writes a variable unsigned integer value (up to 9 bytes) to the underlying storage. :param value: Value to write. :raises PythonRuntimeException: If the value is out of the range. """ self._writeVarNum(value, 9, getBitSizeOfVarUInt(value) // 8, isSigned=False)
def writeVarUInt(self, value): """ Writes a variable unsigned integer value (up to 9 bytes) to the underlying storage. :param value: Value to write. :raises PythonRuntimeException: If the value is out of the range. """ numBytes = getBitSizeOfVarUInt(value) // 8 self._writeVarNum(value, numBytes, VARUINT_NUM_BITS)
def bitSizeOf(_bitPosition, value): """ Returns length of Zserio varuint type stored in the bit stream in bits. :param _bitPosition: Not used. :param value: Zserio varuint type value. :returns: Length of given Zserio varuint type in bits. """ return getBitSizeOfVarUInt(value)
def testGetBitSizeOfVarUInt(self): self.assertEqual(8, getBitSizeOfVarUInt(0)) self.assertEqual(8, getBitSizeOfVarUInt((1 << 7) - 1)) self.assertEqual(16, getBitSizeOfVarUInt((1 << 7))) self.assertEqual(16, getBitSizeOfVarUInt((1 << 14) - 1)) self.assertEqual(24, getBitSizeOfVarUInt((1 << 14))) self.assertEqual(24, getBitSizeOfVarUInt((1 << 21) - 1)) self.assertEqual(32, getBitSizeOfVarUInt((1 << 21))) self.assertEqual(32, getBitSizeOfVarUInt((1 << 28) - 1)) self.assertEqual(40, getBitSizeOfVarUInt((1 << 28))) self.assertEqual(40, getBitSizeOfVarUInt((1 << 35) - 1)) self.assertEqual(48, getBitSizeOfVarUInt((1 << 35))) self.assertEqual(48, getBitSizeOfVarUInt((1 << 42) - 1)) self.assertEqual(56, getBitSizeOfVarUInt((1 << 42))) self.assertEqual(56, getBitSizeOfVarUInt((1 << 49) - 1)) self.assertEqual(64, getBitSizeOfVarUInt((1 << 49))) self.assertEqual(64, getBitSizeOfVarUInt((1 << 56) - 1)) self.assertEqual(72, getBitSizeOfVarUInt((1 << 56))) self.assertEqual(72, getBitSizeOfVarUInt((1 << 64) - 1)) with self.assertRaises(PythonRuntimeException): getBitSizeOfVarUInt(-1) # below the lower bound with self.assertRaises(PythonRuntimeException): getBitSizeOfVarUInt(1 << 64) # above the upper bound