def serialize_int(x: int) -> bytes:
    """ Efficiently convert a python integer to a serializable byte-string. """
    byte_size = (int.bit_length(x) + 8) // 8
    return int.to_bytes(x, length=byte_size, byteorder='big')