register

Applicability

Product

Supported

Atlas A3 training product/Atlas A3 inference product

Atlas A2 training product/Atlas A2 inference product

Atlas 200I/500 A2 inference product

x

Atlas inference product

x

Atlas training product

x

Function Description

Registers the serialization, deserialization, and size calculation functions corresponding to the user-defined type. This function can be used together with the feed and fetch APIs to feed or fetch any Python type.

Prototype

1
register(msg_type, clz, serialize_func, deserialize_func, size_func=None)

Parameters

Parameter

Data Type

Description

msg_type

int

ID of the type to be registered.

clz

Type definition

Type definition, such as int, str, or customized class.

serialize_func

function

Serialization function. It accepts any Python object as input and outputs bytes, which refers to the byte stream generated after the object is serialized.

deserialize_func

function

Deserialization function. It takes bytes as input, representing the byte stream to be deserialized, and outputs the deserialized object, which can be any type of Python objects.

size_func

function

Function for calculating the memory size after serialization, in bytes. This field is reserved.

Returns

None is returned in normal scenarios.

A DfException is thrown upon exceptions. You can catch DfException and retrieve its error_code and message attributes to check the specific error code and error details. For details, see DataFlow Error Codes.

Examples

1
2
3
4
5
6
7
8
9
import cloudpickle
import dataflow as df

class TestClass():
    def __init__(self, name, val):
        self.name = name
        self.val = val

df.msg_type_register.register(1026, TestClass, lambda obj: cloudpickle.dumps(obj), lambda buffer: cloudpickle.loads(buffer))

Constraints

None