def list_of_fragments(full_message, fragment_size):                             # create fragment messages for a huge message
    message_id = randint(0,64000)                                               # generate random message id
    fragments = []                                                              # generate list of data fragments
    cursor = 0
    while cursor < len(full_message):
        fragment_begin = cursor
        if len(full_message) < cursor + fragment_size:
            fragment_end = len(full_message)
            cursor = len(full_message)
        else:
            fragment_end = cursor + fragment_size
            cursor += fragment_size
        fragment = full_message[fragment_begin:fragment_end]
        fragments.append(fragment)

    fragmented_messages_list = []                                               # generate list of fragmented messages (including headers)
    if len(fragments) > 1:
        for count, fragment in enumerate(fragments):                            # iterate through list and have index counter
            fragmented_message_object = {"op":"fragment",                       #   create python-object for each fragment message
                                         "id": str(message_id),
                                         "data": str(fragment),
                                         "num": count,
                                         "total": len(fragments)
                                         }
            fragmented_message = json.dumps(fragmented_message_object)          # create JSON-object from python-object for each fragment message
            fragmented_messages_list.append(fragmented_message)                 # append JSON-object to list of fragmented messages
    else:                                                                       # if only 1 fragment --> do not send as fragment, but as service_response
        fragmented_messages_list.append(str(fragment))
    return fragmented_messages_list                                             # return list of 'ready-to-send' fragmented messages

####################### helper functions end ###################################


####################### script begin ###########################################
# should not need to be changed (but could be improved )                       #
################################################################################
dataset/ETHPy150Open RobotWebTools/rosbridge_suite/rosbridge_library/test/experimental/complex_srv+tcp/test_non-ros_service_server_complex-srv.py/list_of_fragments/original