[Rprotobuf-commits] r509 - pkg/src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 22 05:10:50 CEST 2013


Author: murray
Date: 2013-08-22 05:10:49 +0200 (Thu, 22 Aug 2013)
New Revision: 509

Modified:
   pkg/src/rprotobuf.cpp
Log:
Add function missing from last CL to actually get the extension
descriptor by name.



Modified: pkg/src/rprotobuf.cpp
===================================================================
--- pkg/src/rprotobuf.cpp	2013-08-22 03:05:48 UTC (rev 508)
+++ pkg/src/rprotobuf.cpp	2013-08-22 03:10:49 UTC (rev 509)
@@ -83,7 +83,40 @@
 	return( S4_Descriptor( desc ) ) ;
 }
 
+
 /**
+ * get the descriptor associated with an extension
+ *
+ * @param type message type
+ *
+ * @return an S4 object of class FieldDescriptor, or NULL if the type
+ *  is unknown
+ */
+SEXP getExtensionDescriptor( SEXP type ){
+#ifdef RPB_DEBUG
+Rprintf( "<getExtensionDescriptor>\n      type = " ) ;
+Rf_PrintValue( type ) ;
+#endif
+	
+	const char * typeName = CHAR( STRING_ELT(type, 0 ) ) ;
+	
+	/* first try the generated pool */
+	const GPB::DescriptorPool*  pool = GPB::DescriptorPool::generated_pool() ;
+	const GPB::FieldDescriptor*  desc = pool->FindExtensionByName( typeName ) ; 
+	if( !desc ){
+		/* then try the "runtime" pool" */
+		pool = DescriptorPoolLookup::pool() ;
+		desc = pool->FindExtensionByName( typeName ) ;
+		if( !desc ){
+			/* unlucky */
+			return R_NilValue ;
+		}
+	}
+	
+	return( S4_FieldDescriptor( desc ) ) ;
+}
+
+/**
  * make a new protobuf message
  *
  * @param descriptor a "Descriptor" R object
@@ -233,4 +266,3 @@
 }
 
 } // namespace rprotobuf
-



More information about the Rprotobuf-commits mailing list