in azure/functions/eventhub.py [0:0]
def _marshall_event_body(cls, parsed_data, data_type):
# In IoTHub, when setting the eventhub using cardinality = 'many'
# The data is wrapped inside a json (e.g. '[{ "device-id": "1" }]')
# Previously, since the IoTHub events has a 'json' datatype,
# it is handled as single_event by mistake and our users handle the
# data parsing. And we want to keep the same behavior here.
if data_type == 'json':
return json.dumps(parsed_data).encode('utf-8')
elif data_type == 'bytes':
return parsed_data
elif data_type == 'string':
return parsed_data.encode('utf-8')
elif data_type == 'collection_bytes':
return parsed_data
elif data_type == 'collection_string':
return parsed_data.encode('utf-8')
return parsed_data