From jeff.horner at vanderbilt.edu  Fri Mar 31 00:34:46 2006
From: jeff.horner at vanderbilt.edu (Jeffrey Horner)
Date: Thu, 30 Mar 2006 16:34:46 -0600
Subject: [Rd] Writing character vectors with embedded nulls to a connection
Message-ID: <442C5D06.20309@vanderbilt.edu>

Is this possible? I've tried both writeChar() and writeBin() to no avail.

My goal is to serialize(ascii=FALSE) an object to a connection but 
determine the size of the serialized object before hand:

sobject <- serialize(object,NULL,ascii=FALSE)
len <- nchar(sobject)
#
# run some code here to notify listener on other end of connection
# how many bytes I'm getting ready to send
#
writeChar(sobject,con)

The other option is to serialize twice:

len <- nchar(serialize(object,NULL,ascii=FALSE))
#
# run some code here to notify listener on other end of connection
# how many bytes I'm getting ready to send
#
serialize(object,con,ascii=FALSE)

Object stores, like memcache (http://danga.com/memcached/), need to know 
object sizes before storing. RDBMS's which support large objects (CLOBS 
or BLOBS) don't nececarilly need to know object sizes before-hand, but 
they do have max column size limits which must be honored.

BTW, readchar() can read strings with embedded nulls; I figured 
writeChar() should be able to write them.

-- 
Jeffrey Horner       Computer Systems Analyst         School of Medicine
615-322-8606         Department of Biostatistics   Vanderbilt University



[Rd] Writing character vectors with embedded nulls to a connection
Jeffrey Horner