[Rprotobuf-commits] r383 - in pkg: . R src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Fri Aug 20 12:31:41 CEST 2010


Author: romain
Date: 2010-08-20 12:31:40 +0200 (Fri, 20 Aug 2010)
New Revision: 383

Modified:
   pkg/NAMESPACE
   pkg/R/00classes.R
   pkg/R/completion.R
   pkg/R/read.R
   pkg/src/rprotobuf.h
   pkg/src/wrapper_Descriptor.cpp
Log:
added a readASCII method (currently only reading from a character string)

Modified: pkg/NAMESPACE
===================================================================
--- pkg/NAMESPACE	2010-08-14 19:24:05 UTC (rev 382)
+++ pkg/NAMESPACE	2010-08-20 10:31:40 UTC (rev 383)
@@ -33,7 +33,7 @@
 
 exportMethods( "new", "[[", "[[<-", "$", "$<-", "show",
 	"serialize", "as.character", "update",
-	"has", "clone", "merge", "read", "bytesize",
+	"has", "clone", "merge", "read", "readASCII", "bytesize",
 	"length", "str", "isInitialized",
 	"clear", "size", "size<-", "swap",
 	"descriptor", "set", "fetch", "toString",

Modified: pkg/R/00classes.R
===================================================================
--- pkg/R/00classes.R	2010-08-14 19:24:05 UTC (rev 382)
+++ pkg/R/00classes.R	2010-08-20 10:31:40 UTC (rev 383)
@@ -186,6 +186,7 @@
 	switch( name, 
 		"new" = function( ... ) newProto( x, ... ) , 
 		"read" = function( input ) read( x, input ) ,
+		"readASCII" = function( input ) readASCII( x, input ), 
 		"toString" = function(...) toString(x, ...) ,
 		"as.character" = function(...) as.character(x, ...) ,
 		"as.list" = function(...) as.character(x, ...) ,

Modified: pkg/R/completion.R
===================================================================
--- pkg/R/completion.R	2010-08-14 19:24:05 UTC (rev 382)
+++ pkg/R/completion.R	2010-08-20 10:31:40 UTC (rev 383)
@@ -29,7 +29,7 @@
 	
 	names <- c( 
 		.Call( "Descriptor__getMemberNames", x at pointer, PACKAGE = "RProtoBuf" ), 
-		"new(", "read(", "fileDescriptor()", "name(", "fileDescriptor()", 
+		"new(", "read(", "readASCII(", "fileDescriptor()", "name(", "fileDescriptor()", 
 		"containing_type()", "field_count()", "nested_type_count()", "enum_type_count", 
 		"field(", "nested_type(", "enum_type(" )
 	grep( pattern, names, value = TRUE )

Modified: pkg/R/read.R
===================================================================
--- pkg/R/read.R	2010-08-14 19:24:05 UTC (rev 382)
+++ pkg/R/read.R	2010-08-20 10:31:40 UTC (rev 383)
@@ -26,3 +26,28 @@
 	message
 } )
 
+
+
+
+setGeneric( "readASCII", function( descriptor, input ){
+	standardGeneric( "readASCII" )
+} )
+
+setMethod( "readASCII", c( descriptor = "Descriptor" , input = "character" ), 
+function(descriptor, input ){
+	.Call( "Descriptor__readASCII_FromString", descriptor at pointer, input, PACKAGE = "RProtoBuf" ) 
+} )
+
+setMethod( "readASCII", c( descriptor = "Descriptor" ), 
+function( descriptor, input ){
+	if( !inherits( input, "connection" ) ){ 
+		stop( "can only read from connections" )
+	}
+	sc <- summary( input )
+	wasopen <- identical( sc[["opened"]], "opened" )
+	if( !wasopen ) open( input )
+	message <- .Call( "Descriptor__readASCII_FromConnection", descriptor at pointer, input, PACKAGE = "RProtoBuf" )
+	if( !wasopen ) close( input )
+	message
+} )
+

Modified: pkg/src/rprotobuf.h
===================================================================
--- pkg/src/rprotobuf.h	2010-08-14 19:24:05 UTC (rev 382)
+++ pkg/src/rprotobuf.h	2010-08-20 10:31:40 UTC (rev 383)
@@ -35,6 +35,7 @@
 #include <google/protobuf/io/coded_stream.h>
 #include <google/protobuf/service.h>
 #include <google/protobuf/descriptor.pb.h>
+#include <google/protobuf/text_format.h>
 namespace GPB = google::protobuf;
 
 #define R_NO_REMAP

Modified: pkg/src/wrapper_Descriptor.cpp
===================================================================
--- pkg/src/wrapper_Descriptor.cpp	2010-08-14 19:24:05 UTC (rev 382)
+++ pkg/src/wrapper_Descriptor.cpp	2010-08-20 10:31:40 UTC (rev 383)
@@ -163,7 +163,13 @@
 	message->MergePartialFromCodedStream( &stream ) ;
 	return( S4_Message( message ) ) ;
 }
-	
+
+RCPP_FUNCTION_2( S4_Message, METHOD(readASCII_FromString), Rcpp::XPtr<GPB::Descriptor> desc, std::string input){
+	GPB::Message* message = PROTOTYPE( desc ) ; 
+	GPB::TextFormat::ParseFromString( input, message ) ;
+	return( S4_Message( message ) ) ;
+}
+
 #undef METHOD
 
 } // namespace rprotobuf



More information about the Rprotobuf-commits mailing list