def generate_event_msg_meta(data, class_id):
    meta = pyds.glist_get_nvds_event_msg_meta(data)
    meta.sensorId = 0
    meta.placeId = 0
    meta.moduleId = 0
    meta.sensorStr = "sensor-0"
    meta.ts = pyds.alloc_buffer(MAX_TIME_STAMP_LEN + 1)
    pyds.generate_ts_rfc3339(meta.ts, MAX_TIME_STAMP_LEN)

    # This demonstrates how to attach custom objects.
    # Any custom object as per requirement can be generated and attached
    # like NvDsVehicleObject / NvDsPersonObject. Then that object should
    # be handled in payload generator library (nvmsgconv.cpp) accordingly.
    if (class_id == PGIE_CLASS_ID_VEHICLE):
        meta.type = pyds.NvDsEventType.NVDS_EVENT_MOVING
        meta.objType = pyds.NvDsObjectType.NVDS_OBJECT_TYPE_VEHICLE
        meta.objClassId = PGIE_CLASS_ID_VEHICLE
        obj = pyds.alloc_nvds_vehicle_object()
        obj = generate_vehicle_meta(obj)
        meta.extMsg = obj
        meta.extMsgSize = sys.getsizeof(pyds.NvDsVehicleObject)
    if (class_id == PGIE_CLASS_ID_PERSON):
        meta.type = pyds.NvDsEventType.NVDS_EVENT_ENTRY
        meta.objType = pyds.NvDsObjectType.NVDS_OBJECT_TYPE_PERSON
        meta.objClassId = PGIE_CLASS_ID_PERSON
        obj = pyds.alloc_nvds_person_object()
        obj = generate_person_meta(obj)
        meta.extMsg = obj
        meta.extMsgSize = sys.getsizeof(pyds.NvDsPersonObject)
    return meta
def generate_event_msg_meta(data, class_id):
    '''
    Some MetaData instances are stored in GList form. 
    To access the data in a GList node, 
    the data field needs to be cast to the appropriate structure. 
    This casting is done via cast() member function for the target type:
    '''
    meta = pyds.NvDsEventMsgMeta.cast(data)
    # Check the following link for struct fields
    # https://docs.nvidia.com/metropolis/deepstream/5.0/dev-guide/DeepStream_Development_Guide/baggage/structNvDsEventMsgMeta.html#af94e900971860386108ddcdf82983490
    meta.ts = pyds.alloc_buffer(MAX_TIME_STAMP_LEN + 1)
    pyds.generate_ts_rfc3339(meta.ts, MAX_TIME_STAMP_LEN)
    '''
    if (class_id == PGIE_CLASS_ID_PERSON):
        meta.type = pyds.NvDsEventType.NVDS_EVENT_ENTRY
        meta.objType = pyds.NvDsObjectType.NVDS_OBJECT_TYPE_PERSON # This affects the meta fields
        meta.objClassId = PGIE_CLASS_ID_PERSON
        # We need to allocate memory in order to persist the object 
        # See the following link:
        # https://docs.nvidia.com/metropolis/deepstream/dev-guide/index.html#page/DeepStream_Development_Guide/deepstream_Python_sample_apps.html#wwpID0E0WC0HA
        # obj = pyds.alloc_nvds_person_object() 
        # obj = generate_person_meta(obj)
        # meta.extMsg = obj
        # meta.extMsgSize = sys.getsizeof(pyds.NvDsPersonObject)
    '''

    meta.type = pyds.NvDsEventType.NVDS_EVENT_ENTRY
    meta.objType = pyds.NvDsObjectType.NVDS_OBJECT_TYPE_CUSTOM
    # TODO we need to allocate memory and generate custom metadata
    # See above for how to do it
    meta.objClassId = class_id

    return meta