def decode(msg): buf = msg.next_frame().buf size = FixSizedTypesCodec.decode_int(buf, 0) unscaled_value = int_from_bytes( buf[INT_SIZE_IN_BYTES:INT_SIZE_IN_BYTES + size]) scale = FixSizedTypesCodec.decode_int(buf, INT_SIZE_IN_BYTES + size) sign = 0 if unscaled_value >= 0 else 1 return Decimal( (sign, tuple(int(digit) for digit in str(abs(unscaled_value))), -1 * scale))
def test_int_from_bytes(self, number, buf): self.assertEqual(number, int_from_bytes(buf))
def read_big_integer(inp: ObjectDataInput) -> int: length = inp.read_int() result = bytearray(length) inp.read_into(result, 0, length) return int_from_bytes(result)