[Rprotobuf-commits] r425 - in pkg: . R inst/unitTests man src
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Mon Jul 18 00:54:27 CEST 2011
Author: edd
Date: 2011-07-18 00:54:26 +0200 (Mon, 18 Jul 2011)
New Revision: 425
Modified:
pkg/ChangeLog
pkg/DESCRIPTION
pkg/R/read.R
pkg/inst/unitTests/runit.addressbook.R
pkg/man/readASCII.Rd
pkg/src/wrapper_Descriptor.cpp
Log:
new patch my Murray
Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog 2011-07-07 19:13:46 UTC (rev 424)
+++ pkg/ChangeLog 2011-07-17 22:54:26 UTC (rev 425)
@@ -1,3 +1,14 @@
+2011-07-17 Dirk Eddelbuettel <edd at debian.org>
+
+ * Applied another patch by Murray:
+ - src/wrapper_Descriptor.cpp: Add missing readASCIIFromConnection
+ C++ function that was called in read.R but not defined.
+ - R/read.R: Remove an _ in the readASCII C++ functions to match the
+ naming convention of the other nearby functions.
+ - man/readASCII.Rd: Add examples of ascii export/import of messages.
+ - inst/unitTests/runit.addressbook.R: Add tests of ascii
+ export/import of messages.
+
2011-07-07 Dirk Eddelbuettel <edd at debian.org>
* src/wrapper_FileDescriptor.cpp (rprotobuf): Applied patch by Murray
Modified: pkg/DESCRIPTION
===================================================================
--- pkg/DESCRIPTION 2011-07-07 19:13:46 UTC (rev 424)
+++ pkg/DESCRIPTION 2011-07-17 22:54:26 UTC (rev 425)
@@ -1,5 +1,5 @@
Package: RProtoBuf
-Version: 0.2.3
+Version: 0.2.4
Date: $Date$
Author: Romain Francois <romain at r-enthusiasts.com> and Dirk Eddelbuettel <edd at debian.org>
Maintainer: Romain and Dirk <RomainAndDirk at r-enthusiasts.com>
Modified: pkg/R/read.R
===================================================================
--- pkg/R/read.R 2011-07-07 19:13:46 UTC (rev 424)
+++ pkg/R/read.R 2011-07-17 22:54:26 UTC (rev 425)
@@ -35,7 +35,7 @@
setMethod( "readASCII", c( descriptor = "Descriptor" , input = "character" ),
function(descriptor, input ){
- .Call( "Descriptor__readASCII_FromString", descriptor at pointer, input, PACKAGE = "RProtoBuf" )
+ .Call( "Descriptor__readASCIIFromString", descriptor at pointer, input, PACKAGE = "RProtoBuf" )
} )
setMethod( "readASCII", c( descriptor = "Descriptor" ),
@@ -46,8 +46,7 @@
sc <- summary( input )
wasopen <- identical( sc[["opened"]], "opened" )
if( !wasopen ) open( input )
- message <- .Call( "Descriptor__readASCII_FromConnection", descriptor at pointer, input, PACKAGE = "RProtoBuf" )
+ message <- .Call( "Descriptor__readASCIIFromConnection", descriptor at pointer, input, PACKAGE = "RProtoBuf" )
if( !wasopen ) close( input )
message
} )
-
Modified: pkg/inst/unitTests/runit.addressbook.R
===================================================================
--- pkg/inst/unitTests/runit.addressbook.R 2011-07-07 19:13:46 UTC (rev 424)
+++ pkg/inst/unitTests/runit.addressbook.R 2011-07-17 22:54:26 UTC (rev 425)
@@ -29,3 +29,13 @@
checkEquals(book$person[[2]]$phone[[1]]$number, "+01...", msg="Second person phone number")
checkEquals(book$person[[2]]$phone[[1]]$type, 0, msg="Second person phone number")
}
+
+test.ascii <- function() {
+ # Output in text format to a temporary file
+ out.file <- tempfile()
+ writeLines( as.character(book), file(out.file))
+
+ # Verify we can read back in the message from a text file.
+ book2 <- readASCII( tutorial.AddressBook, file(out.file, "rb"))
+ checkEquals(book, book2)
+}
Modified: pkg/man/readASCII.Rd
===================================================================
--- pkg/man/readASCII.Rd 2011-07-07 19:13:46 UTC (rev 424)
+++ pkg/man/readASCII.Rd 2011-07-17 22:54:26 UTC (rev 425)
@@ -20,4 +20,21 @@
}
}}
\keyword{methods}
+\examples{
+# example file that contains a "tutorial.AddressBook" message
+book <- system.file( "examples", "addressbook.pb", package = "RProtoBuf" )
+# read the message
+message <- read( tutorial.AddressBook, book )
+
+# Output in text format to a temporary file
+out.file <- tempfile()
+writeLines( as.character(message), file(out.file))
+
+# Verify we can read back in the message from a text file.
+message2 <- readASCII( tutorial.AddressBook, file(out.file, "rb"))
+
+\dontshow{
+stopifnot( identical( message, message2) )
+}
+}
Modified: pkg/src/wrapper_Descriptor.cpp
===================================================================
--- pkg/src/wrapper_Descriptor.cpp 2011-07-07 19:13:46 UTC (rev 424)
+++ pkg/src/wrapper_Descriptor.cpp 2011-07-17 22:54:26 UTC (rev 425)
@@ -164,12 +164,25 @@
return( S4_Message( message ) ) ;
}
-RCPP_FUNCTION_2( S4_Message, METHOD(readASCII_FromString), Rcpp::XPtr<GPB::Descriptor> desc, std::string input){
+RCPP_FUNCTION_2( S4_Message, METHOD(readASCIIFromString), Rcpp::XPtr<GPB::Descriptor> desc, std::string input){
GPB::Message* message = PROTOTYPE( desc ) ;
GPB::TextFormat::ParseFromString( input, message ) ;
return( S4_Message( message ) ) ;
}
+RCPP_FUNCTION_2( S4_Message, METHOD(readASCIIFromConnection), Rcpp::XPtr<GPB::Descriptor> desc, int conn_id){
+ RconnectionCopyingInputStream wrapper( conn_id ) ;
+ GPB::io::CopyingInputStreamAdaptor stream( &wrapper ) ;
+
+ /* create a prototype of the message we are going to read */
+ GPB::Message* message = PROTOTYPE( desc ) ;
+ if( !message ){
+ throw std::range_error( "could not call factory->GetPrototype(desc)->New()" ) ;
+ }
+ GPB::TextFormat::Parse( &stream, message ) ;
+ return( S4_Message( message ) ) ;
+}
+
#undef METHOD
} // namespace rprotobuf
More information about the Rprotobuf-commits
mailing list