Returns a serialization configuration for custom serialization and unserialization of non-system reference objects, using the 'refhook' system of R native serialization. This allows their use across different R sessions.
Arguments
- class
character string of the class of object custom serialization functions are applied to, e.g. ‘ArrowTabular’ or ‘torch_tensor’.
- sfunc
a function that accepts a reference object inheriting from ‘class’ (or a list of such objects) and returns a raw vector.
- ufunc
a function that accepts a raw vector and returns a reference object (or list of such objects).
- vec
[default FALSE] whether or not the serialization functions are vectorized. If FALSE, they should accept and return reference objects individually e.g.
arrow::write_to_raw
andarrow::read_ipc_stream
. If TRUE, they should accept and return a list of reference objects, e.g.torch::torch_serialize
andtorch::torch_load
.
Value
A pairlist comprising the configuration. This may be provided to the
'hook' argument of serialize
and unserialize
.
Examples
serial_config("test_class", base::serialize, base::unserialize)
#> [[1]]
#> [1] "test_class"
#>
#> [[2]]
#> function (object, connection, ascii = FALSE, xdr = TRUE, version = NULL,
#> refhook = NULL)
#> {
#> if (!is.null(connection)) {
#> if (!inherits(connection, "connection"))
#> stop("'connection' must be a connection")
#> if (missing(ascii))
#> ascii <- summary(connection)$text == "text"
#> }
#> if (!ascii && inherits(connection, "sockconn"))
#> .Internal(serializeb(object, connection, xdr, version,
#> refhook))
#> else {
#> type <- if (is.na(ascii))
#> 2L
#> else if (ascii)
#> 1L
#> else if (!xdr)
#> 3L
#> else 0L
#> .Internal(serialize(object, connection, type, version,
#> refhook))
#> }
#> }
#> <bytecode: 0x55592c5602d8>
#> <environment: namespace:base>
#>
#> [[3]]
#> 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: 0x55592ed51010>
#> <environment: namespace:base>
#>
#> [[4]]
#> [1] FALSE
#>