Skip to content

Fast reading and writing of Msgpack data in R msgpack.org[R]

License

Notifications You must be signed in to change notification settings

crowding/msgpack-r

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

65 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

msgpack for R

Peter Meilstrup

CRAN version badge Travis build status Code coverage

This is a high speed msgpack encoder and decoder for R, based on the CWPack C implementation.

msgpack is a binary data format with data structures similar to JSON and a compact binary encoding. It can be a drop-in replacement for JSON in most applications. It is designed to be fast to parse and compact to transmit and store.

Installation

From CRAN:

install.packages("msgpack")

From Github:

library(devtools)
install_github("crowding/msgpack-r")

Usage

library(msgpack)
x <- packMsg( list(compact=TRUE, schema=0) )
x
##  [1] 82 a7 63 6f 6d 70 61 63 74 c3 a6 73 63 68 65 6d 61 00
dput(unpackMsg( x ))
## structure(list(compact = TRUE, schema = 0L), .Names = c("compact", 
## "schema"))

Connections / Streaming

Write messages one or several at a time:

conOut <- rawConnection(raw(0), open = "w") # or socketConnection, etc
writeMsg("one", conOut)
writeMsgs(list(2, c(buckle=TRUE), c(owner="my", type="shoe")), conOut)

Use a msgConnection object to read messages one or several at a time:

conIn <- msgConnection(rawConnection(rawConnectionValue(conOut), open = "r"))
dput(readMsgs(conIn, 2))
## list("one", 2L)
dput(readMsg(conIn))
## structure(TRUE, .Names = "buckle")
dput(readMsgs(conIn))
## list(structure(c("my", "shoe"), .Names = c("owner", "type")))

Performance

Msgpack is fast and compact. See the benchmarking vignette.

Plot of time taken to transmit dataset, vs size of dataset, for each encoder under four conditions.

Comparison of space used by each encoder to encode a test dataset.

About

Fast reading and writing of Msgpack data in R msgpack.org[R]

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published