See the full example here
Python is a dynamic language, and its flexibility makes it challenging to design a universal serialization layer as seen in other languages. Therefore, we have removed the “serialization layer” and left it to the users to implement (since users know the formats of the data they will pass).
Serialization typically consists of two parts: serialization and deserialization. We have defined the types for these functions, and custom serialization/deserialization functions must adhere to these “formats.”
First, for serialization functions, we specify:
Next, for deserialization functions, we specify:
Below, I’ll demonstrate how to use custom functions with protobuf
and json
.
For defining and compiling protobuf
files, please refer to the protobuf tutorial for detailed instructions.
Set xxx_serializer
and xxx_deserializer
in the client and server.
client
server
protobuf
does not fully illustrate how to implement custom serialization and deserialization because its built-in functions perfectly meet the requirements. Instead, I’ll demonstrate how to create custom serialization and deserialization functions using orjson
:
Install orjson
:
Define serialization and deserialization functions:
client
server