|
19 | 19 |
|
20 | 20 |
|
21 | 21 | class Format(Protocol): |
| 22 | + """ |
| 23 | + Protocol defining the contract for CloudEvent format implementations. |
| 24 | +
|
| 25 | + Format implementations are responsible for serializing and deserializing CloudEvents |
| 26 | + to and from specific wire formats (e.g., JSON, Avro, Protobuf). Each format must |
| 27 | + implement both read and write operations to convert between CloudEvent objects and |
| 28 | + their byte representations according to the CloudEvents specification. |
| 29 | + """ |
| 30 | + |
22 | 31 | def read( |
23 | 32 | self, |
24 | 33 | event_factory: Callable[ |
25 | 34 | [dict, Optional[Union[dict, str, bytes]]], BaseCloudEvent |
26 | 35 | ], |
27 | 36 | data: Union[str, bytes], |
28 | | - ) -> BaseCloudEvent: ... |
| 37 | + ) -> BaseCloudEvent: |
| 38 | + """ |
| 39 | + Deserialize a CloudEvent from its wire format representation. |
| 40 | +
|
| 41 | + :param event_factory: A factory function that creates CloudEvent instances from |
| 42 | + attributes and data. The factory should accept a dictionary of attributes and |
| 43 | + optional event data (dict, str, or bytes). |
| 44 | + :param data: The serialized CloudEvent data as a string or bytes. |
| 45 | + :return: A CloudEvent instance constructed from the deserialized data. |
| 46 | + :raises ValueError: If the data cannot be parsed or is invalid according to the format. |
| 47 | + """ |
| 48 | + ... |
| 49 | + |
| 50 | + def write(self, event: BaseCloudEvent) -> bytes: |
| 51 | + """ |
| 52 | + Serialize a CloudEvent to its wire format representation. |
29 | 53 |
|
30 | | - def write(self, event: BaseCloudEvent) -> bytes: ... |
| 54 | + :param event: The CloudEvent instance to serialize. |
| 55 | + :return: The CloudEvent serialized as bytes in the format's wire representation. |
| 56 | + :raises ValueError: If the event cannot be serialized according to the format. |
| 57 | + """ |
| 58 | + ... |
0 commit comments