[Rprotobuf-commits] r305 - pkg/R
noreply at r-forge.r-project.org
noreply at r-forge.r-project.org
Thu Apr 8 21:47:08 CEST 2010
Author: romain
Date: 2010-04-08 21:47:08 +0200 (Thu, 08 Apr 2010)
New Revision: 305
Added:
pkg/R/http.handler.R
Modified:
pkg/R/zzz.R
Log:
install RProtoBuf http handler
Added: pkg/R/http.handler.R
===================================================================
--- pkg/R/http.handler.R (rev 0)
+++ pkg/R/http.handler.R 2010-04-08 19:47:08 UTC (rev 305)
@@ -0,0 +1,25 @@
+
+RProtoBuf.http.handler <- function(path, query, body) {
+
+ if( !all( c("service", "method" ) ) %in% names(query) ){
+ stop( "need service and method " )
+ }
+ service <- query[["service"]]
+ method <- query[["method"]]
+
+ m <- get(
+ sprintf( "%s.%s", service, method ),
+ as.environment( "RProtoBuf:DescriptorPool" )
+ )
+ if( is.null( m ) ){
+ stop( "unknown method" )
+ }
+ input <- if( length( body ) ){
+ m$input_type()$read( body )
+ } else{
+ new( m$input_type() )
+ }
+ res <- invoke( m, input )
+ list( serialize( res, NULL ) )
+}
+
Modified: pkg/R/zzz.R
===================================================================
--- pkg/R/zzz.R 2010-04-08 19:21:37 UTC (rev 304)
+++ pkg/R/zzz.R 2010-04-08 19:47:08 UTC (rev 305)
@@ -5,5 +5,10 @@
.Call( "check_libprotobuf_version", minversion, PACKAGE = "RProtoBuf" )
readProtoFiles( package = pkgname )
attachDescriptorPool( pos = length(search()) )
+
+ if( exists( ".httpd.handlers.env", asNamespace( "tools" ) ) ){
+ e <- tools:::.httpd.handlers.env
+ e[["RProtoBuf"]] <- RProtoBuf.http.handler
+ }
}
More information about the Rprotobuf-commits
mailing list