def chunk_objects(objects, chunk_size, max_chunk_bytes, serializer):
    """
    Split objects into chunks by number or size, serialize them into strings in
    the process.
    """
    bulk_objs, bulk_ser_objs = [], []
    size, count = 0, 0
    for obj in objects:
        ser_obj = serializer.dumps(obj)
        cur_size = len(ser_obj) + 1
        if size + cur_size > max_chunk_bytes or count == chunk_size:
            yield bulk_objs, bulk_ser_objs
            bulk_objs, bulk_ser_objs = [], []
            size, count = 0, 0
        bulk_objs.append(obj)
        bulk_ser_objs.append(ser_obj)
        size += cur_size
        count += 1
    if bulk_objs:
        yield bulk_objs, bulk_ser_objs
