Skip to content

How can C++ read the R object written into socket with saveRDS or save

4 messages · Rong lI Li, Brian Ripley, Dirk Eddelbuettel +1 more

#
On 25/06/2013 16:52, Rong lI Li wrote:
R-help was really the wrong list: see the posting guide. And multiple 
posting is really discouraged.

But see package 'parallel' which has lots of examples of doing this.
It may do ... depending how you call it.  You may prefer to serialize() 
to a raw vector whose size you can find, and transmit that.
You were asked not to send HTML.

  
    
#
On 25 June 2013 at 17:12, Prof Brian Ripley wrote:
| On 25/06/2013 16:52, Rong lI Li wrote:
| > I found actually, the saveRDS writes the R object with XDR format. I could
| 
| It may do ... depending how you call it.  You may prefer to serialize() 
| to a raw vector whose size you can find, and transmit that.

I am not aware of a (simple) library parsing this outside of an R context
(and within the R context, I'd always start with Rserve from RForge.net).

But you could look into general serialization / translation libraries such as
Google Protocol Buffers (see https://developers.google.com/protocol-buffers/)
which can also translate into C++, Java, Python plus a host of
user-contributed bindings. 

For R, you will find a package RProtoBuf on CRAN.  There are other, related
libraries but I have worked only with Protocol Buffers.

Dirk
1 day later
#
On Jun 25, 2013, at 11:52 AM, Rong lI Li wrote:

            
There is nothing preventing you from adding a frame with the size of the serialization - that is what Rserve does (mentioned earlier by Dirk - it even has a C++ client ...): it uses a fixed-size header that specifies the kind of payload and its length, then the serialization follows in the payload. That way you only need to read a fixed header.

Cheers,
Simon