DefaultSerialiser
- class statefun_tasks.DefaultSerialiser(known_proto_types=None, protobuf_converters=None)
Default protobuf serialiser for Flink Tasks
- Parameters:
known_proto_types (
Optional
[Iterable
[Type
[Message
]]]) – an array of known protobuf types that will not be packed inside Any
- __init__(known_proto_types=None, protobuf_converters=None)
Methods
__init__
([known_proto_types, ...])deserialise_args_and_kwargs
(request)Deserialises Any into Python args and kwargs
deserialise_request
(task_request)Dserialises a TaskRequest back into args, kwargs and state
deserialise_result
(task_result)Dserialises a TaskResult back into result and state
from_proto
(proto[, default])Converts from protobuf to Python
register_converters
(converters)register_proto_types
(proto_types)serialise_args_and_kwargs
(args, kwargs)Serialises Python args and kwargs into protobuf
serialise_request
(task_request, request[, ...])Serialises args, kwargs and optional state into a TaskRequest
serialise_result
(task_result, result, state)Serialises the result of a task invocation into a TaskResult
to_proto
(item)Converts from Python to protobuf
- deserialise_args_and_kwargs(request)
Deserialises Any into Python args and kwargs
- Parameters:
request (
Any
) – the protobuf message- Returns:
tuple of args and kwargs
- deserialise_request(task_request)
Dserialises a TaskRequest back into args, kwargs and state
- Parameters:
task_request (
TaskRequest
) – the TaskRequest- Returns:
tuple of task args, kwargs and state
- deserialise_result(task_result)
Dserialises a TaskResult back into result and state
- Parameters:
task_result (
TaskResult
) – the TaskResult- Returns:
tuple of result and state
- from_proto(proto, default=None)
Converts from protobuf to Python
- Parameters:
proto (
Message
) – the protobuf messagedefault (option) – an optional default value to return
- Returns:
the Python type or default value if deserialisation return None
- serialise_args_and_kwargs(args, kwargs)
Serialises Python args and kwargs into protobuf
If there is a single arg and no kwargs and the arg is already a protobuf it returns that instance packed inside an Any. Otherwise it returns an ArgsAndKwargs packed in an Any.
- Parameters:
args – the Python args
kwargs – the Python kwargs
- Return type:
Any
- Returns:
protobuf Any
- serialise_request(task_request, request, state=None, retry_policy=None)
Serialises args, kwargs and optional state into a TaskRequest
- Parameters:
task_request (
TaskRequest
) – the TaskRequestrequest (
Any
) – request (proto format)state (optional) – task state
retry_policy (optional) – task retry policy
- serialise_result(task_result, result, state)
Serialises the result of a task invocation into a TaskResult
- Parameters:
task_result (
TaskResult
) – the TaskResultresult – task result
state – task state
- to_proto(item)
Converts from Python to protobuf
- Parameters:
item – the item to convert
- Return type:
Message
- Returns:
the protobuf message possibly packed in an Any