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

serialization(refhook = list(), class = "", vec = FALSE)

Arguments

refhook

either a list or pairlist of two functions: the signature for the first must accept a reference object inheriting from 'class' (or a list of such objects) and return a raw vector, and the second must accept a raw vector and return reference objects (or a list of such objects),
or else NULL to reset.

class

[default ""] a character string representing the class of object that these serialization function will be applied to, e.g. 'ArrowTabular' or 'torch_tensor'.

vec

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

Value

Invisibly, the pairlist of currently-registered 'refhook' functions. A message is printed to the console when functions are successfully registered or reset.

Details

Calling without any arguments returns the pairlist of currently-registered 'refhook' functions.

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

Examples

r <- serialization(list(function(x) serialize(x, NULL), unserialize))
print(serialization())
#> [[1]]
#> function(x) serialize(x, NULL)
#> <environment: 0x5635ca2ead88>
#> 
#> [[2]]
#> function (connection, refhook = NULL) 
#> {
#>     if (typeof(connection) != "raw" && !is.character(connection) && 
#>         !inherits(connection, "connection")) 
#>         stop("'connection' must be a connection")
#>     .Internal(unserialize(connection, refhook))
#> }
#> <bytecode: 0x5635c9e58198>
#> <environment: namespace:base>
#> 
serialization(r)

serialization(NULL)
print(serialization())
#> [[1]]
#> NULL
#> 
#> [[2]]
#> NULL
#>