Skip to content

Commit 617a9a5

Browse files
committed
WIP: add EncodingPayloadConverter
1 parent ab0b57a commit 617a9a5

File tree

1 file changed

+36
-1
lines changed

1 file changed

+36
-1
lines changed

tests/test_serialization_context.py

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,7 +1759,42 @@ class UserMethodCalledError(Exception):
17591759
pass
17601760

17611761

1762-
class CustomPayloadConverter(DefaultPayloadConverter):
1762+
class CustomEncodingPayloadConverter(
1763+
EncodingPayloadConverter, WithSerializationContext
1764+
):
1765+
@property
1766+
def encoding(self) -> str:
1767+
return "json/plain"
1768+
1769+
def __init__(self):
1770+
super().__init__()
1771+
self.context: Optional[SerializationContext] = None
1772+
1773+
def to_payload(self, value: Any) -> temporalio.api.common.v1.Payload:
1774+
return super().to_payload(value)
1775+
1776+
def from_payload(
1777+
self,
1778+
payload: temporalio.api.common.v1.Payload,
1779+
type_hint: Optional[Type] = None,
1780+
) -> Any:
1781+
raise NotImplementedError
1782+
1783+
def with_context(
1784+
self, context: Optional[SerializationContext]
1785+
) -> CustomEncodingPayloadConverter:
1786+
converter = CustomEncodingPayloadConverter()
1787+
converter.context = context
1788+
return converter
1789+
1790+
1791+
class CustomPayloadConverter(CompositePayloadConverter):
1792+
def __init__(self):
1793+
super().__init__(
1794+
CustomEncodingPayloadConverter(),
1795+
*DefaultPayloadConverter.default_encoding_payload_converters,
1796+
)
1797+
17631798
def to_payloads(
17641799
self, values: Sequence[Any]
17651800
) -> List[temporalio.api.common.v1.Payload]:

0 commit comments

Comments
 (0)