DefaultSerialiser

class statefun_tasks.DefaultSerialiser(known_proto_types=None, protobuf_converters=None, use_legacy_types=False)

Default protobuf serialiser for Flink Tasks

Parameters:
  • known_proto_types (Iterable[Type[Message]]) – an array of known protobuf types that will not be packed inside Any

  • protobuf_converters (Iterable[ObjectProtobufConverter]) – an array of custom converters used to transform Python objects to and from protobuf.

  • use_legacy_types (bool) – whether to use legacy types for serialization. Legacy types are less efficient at serialising nested structures.

__init__(known_proto_types=None, protobuf_converters=None, use_legacy_types=False)

Methods

__init__([known_proto_types, ...])

deserialise_args_and_kwargs(request)

Deserialises Any into Python args and kwargs

deserialise_request(task_request)

Deserialises a TaskRequest back into args, kwargs and state

deserialise_result(task_result)

Deserialises 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)

Deserialises 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)

Deserialises 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 message

  • default – an optional default value to return

Returns:

the Python type or default value if deserialisation returns 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 (legacy) or ValueArgsAndKwargs 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 TaskRequest

  • request (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 TaskResult

  • result – 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