def extract_topic_data(msg, t):
    """ Reads all data in a message

        This is a recursive function. Given a message, extract all of the data in the message to a dictionary. The keys
        of the dictionary are the field names within the message, and the values are the values of the fields in the
        message. Recursively call this function on a message to build up a dictionary of dictionaries representing the
        ROS message.

        Args:
            msg: A ROS message
            t: Time the message was recorded in the bag file

        Returns:
            A dictionary containing all information found in the message.
    """
    # Initialize the information found for this message
    data = {}
    # If the message has slots, we have a non-primitive type, and need to extract all of the information from this
    # message by recursively calling this function on the data in that slot. For example, we may have a message with a
    # geometry_msgs/Vector3 as a field. Call this function on that field to get the x, y, and z components
    if hasattr(msg, '__slots__'):
        # Extract all information on a non-primitive type
        for slot in msg.__slots__:
            data[slot] = extract_topic_data(getattr(msg, slot), t)
    else:
        # We encountered a primitive type, like a double. Just return it so it gets put into the output dictionary
        return msg

    # Return the dictionary representing all of the fields and their information in this message
    return data