Object serialization is available via to_json()
, while de-serialization
is available as from_json()
. Blocks are serialized by writing out
information on the constructor used to create the object, combining this
with block state information, which constitutes values such that when passed
to the constructor the original object can be re-created.
Usage
blockr_ser(x, ...)
# S3 method for class 'block'
blockr_ser(x, state = NULL, ...)
# S3 method for class 'blocks'
blockr_ser(x, blocks = NULL, ...)
# S3 method for class 'board_options'
blockr_ser(x, options = NULL, ...)
# S3 method for class 'board'
blockr_ser(x, blocks = NULL, options = NULL, ...)
# S3 method for class 'link'
blockr_ser(x, ...)
# S3 method for class 'links'
blockr_ser(x, ...)
# S3 method for class 'stack'
blockr_ser(x, ...)
# S3 method for class 'stacks'
blockr_ser(x, ...)
blockr_deser(x, ...)
# S3 method for class 'list'
blockr_deser(x, ...)
# S3 method for class 'block'
blockr_deser(x, data, ...)
# S3 method for class 'blocks'
blockr_deser(x, data, ...)
# S3 method for class 'board'
blockr_deser(x, data, ...)
# S3 method for class 'link'
blockr_deser(x, data, ...)
# S3 method for class 'links'
blockr_deser(x, data, ...)
# S3 method for class 'stack'
blockr_deser(x, data, ...)
# S3 method for class 'stacks'
blockr_deser(x, data, ...)
# S3 method for class 'board_options'
blockr_deser(x, data, ...)
to_json(x, ...)
from_json(x)
Value
Serialization helper function blockr_ser()
returns lists, which
for most objects contain slots object
and payload
, where object
contains a class vector which is used by blockr_deser()
to instantiate an
empty object of that class and use S3 dispatch to identify the correct method
that, given the content in payload
, can re-create the original object.
These are wrapped by to_json()
, which returns JSON and from_json()
which
can consume JSON and returns the original object.
Details
Helper functions blockr_ser()
and blockr_deser()
are implemented as
generics and perform most of the heavy lifting for (de-)serialization:
representing objects as easy-to-serialize (nested) lists containing mostly
strings and no objects which are hard/impossible to truthfully re-create in
new sessions (such as environments).
Examples
blk <- new_dataset_block("iris")
blockr_ser(blk)
#> $object
#> [1] "dataset_block" "data_block" "block" "vctrs_vctr"
#> [5] "list"
#>
#> $payload
#> $payload$dataset
#> [1] "iris"
#>
#> $payload$package
#> [1] "datasets"
#>
#> $payload$name
#> [1] "Dataset block"
#>
#>
#> $constructor
#> [1] "new_dataset_block"
#>
#> $package
#> [1] "blockr.core"
#>
#> $version
#> [1] "0.1.0"
#>
to_json(blk)
#> {"object":["dataset_block","data_block","block","vctrs_vctr","list"],"payload":{"dataset":"iris","package":"datasets","name":"Dataset block"},"constructor":"new_dataset_block","package":"blockr.core","version":"0.1.0"}
all.equal(blk, blockr_deser(blockr_ser(blk)), check.environment = FALSE)
#> [1] TRUE
all.equal(blk, from_json(to_json(blk)), check.environment = FALSE)
#> [1] TRUE