Implement a custom Serialization Format in v2
mainv2 uses the Format protocol instead of marshaller callbacks. To support a new format (like YAML), implement the Format class with the following methods:
read(event_factory, data): Parse data into attributes and return aBaseCloudEvent.write(event): Serialize the entire event to bytes.write_data(data, datacontenttype): Serialize just the data payload.read_data(body, datacontenttype): Deserialize just the data payload.get_content_type(): Return the MIME type.
Example usage:
from cloudevents.core.bindings.http import to_binary
# Use your custom format implementation
message = to_binary(event, event_format=YAMLFormat())