Highly Optimized Protocol Buffer Serializers

Pure C++ implementations for reading and writing several common data formats based on Google protocol-buffers. Currently supports 'rexp.proto' for serialized R objects, 'geobuf.proto' for binary geojson, and 'mvt.proto' for vector tiles. This package uses the auto-generated C++ code by protobuf-compiler, hence the entire serialization is optimized at compile time. The 'RProtoBuf' package on the other hand uses the protobuf runtime library to provide a general- purpose toolkit for reading and writing arbitrary protocol-buffer data in R.

Fast and Simple Object Serialization to Protocol Buffers

Build Status AppVeyor Build Status Coverage Status CRAN_Status_Badge CRAN RStudio mirror downloads Github Stars and writing protocol-buffers. Currently supports rexp.proto for serializing R objects and geobuf.proto for geojson data. This lightweight package is complementary to the much larger 'RProtoBuf' package which provides a full featured toolkit for working with protocol-buffers in R.

RProtoBuf vs protolite

This small package contains optimized C++ implementations for reading and writing protocol-buffers. Currently it supports rexp.proto for serializing R objects and geobuf.proto for geojson data. To extend the package with additional formats, put your .proto file in the src directory. The package configure script will automatically generate the code and header file to include in your C++ bindings.

The protolite package is much faster than RProtoBuf because it binds directly to generated C++ code from the protoc compiler. RProtoBuf on the other hand uses the more flexible but slower reflection-based interface, which parses the descriptors at runtime. With RProtoBuf you can create new protocol buffers of a schema, read in arbitrary .proto files, manipulate fields, and generate / parse .prototext ascii format protocol buffers. For more details have a look at our paper: RProtoBuf: Efficient Cross-Language Data Serialization in R.

Serializing R objects

# Serialize and unserialize an object
buf <- serialize_pb(iris)
out <- unserialize_pb(buf)
stopifnot(identical(iris, out))
# 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))

Converting between GeoJSON and GeoBuf

Use the countries.geo.json example data:

# Example data
# Convert geojson to geobuf
buf <- json2geobuf("countries.geo.json")
writeBin(buf, "countries.buf")
# The other way around
geobuf2json(buf) #either in memory
geobuf2json("countries.buf") #or from disk
# Read directly from geobuf
mydata <- read_geobuf("countries.buf")


Binary packages for OS-X or Windows can be installed directly from CRAN:


Installation from source on Linux or OSX requires Google's Protocol Buffers library. On Debian or Ubuntu install libprotobuf-dev and protobuf-compiler:

sudo apt-get install -y libprotobuf-dev protobuf-compiler

On Fedora we need protobuf-devel:

sudo yum install protobuf-devel

On CentOS / RHEL we install protobuf-devel via EPEL:

sudo yum install epel-release
sudo yum install protobuf-devel

On OS-X use protobuf from Homebrew:

brew install protobuf



  • Update to protobuf v3.5.1 on Windows


  • Move autobrew script to external repo
  • Use Rcpp symbol registration and visibility


  • Update protobuf to 3.2.0 on Windows and OSX


  • Fix for Solaris
  • Switch to C++11 on Windows


  • Add support for reading/writing geobuf (binary geojson)


  • Use new Homebrew URL in configure script
  • Switch to CXX_STD=CXX11 to suppress some warnings


  • Fix configure script to test if protoc version matches libprotobuf


  • Cross reference to RProtoBuf pkg in description and readme
  • Add option 'skip_native' in serialize_pb()
  • Fix bug where 'native' objects were stored in 'raw' field


  • Initial CRAN release

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.


2.1 by Jeroen Ooms, 10 months ago

https://jeroen.cran.dev/protolite (website) https://github.com/jeroen/protolite (devel)

Report a bug at https://github.com/jeroen/protolite/issues

Browse source code at https://github.com/cran/protolite

Authors: Jeroen Ooms

Documentation:   PDF Manual  

MIT + file LICENSE license

Imports Rcpp, jsonlite

Suggests spelling, curl, testthat, RProtoBuf, sf

Linking to Rcpp

System requirements: libprotobuf and protobuf-compiler

Imported by geojson, mapboxapi, opencpu.

Suggested by polmineR, rgbif.

See at CRAN