Title: | Highly Optimized Protocol Buffer Serializers |
---|---|
Description: | 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. |
Authors: | Jeroen Ooms [aut, cre] |
Maintainer: | Jeroen Ooms <[email protected]> |
License: | MIT + file LICENSE |
Version: | 2.3.1 |
Built: | 2024-11-02 05:58:33 UTC |
Source: | https://github.com/jeroen/protolite |
The geobuf format is an optimized
binary format for storing geojson
data with protocol buffers. These
functions are compatible with the geobuf2json
and json2geobuf
utilities from the geobuf npm package.
read_geobuf(x, as_data_frame = TRUE) geobuf2json(x, pretty = FALSE) json2geobuf(json, decimals = 6)
read_geobuf(x, as_data_frame = TRUE) geobuf2json(x, pretty = FALSE) json2geobuf(json, decimals = 6)
x |
file path or raw vector with the serialized |
as_data_frame |
simplify geojson data into data frames |
pretty |
indent json, see jsonlite::toJSON |
json |
a text string with geojson data |
decimals |
how many decimals (digits behind the dot) to store for numbers |
Read Mapbox vector-tile (mvt) files and returns the list of layers.
read_mvt_data(data, as_latlon = TRUE, zxy = NULL) read_mvt_sf(data, crs = 4326, zxy = NULL)
read_mvt_data(data, as_latlon = TRUE, zxy = NULL) read_mvt_sf(data, crs = 4326, zxy = NULL)
data |
url, path or raw vector with the mvt data |
as_latlon |
return the data as lat/lon instead of raw EPSG:3857 positions |
zxy |
vector of length 3 with respectively z (zoom), x (column) and y (row).
For file/url in the standard |
crs |
desired output coordinate system (passed to sf::st_transform). Note that mvt input is always by definition 3857. |
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.
serialize_pb(object, connection = NULL, skip_native = FALSE) unserialize_pb(msg)
serialize_pb(object, connection = NULL, skip_native = FALSE) unserialize_pb(msg)
object |
an R object to serialize |
connection |
a connection, file, or |
skip_native |
do not serialize 'native' (non-data) R objects. Setting to |
msg |
raw vector with the serialized |
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.
# 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)
# 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)