<div><div>A minor patch for your consideration..</div><div><br></div><div>Add missing readASCIIFromConnection C++ function that was called in read.R but not defined.</div><div>Add examples to the readASCII.Rd help file and tests of ascii export/import of messages.</div>
</div><div>Remove an _ in the readASCII C++ functions to match the naming convention of the other nearby functions.</div><div><br></div><div>----</div><div><br></div><div>Index: R/read.R</div><div>===================================================================</div>
<div>--- R/read.R<span class="Apple-tab-span" style="white-space:pre">        </span>(revision 424)</div><div>+++ R/read.R<span class="Apple-tab-span" style="white-space:pre">        </span>(working copy)</div><div>@@ -35,7 +35,7 @@</div>
<div> </div><div> setMethod( "readASCII", c( descriptor = "Descriptor" , input = "character" ), </div><div> function(descriptor, input ){</div><div>-<span class="Apple-tab-span" style="white-space:pre">        </span>.Call( "Descriptor__readASCII_FromString", descriptor@pointer, input, PACKAGE = "RProtoBuf" ) </div>
<div>+<span class="Apple-tab-span" style="white-space:pre">        </span>.Call( "Descriptor__readASCIIFromString", descriptor@pointer, input, PACKAGE = "RProtoBuf" ) </div><div> } )</div><div> </div><div> setMethod( "readASCII", c( descriptor = "Descriptor" ), </div>
<div>@@ -46,8 +46,7 @@</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>sc <- summary( input )</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>wasopen <- identical( sc[["opened"]], "opened" )</div>
<div> <span class="Apple-tab-span" style="white-space:pre">        </span>if( !wasopen ) open( input )</div><div>-<span class="Apple-tab-span" style="white-space:pre">        </span>message <- .Call( "Descriptor__readASCII_FromConnection", descriptor@pointer, input, PACKAGE = "RProtoBuf" )</div>
<div>+<span class="Apple-tab-span" style="white-space:pre">        </span>message <- .Call( "Descriptor__readASCIIFromConnection", descriptor@pointer, input, PACKAGE = "RProtoBuf" )</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>if( !wasopen ) close( input )</div>
<div> <span class="Apple-tab-span" style="white-space:pre">        </span>message</div><div> } )</div><div>-</div><div>Index: src/wrapper_Descriptor.cpp</div><div>===================================================================</div>
<div>--- src/wrapper_Descriptor.cpp<span class="Apple-tab-span" style="white-space:pre">        </span>(revision 424)</div><div>+++ src/wrapper_Descriptor.cpp<span class="Apple-tab-span" style="white-space:pre">        </span>(working copy)</div>
<div>@@ -164,12 +164,25 @@</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>return( S4_Message( message ) ) ;</div><div> }</div><div> </div><div>-RCPP_FUNCTION_2( S4_Message, METHOD(readASCII_FromString), Rcpp::XPtr<GPB::Descriptor> desc, std::string input){</div>
<div>+RCPP_FUNCTION_2( S4_Message, METHOD(readASCIIFromString), Rcpp::XPtr<GPB::Descriptor> desc, std::string input){</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>GPB::Message* message = PROTOTYPE( desc ) ; </div>
<div> <span class="Apple-tab-span" style="white-space:pre">        </span>GPB::TextFormat::ParseFromString( input, message ) ;</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>return( S4_Message( message ) ) ;</div>
<div> }</div><div> </div><div>+RCPP_FUNCTION_2( S4_Message, METHOD(readASCIIFromConnection), Rcpp::XPtr<GPB::Descriptor> desc, int conn_id){</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>RconnectionCopyingInputStream wrapper( conn_id ) ;</div>
<div>+<span class="Apple-tab-span" style="white-space:pre">        </span>GPB::io::CopyingInputStreamAdaptor stream( &wrapper ) ;</div><div>+</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>/* create a prototype of the message we are going to read */</div>
<div>+<span class="Apple-tab-span" style="white-space:pre">        </span>GPB::Message* message = PROTOTYPE( desc ) ;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>if( !message ){</div><div>+<span class="Apple-tab-span" style="white-space:pre">                </span>throw std::range_error( "could not call factory->GetPrototype(desc)->New()" ) ; </div>
<div>+<span class="Apple-tab-span" style="white-space:pre">        </span>}</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>GPB::TextFormat::Parse( &stream, message ) ;</div><div>+<span class="Apple-tab-span" style="white-space:pre">        </span>return( S4_Message( message ) ) ;</div>
<div>+}</div><div>+</div><div> #undef METHOD</div><div> </div><div> } // namespace rprotobuf</div><div>Index: man/readASCII.Rd</div><div>===================================================================</div><div>--- man/readASCII.Rd<span class="Apple-tab-span" style="white-space:pre">        </span>(revision 424)</div>
<div>+++ man/readASCII.Rd<span class="Apple-tab-span" style="white-space:pre">        </span>(working copy)</div><div>@@ -20,4 +20,21 @@</div><div> }</div><div> }}</div><div> \keyword{methods}</div><div>+\examples{</div><div>+# example file that contains a "tutorial.AddressBook" message</div>
<div>+book <- system.file( "examples", "addressbook.pb", package = "RProtoBuf" )</div><div> </div><div>+# read the message</div><div>+message <- read( tutorial.AddressBook, book )</div>
<div>+</div><div>+# Output in text format to a temporary file</div><div>+out.file <- tempfile()</div><div>+writeLines( as.character(message), file(out.file))</div><div>+</div><div>+# Verify we can read back in the message from a text file.</div>
<div>+message2 <- readASCII( tutorial.AddressBook, file(out.file, "rb"))</div><div>+</div><div>+\dontshow{</div><div>+stopifnot( identical( message, message2) )</div><div>+}</div><div>+}</div><div>Index: inst/unitTests/runit.addressbook.R</div>
<div>===================================================================</div><div>--- inst/unitTests/runit.addressbook.R<span class="Apple-tab-span" style="white-space:pre">        </span>(revision 424)</div><div>+++ inst/unitTests/runit.addressbook.R<span class="Apple-tab-span" style="white-space:pre">        </span>(working copy)</div>
<div>@@ -29,3 +29,13 @@</div><div> checkEquals(book$person[[2]]$phone[[1]]$number, "+01...", msg="Second person phone number")</div><div> checkEquals(book$person[[2]]$phone[[1]]$type, 0, msg="Second person phone number")</div>
<div> }</div><div>+</div><div>+test.ascii <- function() {</div><div>+ # Output in text format to a temporary file</div><div>+ out.file <- tempfile()</div><div>+ writeLines( as.character(book), file(out.file))</div>
<div>+</div><div>+ # Verify we can read back in the message from a text file.</div><div>+ book2 <- readASCII( tutorial.AddressBook, file(out.file, "rb"))</div><div>+ checkEquals(book, book2)</div><div>
+}</div><div><br></div>