Peter Meilstrup
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.
From CRAN:
install.packages("msgpack")
From Github:
library(devtools)
install_github("crowding/msgpack-r")
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"))
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")))
Msgpack is fast and compact. See the benchmarking vignette.