[Rprotobuf-commits] r308 - in pkg: R src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Wed Apr 28 15:21:39 CEST 2010


Author: romain
Date: 2010-04-28 15:21:39 +0200 (Wed, 28 Apr 2010)
New Revision: 308

Added:
   pkg/src/wrapper_Message.cpp
Removed:
   pkg/src/serialize.cpp
Modified:
   pkg/R/serialize.R
Log:
move some Message methods to wrapp_Message.cpp

Modified: pkg/R/serialize.R
===================================================================
--- pkg/R/serialize.R	2010-04-28 07:33:17 UTC (rev 307)
+++ pkg/R/serialize.R	2010-04-28 13:21:39 UTC (rev 308)
@@ -21,12 +21,12 @@
 			} else{
 				file <- tools:::file_path_as_absolute(connection)
 			}
-			.Call( "serializeMessageToFile", object at pointer, file, PACKAGE = "RProtoBuf" )
+			.Call( "Message__serialize_to_file", object at pointer, file, PACKAGE = "RProtoBuf" )
 			invisible( NULL)
 		} else if( iscon || isnull ) {
 			
 			# first grab the payload as a raw vector, 
-			payload <- .Call( "getMessagePayload", object at pointer, PACKAGE = "RProtoBuf" )
+			payload <- .Call( "Message__get_payload", object at pointer, PACKAGE = "RProtoBuf" )
 			if( isnull ){
 				# just return it if the connection is NULL
 				payload

Deleted: pkg/src/serialize.cpp
===================================================================
--- pkg/src/serialize.cpp	2010-04-28 07:33:17 UTC (rev 307)
+++ pkg/src/serialize.cpp	2010-04-28 13:21:39 UTC (rev 308)
@@ -1,44 +0,0 @@
-#include "rprotobuf.h"
-#include "connections.h"
-
-namespace rprotobuf{
-
-/**
- * create a raw vector that contains the content of the serialized 
- * message
- *
- * @param xp xternal pointer to the message
- */
-RCPP_FUNCTION_1( Rcpp::RawVector, getMessagePayload, Rcpp::XPtr<GPB::Message> message ){
-
-	/* create a raw vector of the appropriate size */
-	int size = message->ByteSize() ;
-	Rcpp::RawVector payload( size ) ;
-	
-	/* fill the array */
-	message->SerializePartialToArray( payload.begin(), size ); 
-	
-	return( payload ) ;
-}
-
-/** 
- * serialize a message to a file
- *
- * @param xp external pointer to a GPB::Message*
- * @param filename file name where to serialize
- */
-RCPP_FUNCTION_VOID_2( serializeMessageToFile, Rcpp::XPtr<GPB::Message> message, const char* filename){
-	
-	/* open the file in binary mode to write */
-	/* we make sure in the R side that filename is the full path of the file */
-	int file = open( filename, 
-		O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); 
-	
-	/* using partial to allow partially filled messages */
-	message->SerializePartialToFileDescriptor( file ) ;
-	
-	close( file ) ; 
-}
-
-} // namespace rprotobuf
-

Added: pkg/src/wrapper_Message.cpp
===================================================================
--- pkg/src/wrapper_Message.cpp	                        (rev 0)
+++ pkg/src/wrapper_Message.cpp	2010-04-28 13:21:39 UTC (rev 308)
@@ -0,0 +1,92 @@
+#include "rprotobuf.h"
+
+namespace rprotobuf{
+	
+/**
+ * clone a message
+ *
+ * @param xp external pointer to a message
+ * @return a new message, clone of the input message
+ */
+RCPP_FUNCTION_1( S4_Message, Message__clone, Rcpp::XPtr<GPB::Message> message ){
+	/* cloning message as sheep */
+	GPB::Message* sheep = message->New() ;
+	sheep->CopyFrom( *message );
+	
+	return S4_Message( sheep ) ;
+}
+
+/**
+ * TRUE if the message has the field name
+ *
+ * @param xp external pointer to the Message
+ * @param name name of the field
+ */
+RCPP_FUNCTION_2(bool, Message__has_field, Rcpp::XPtr<GPB::Message> message, std::string name ){
+
+	const GPB::Descriptor* desc = message->GetDescriptor(); 
+	const GPB::FieldDescriptor* field_desc = desc->FindFieldByName( name ) ;
+	
+	bool res = false ;
+	if( field_desc ){
+		const GPB::Reflection * ref = message->GetReflection() ;
+		if( field_desc->is_repeated() ){
+			res = ref->FieldSize( *message, field_desc ) > 0 ;
+		} else{
+			res = ref->HasField( *message, field_desc ) ;
+		}
+	}
+	return res ;
+}
+
+
+/**
+ * Check if all required fields are set
+ *
+ * @param xp external pointer to the Message
+ */
+RCPP_FUNCTION_1( bool, Message__is_initialized, Rcpp::XPtr<GPB::Message> message){
+	return message->IsInitialized() ;
+}
+
+
+/** 
+ * serialize a message to a file
+ *
+ * @param xp external pointer to a GPB::Message*
+ * @param filename file name where to serialize
+ */
+RCPP_FUNCTION_VOID_2( Message__serialize_to_file, Rcpp::XPtr<GPB::Message> message, const char* filename){
+	
+	/* open the file in binary mode to write */
+	/* we make sure in the R side that filename is the full path of the file */
+	int file = open( filename, 
+		O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); 
+	
+	/* using partial to allow partially filled messages */
+	message->SerializePartialToFileDescriptor( file ) ;
+	
+	close( file ) ; 
+}
+
+/**
+ * create a raw vector that contains the content of the serialized 
+ * message
+ *
+ * @param xp xternal pointer to the message
+ */
+RCPP_FUNCTION_1( Rcpp::RawVector, Message__get_payload, Rcpp::XPtr<GPB::Message> message ){
+
+	/* create a raw vector of the appropriate size */
+	int size = message->ByteSize() ;
+	Rcpp::RawVector payload( size ) ;
+	
+	/* fill the array */
+	message->SerializePartialToArray( payload.begin(), size ); 
+	
+	return( payload ) ;
+}
+
+
+}
+



More information about the Rprotobuf-commits mailing list