def writeVarInt64(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, 8, getBitSizeOfVarInt64(value) // 8, isSigned=True)
def bitSizeOf(_bitPosition, value): """ Returns length of Zserio varint64 type stored in the bit stream in bits. :param _bitPosition: Not used. :param value: Zserio varint64 type value. :returns: Length of given Zserio varint64 type in bits. """ return getBitSizeOfVarInt64(value)
def writeVarInt64(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 = getBitSizeOfVarInt64(value) // 8 self._writeVarNum(abs(value), numBytes, VARINT64_NUM_BITS, sign=(value < 0))
def testGetBitSizeOfVarInt64(self): self.assertEqual(1 * 8, getBitSizeOfVarInt64(0)) self.assertEqual(1 * 8, getBitSizeOfVarInt64(1 << (0))) self.assertEqual(1 * 8, getBitSizeOfVarInt64(-(1 << (0)))) self.assertEqual(1 * 8, getBitSizeOfVarInt64((1 << (6)) - 1)) self.assertEqual(1 * 8, getBitSizeOfVarInt64(-((1 << (6)) - 1))) self.assertEqual(2 * 8, getBitSizeOfVarInt64(1 << (6))) self.assertEqual(2 * 8, getBitSizeOfVarInt64(-(1 << (6)))) self.assertEqual(2 * 8, getBitSizeOfVarInt64((1 << (6 + 7)) - 1)) self.assertEqual(2 * 8, getBitSizeOfVarInt64(-((1 << (6 + 7)) - 1))) self.assertEqual(3 * 8, getBitSizeOfVarInt64(1 << (6 + 7))) self.assertEqual(3 * 8, getBitSizeOfVarInt64(-(1 << (6 + 7)))) self.assertEqual(3 * 8, getBitSizeOfVarInt64((1 << (6 + 7 + 7)) - 1)) self.assertEqual(3 * 8, getBitSizeOfVarInt64(-((1 << (6 + 7 + 7)) - 1))) self.assertEqual(4 * 8, getBitSizeOfVarInt64(1 << (6 + 7 + 7))) self.assertEqual(4 * 8, getBitSizeOfVarInt64(-(1 << (6 + 7 + 7)))) self.assertEqual(4 * 8, getBitSizeOfVarInt64((1 << (6 + 7 + 7 + 7)) - 1)) self.assertEqual(4 * 8, getBitSizeOfVarInt64(-((1 << (6 + 7 + 7 + 7)) - 1))) self.assertEqual(5 * 8, getBitSizeOfVarInt64(1 << (6 + 7 + 7 + 7))) self.assertEqual(5 * 8, getBitSizeOfVarInt64(-(1 << (6 + 7 + 7 + 7)))) self.assertEqual(5 * 8, getBitSizeOfVarInt64((1 << (6 + 7 + 7 + 7 + 7)) - 1)) self.assertEqual( 5 * 8, getBitSizeOfVarInt64(-((1 << (6 + 7 + 7 + 7 + 7)) - 1))) self.assertEqual(6 * 8, getBitSizeOfVarInt64(1 << (6 + 7 + 7 + 7 + 7))) self.assertEqual(6 * 8, getBitSizeOfVarInt64(-(1 << (6 + 7 + 7 + 7 + 7)))) self.assertEqual( 6 * 8, getBitSizeOfVarInt64((1 << (6 + 7 + 7 + 7 + 7 + 7)) - 1)) self.assertEqual( 6 * 8, getBitSizeOfVarInt64(-((1 << (6 + 7 + 7 + 7 + 7 + 7)) - 1))) self.assertEqual(7 * 8, getBitSizeOfVarInt64(1 << (6 + 7 + 7 + 7 + 7 + 7))) self.assertEqual(7 * 8, getBitSizeOfVarInt64(-(1 << (6 + 7 + 7 + 7 + 7 + 7)))) self.assertEqual( 7 * 8, getBitSizeOfVarInt64((1 << (6 + 7 + 7 + 7 + 7 + 7 + 7)) - 1)) self.assertEqual( 7 * 8, getBitSizeOfVarInt64(-((1 << (6 + 7 + 7 + 7 + 7 + 7 + 7)) - 1))) self.assertEqual( 8 * 8, getBitSizeOfVarInt64(1 << (6 + 7 + 7 + 7 + 7 + 7 + 7))) self.assertEqual( 8 * 8, getBitSizeOfVarInt64(-(1 << (6 + 7 + 7 + 7 + 7 + 7 + 7)))) self.assertEqual( 8 * 8, getBitSizeOfVarInt64((1 << (6 + 7 + 7 + 7 + 7 + 7 + 7 + 8)) - 1)) self.assertEqual( 8 * 8, getBitSizeOfVarInt64(-( (1 << (6 + 7 + 7 + 7 + 7 + 7 + 7 + 8)) - 1))) with self.assertRaises(PythonRuntimeException): getBitSizeOfVarInt64( -(1 << (6 + 7 + 7 + 7 + 7 + 7 + 7 + 8))) # below the lower bound with self.assertRaises(PythonRuntimeException): getBitSizeOfVarInt64( 1 << (6 + 7 + 7 + 7 + 7 + 7 + 7 + 8)) # above the upper bound