<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( &quot;readASCII&quot;, c( descriptor = &quot;Descriptor&quot; , input = &quot;character&quot; ), </div><div> function(descriptor, input ){</div><div>-<span class="Apple-tab-span" style="white-space:pre">        </span>.Call( &quot;Descriptor__readASCII_FromString&quot;, descriptor@pointer, input, PACKAGE = &quot;RProtoBuf&quot; ) </div>
<div>+<span class="Apple-tab-span" style="white-space:pre">        </span>.Call( &quot;Descriptor__readASCIIFromString&quot;, descriptor@pointer, input, PACKAGE = &quot;RProtoBuf&quot; ) </div><div> } )</div><div> </div><div> setMethod( &quot;readASCII&quot;, c( descriptor = &quot;Descriptor&quot; ), </div>
<div>@@ -46,8 +46,7 @@</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>sc &lt;- summary( input )</div><div> <span class="Apple-tab-span" style="white-space:pre">        </span>wasopen &lt;- identical( sc[[&quot;opened&quot;]], &quot;opened&quot; )</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 &lt;- .Call( &quot;Descriptor__readASCII_FromConnection&quot;, descriptor@pointer, input, PACKAGE = &quot;RProtoBuf&quot; )</div>
<div>+<span class="Apple-tab-span" style="white-space:pre">        </span>message &lt;- .Call( &quot;Descriptor__readASCIIFromConnection&quot;, descriptor@pointer, input, PACKAGE = &quot;RProtoBuf&quot; )</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&lt;GPB::Descriptor&gt; desc, std::string input){</div>
<div>+RCPP_FUNCTION_2( S4_Message, METHOD(readASCIIFromString), Rcpp::XPtr&lt;GPB::Descriptor&gt; 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&lt;GPB::Descriptor&gt; 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( &amp;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( &quot;could not call factory-&gt;GetPrototype(desc)-&gt;New()&quot; ) ; </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( &amp;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 &quot;tutorial.AddressBook&quot; message</div>
<div>+book &lt;- system.file( &quot;examples&quot;, &quot;addressbook.pb&quot;, package = &quot;RProtoBuf&quot; )</div><div> </div><div>+# read the message</div><div>+message &lt;- read( tutorial.AddressBook, book )</div>
<div>+</div><div>+# Output in text format to a temporary file</div><div>+out.file &lt;- 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 &lt;- readASCII( tutorial.AddressBook, file(out.file, &quot;rb&quot;))</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, &quot;+01...&quot;,            msg=&quot;Second person phone number&quot;)</div><div>     checkEquals(book$person[[2]]$phone[[1]]$type,   0,                   msg=&quot;Second person phone number&quot;)</div>
<div> }</div><div>+</div><div>+test.ascii &lt;- function() {</div><div>+    # Output in text format to a temporary file</div><div>+    out.file &lt;- 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 &lt;- readASCII( tutorial.AddressBook, file(out.file, &quot;rb&quot;))</div><div>+    checkEquals(book, book2)</div><div>
+}</div><div><br></div>