spinedb_api.server_client_helpers

Module Contents

Functions

encode(o)

Encodes given object into a message to be sent via a socket, with the following structure:

decode(b)

Decodes given message received via a socket into a Python object.

spinedb_api.server_client_helpers.encode(o)[source]

Encodes given object into a message to be sent via a socket, with the following structure:

body | start of tail character | tail

The body is obtained by JSON-encoding the argument, while replacing all bytes objects by addresses in the tail. The tail is computed by concatenating all bytes objects in the argument. See class:_TailJSONEncoder.

Parameters:

o (any) – A Python object to encode.

Returns:

Encoded message.

Return type:

bytes

spinedb_api.server_client_helpers.decode(b)[source]

Decodes given message received via a socket into a Python object. The message must have the following structure:

body | start of tail character | tail

The result is obtained by JSON-decoding the body, and then replacing all the addresses with the referred bytes from the tail.

Parameters:

b (bytes) – A message to decode.

Returns:

Decoded object.

Return type:

any