serialization {mirai}R Documentation

Custom Serialization Functions

Description

Registers custom serialization and unserialization functions for sending and receiving reference objects.

Usage

serialization(fns, class, vec = FALSE)

Arguments

fns

either a list comprising 2 functions:
serialization function: must accept a reference object (or list of objects) inheriting from ‘class’ and return a raw vector.
unserialization function: must accept a raw vector and return a reference object (or list of reference objects).
or else NULL to reset.

class

the class of reference object (as a character string) that these functions are applied to, e.g. 'ArrowTabular' or 'torch_tensor'.

vec

[default FALSE] if FALSE the functions must accept and return reference objects individually e.g. arrow::write_to_raw and arrow::read_ipc_stream. If TRUE, the functions are vectorized and must accept and return a list of reference objects, e.g. torch::torch_serialize and torch::torch_load.

Details

Registering new functions replaces any existing registered functions.

This function may be called prior to or after setting daemons, with the registered functions applying across all compute profiles.

Calling without any arguments returns a list comprising the registered values for 'fns', class', and 'vec', or else NULL if not registered.

Value

Invisibly, a list comprising 'fns', class', and 'vec', or else NULL if supplied to 'fns'.

Examples

reg <- serialization(
  list(function(x) serialize(x, NULL), base::unserialize),
  class = "example_class"
)
reg

serialization(NULL)
print(serialization())


[Package mirai version 1.1.1 Index]