def testGetBitSizeOfVarUInt16(self): self.assertEqual(1 * 8, getBitSizeOfVarUInt16(0)) self.assertEqual(1 * 8, getBitSizeOfVarUInt16(1 << (0))) self.assertEqual(1 * 8, getBitSizeOfVarUInt16((1 << (7)) - 1)) self.assertEqual(2 * 8, getBitSizeOfVarUInt16(1 << (7))) self.assertEqual(2 * 8, getBitSizeOfVarUInt16((1 << (7 + 8)) - 1)) with self.assertRaises(PythonRuntimeException): getBitSizeOfVarUInt16(-1) # below the lower bound with self.assertRaises(PythonRuntimeException): getBitSizeOfVarUInt16(1 << (7 + 8)) # above the upper bound
def writeVarUInt16(self, value: int) -> None: """ Writes a variable 16-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, 2, getBitSizeOfVarUInt16(value) // 8, isSigned=False)
def writeVarUInt16(self, value): """ Writes a variable 16-bit unsigned integer value to the underlying storage. :param value: Value to write. :raises PythonRuntimeException: If the value is out of the range. """ numBytes = getBitSizeOfVarUInt16(value) // 8 self._writeVarNum(value, numBytes, VARUINT16_NUM_BITS)
def bitSizeOf(_bitPosition, value): """ Returns length of Zserio varuint16 type stored in the bit stream in bits. :param _bitPosition: Not used. :param value: Zserio varuint16 type value. :returns: Length of given Zserio varuint16 type in bits. """ return getBitSizeOfVarUInt16(value)