Description Usage Arguments Details Value Examples
A msgConnection
object decodes msgpack messages from an
underlying R raw connection.
readMsg(con)
reads exactly one message from a
msgConnection, or throws an error.
writeMsg(x, con)
writes a single message to a msgConnection.
writeMsg
will work with any R connection in raw mode, but reading
requires a msgConnection object.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | msgConnection(con, read_size = 2^16, max_size = NA, ...)
## S3 method for class 'msgConnection'
close(con, ...)
partial(con)
## S3 method for class 'msgConnection'
partial(con)
readMsgs(con, n = NA, ...)
status(con)
## S3 method for class 'msgConnection'
status(con)
## S3 method for class 'msgConnection'
seek(con, rw = summary(con)$mode, ...)
readMsg(con, ...)
writeMsg(obj, con, ...)
writeMsgs(objs, con, ...)
|
con |
A connection object open in binary mode. |
read_size |
How many bytes to read at a time. |
max_size |
The largest partial message to store, in
bytes. |
... |
Unpacking options (see unpackMsg). |
n |
The maximum number of messages to read. A value of NA means to parse all available messages until end of input. |
rw |
See |
obj |
An R object. |
objs |
A list of R objects. |
Because msgpack messages have unpredictable length, the decoder reads ahead in chunks, then finds the boundaries between messages. Therefore when reading over a socket or a fifo it is best to use a nonblocking connection, and it will not work to mix readMsg and readBin on the same connection.
If you are reading data from a not completely trusted source you
should specify options max_size
and max_depth
(see
unpackOpts). Without it, some deeply nested or cleverly designed
messages can cause a stack overflow or out-of-memory error. With
these options set, you will get an R exception instead.
msgConnection()
returns an object of class
msgConnection
.
partial(con)
returns any data that has been read ahead of
the last decoded message.
readMsgs(con, n)
returns a list of up to n
decoded messages.
status(con)
returns the status of msgpack decoding on the
connection. A value of "ok"
indicates all requested messages
were read, "buffer underflow"
for a non-blocking connection
indicates that only part of a message has been received, and
"end of input"
means the last available message has been read.
Other values indicate errors encountered in decoding, which will
effectively halt reading.
seek(con)
returns the number of bytes that have been
successfully read or written, depending on the mode of the
connection. (Repositioning is not supported.)
readMsg(con)
returns one decoded message.
1 2 3 4 5 6 | out <- rawConnection(raw(0), open="wb")
apply(quakes, 1, function(x) writeMsg(x, out))
length(rawConnectionValue(out))
inn <- msgConnection(rawConnection(rawConnectionValue(out), open="rb"))
readMsg(inn)
readMsgs(inn, 3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.