Skip to content

Commit 34acf65

Browse files
committed
chore(docs): document Format protocol
Signed-off-by: Tudor Plugaru <[email protected]>
1 parent 3978caf commit 34acf65

File tree

1 file changed

+30
-2
lines changed
  • src/cloudevents/core/formats

1 file changed

+30
-2
lines changed

src/cloudevents/core/formats/base.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,40 @@
1919

2020

2121
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+
2231
def read(
2332
self,
2433
event_factory: Callable[
2534
[dict, Optional[Union[dict, str, bytes]]], BaseCloudEvent
2635
],
2736
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.
2953
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

Comments
 (0)