serialize_pb: Serialize to Protocol Buffers

Description Usage Arguments Details Examples

View source: R/serialize_pb.R

Description

Serializes R objects to a general purpose protobuf message. It uses the same rexp.proto descriptor and mapping between R objects and protobuf messages as RHIPE and the RProtoBuf package.

Usage

1
2
3
serialize_pb(object, connection = NULL, skip_native = FALSE)

unserialize_pb(msg)

Arguments

object

an R object to serialize

connection

a connection, file, or NULL for a raw vector

skip_native

do not serialize 'native' (non-data) R objects. Setting to TRUE will only serialize data types (numeric, boolean, string, raw, list). The default behavior is to fall back on base R serialize for non-data objects.

msg

raw vector with the serialized rexp.proto message

Details

The serialize_pb and unserialize_pb reimplement the identically named functions from the RProtoBuf package in pure C++. This makes the function faster and simpler, but the output should be identical.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
# Serialize and unserialize an object
buf <- serialize_pb(iris)
out <- unserialize_pb(buf)
stopifnot(identical(iris, out))

## Not run:  #Fully compatible with RProtoBuf
buf <- RProtoBuf::serialize_pb(iris, NULL)
out <- protolite::unserialize_pb(buf)
stopifnot(identical(iris, out))

# Other way around
buf <- protolite::serialize_pb(mtcars, NULL)
out <- RProtoBuf::unserialize_pb(buf)
stopifnot(identical(mtcars, out))

## End(Not run)

protolite documentation built on July 28, 2021, 5:09 p.m.