serialize_pb: Serializes R object to Protocol Buffer Message.

Description Usage Arguments Details Value Examples

View source: R/serialize_pb.R

Description

This function serializes an arbitrary R object to a general purpose protobuf message. Note that for a 3rd party client to read the object, it needs to have the rexp.proto file, which is included in the package installation "proto" directory.

Usage

1
2
  serialize_pb(object, connection,
    proto = c("rexp", "dataframe", "stocks"), ...)

Arguments

object

R object to serialize

connection

an open connection or (for 'serialize') 'NULL' or (for 'unserialize') a raw vector (see 'Details').

...

arguments passed on to serialize()

Details

This function serializes R objects to a general purpose protobuf message that was designed exactly for this purpose. The .proto schema is borrowed from the RHIPE project, which uses protocol buffers to serialize R objects for use with HADOOP. One can find the proto file at this location:

system.file(package="RProtoBufUtils", "proto/rexp.proto")

In order for a third party to unserialize the message, they will need both the serialized data and the rexp.proto file.

Note that for now only regular S3 data objects will be serialized. Special object like functions, expressions, formulas, environments, S4 classes, etc are skipped with a warning. However, missing values, attributes and numeric precision will be preserved.

Value

For 'serialize', 'NULL' unless 'connection = NULL', when the result is returned in a raw vector.

Examples

1
2
3
4
msg <- tempfile();
serialize_pb(iris, msg);
obj <- unserialize_pb(msg);
identical(iris, obj);

jeroenooms/RProtoBufUtils documentation built on May 17, 2017, 6:16 p.m.