From noreply at r-forge.r-project.org Sun Dec 15 00:19:50 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Dec 2013 00:19:50 +0100 (CET) Subject: [Rprotobuf-commits] r543 - in pkg: . inst/unitTests man Message-ID: <20131214231950.9EF1B18517B@r-forge.r-project.org> Author: murray Date: 2013-12-15 00:19:49 +0100 (Sun, 15 Dec 2013) New Revision: 543 Modified: pkg/ChangeLog pkg/inst/unitTests/runit.bytes.R pkg/man/clone.Rd Log: Add a unit test for correct behavior of required bytes fields for issue reported on the list. Also, fix a documentation typo. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-11-15 03:30:47 UTC (rev 542) +++ pkg/ChangeLog 2013-12-14 23:19:49 UTC (rev 543) @@ -1,3 +1,9 @@ +2013-12-14 Murray Stokely + + * inst/unitTests/runit.bytes.R (test.all): Verify raw(10) can be + set to required bytes fields to verify correct behavior for use + case mentioned on rprotobuf-yada list. + 2013-11-13 Murray Stokely * R/extensions.R: Give a user friendly error message if someone tries Modified: pkg/inst/unitTests/runit.bytes.R =================================================================== --- pkg/inst/unitTests/runit.bytes.R 2013-11-15 03:30:47 UTC (rev 542) +++ pkg/inst/unitTests/runit.bytes.R 2013-12-14 23:19:49 UTC (rev 543) @@ -18,4 +18,9 @@ checkEquals(rawToChar(test1$req), "abc") checkEquals(rawToChar(test1$opt), "hello world") checkEquals(test1$rep, list(charToRaw("def"), raw(10), charToRaw("ghi"))) + + # Test raw(10) can be set to a single req field. + test$req <- raw(10) + checkEquals(length(test$req), 10) + checkTrue(all(blob$content == raw(10))) } Modified: pkg/man/clone.Rd =================================================================== --- pkg/man/clone.Rd 2013-11-15 03:30:47 UTC (rev 542) +++ pkg/man/clone.Rd 2013-12-14 23:19:49 UTC (rev 543) @@ -3,7 +3,7 @@ \alias{clone} \alias{clone-methods} \alias{clone,Message-method} -\title{Clone protocolo buffer messages} +\title{Clone protocol buffer messages} \description{ Generic "clone" function and associated method for \linkS4class{Message} objects From noreply at r-forge.r-project.org Sun Dec 15 00:47:22 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Dec 2013 00:47:22 +0100 (CET) Subject: [Rprotobuf-commits] r544 - in pkg: . inst inst/unitTests src Message-ID: <20131214234722.DC1E3186783@r-forge.r-project.org> Author: murray Date: 2013-12-15 00:47:22 +0100 (Sun, 15 Dec 2013) New Revision: 544 Modified: pkg/ChangeLog pkg/DESCRIPTION pkg/inst/NEWS.Rd pkg/inst/unitTests/runit.bytes.R pkg/src/mutators.cpp Log: Merge a fix I had made internally at Google over a year ago which fixes the handling of repeated raw characters. This problem was reported on the protobuf list today. Also add more tests, summarize the recent changes into the NEWS.Rd file and update the version number to 0.3.2 in anticipation of the next CRAN release. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-14 23:19:49 UTC (rev 543) +++ pkg/ChangeLog 2013-12-14 23:47:22 UTC (rev 544) @@ -1,5 +1,8 @@ 2013-12-14 Murray Stokely + * src/mutators.cpp (rprotobuf): Fix a bug which incorrectly + prevented users from setting raw non-repeated fields under some + circumstances. * inst/unitTests/runit.bytes.R (test.all): Verify raw(10) can be set to required bytes fields to verify correct behavior for use case mentioned on rprotobuf-yada list. Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-12-14 23:19:49 UTC (rev 543) +++ pkg/DESCRIPTION 2013-12-14 23:47:22 UTC (rev 544) @@ -1,5 +1,5 @@ Package: RProtoBuf -Version: 0.3.1.1 +Version: 0.3.2 Date: $Date$ Author: Romain Francois, Dirk Eddelbuettel and Murray Stokely Maintainer: Dirk Eddelbuettel Modified: pkg/inst/NEWS.Rd =================================================================== --- pkg/inst/NEWS.Rd 2013-12-14 23:19:49 UTC (rev 543) +++ pkg/inst/NEWS.Rd 2013-12-14 23:47:22 UTC (rev 544) @@ -2,7 +2,20 @@ \title{News for Package \pkg{RProtoBuf}} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} -% TODO(edd): Update date and version number. +\section{Changes in RProtoBuf version 0.3.2 (2013-12-15)}{ + \itemize{ + \item Fixed a bug that erroneously prevented users from setting raw + byte fields in protocol buffers under certain circumstances. + \item Give a user friendly error message when seting an extension to + a message of the wrong type instead of causing a C++ check failure + that terminates the Rsession. + \item Change object table lookup slightly to allow users to use the + '<<-' operator in code using RProtoBuf without hitting a stop() error + in the lookup routine. + \item Improve documentation and tests for all of the above. + } +} + \section{Changes in RProtoBuf version 0.3.1 (2013-09-13)}{ \itemize{ \item Added support for setting and getting 64-bit integer types as Modified: pkg/inst/unitTests/runit.bytes.R =================================================================== --- pkg/inst/unitTests/runit.bytes.R 2013-12-14 23:19:49 UTC (rev 543) +++ pkg/inst/unitTests/runit.bytes.R 2013-12-14 23:47:22 UTC (rev 544) @@ -9,6 +9,8 @@ test.all <- function() { test <- new(TestBytes, req = "abc", rep = list(charToRaw("def"), raw(10))) checkEquals(rawToChar(test$req), "abc") + test$req <- charToRaw("abc") + checkEquals(rawToChar(test$req), "abc") checkEquals(rawToChar(test$opt), "hello world") checkEquals(test$rep, list(charToRaw("def"), raw(10))) test$rep[[3]]=charToRaw("ghi") Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-14 23:19:49 UTC (rev 543) +++ pkg/src/mutators.cpp 2013-12-14 23:47:22 UTC (rev 544) @@ -401,31 +401,32 @@ } // }}} + // {{{ preliminary checks + int value_size = Rf_isVector(value) ? LENGTH(value) : 1; + // if the R type is RAWSXP and the cpp type is string or bytes, + // then value_size is actually one because the raw vector + // is converted to a string + int field_type = field_desc->type() ; + if( field_type == TYPE_STRING || field_type == TYPE_BYTES ){ + if( TYPEOF(value) == RAWSXP ){ + value_size = 1 ; + } else if( TYPEOF(value) == STRSXP ){ + value_size = LENGTH(value); + } else if( TYPEOF(value) == S4SXP && Rf_inherits( value, "Message") ){ + value_size = 1 ; /* we will store the message payload */ + } else if( TYPEOF(value) == VECSXP && allAreMessages( value ) ){ + value_size = LENGTH(value) ; + } else if( TYPEOF(value) == VECSXP && allAreRaws( value ) ){ + value_size = LENGTH(value) ; + } else { + throwException( "cannot convert to string", "ConversionException" ) ; + } + } + // }}} + if( field_desc->is_repeated() ){ // {{{ repeated fields - // {{{ preliminary checks - int value_size = Rf_isVector(value) ? LENGTH(value) : 1; - // if the R type is RAWSXP and the cpp type is string or bytes, - // then value_size is actually one because the raw vector - // is converted to a string - int field_type = field_desc->type() ; - if( field_type == TYPE_STRING || field_type == TYPE_BYTES ){ - if( TYPEOF(value) == RAWSXP ){ - value_size = 1 ; - } else if( TYPEOF(value) == STRSXP ){ - value_size = LENGTH(value); - } else if( TYPEOF(value) == S4SXP && Rf_inherits( value, "Message") ){ - value_size = 1 ; /* we will store the message payload */ - } else if( TYPEOF(value) == VECSXP && allAreMessages( value ) ){ - value_size = LENGTH(value) ; - } else if( TYPEOF(value) == VECSXP && allAreRaws( value ) ){ - value_size = LENGTH(value) ; - } else { - throwException( "cannot convert to string", "ConversionException" ) ; - } - } - // }}} // The number of elements already in the repeated field. int field_size = ref->FieldSize( *message, field_desc ) ; @@ -1011,7 +1012,7 @@ // }}} } else { // {{{ non repeated fields - if (Rf_isVector(value) && LENGTH(value) > 1) { + if (value_size > 1) { throwException( "cannot set non-repeated field to vector of length > 1", "CastException" ) ; } switch( GPB::FieldDescriptor::TypeToCppType( field_desc->type() ) ){ From noreply at r-forge.r-project.org Sun Dec 15 01:27:46 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Dec 2013 01:27:46 +0100 (CET) Subject: [Rprotobuf-commits] r545 - pkg/inst Message-ID: <20131215002746.CA45E185F9C@r-forge.r-project.org> Author: murray Date: 2013-12-15 01:27:42 +0100 (Sun, 15 Dec 2013) New Revision: 545 Modified: pkg/inst/NEWS.Rd Log: Another update since the last release (enum_type method) Modified: pkg/inst/NEWS.Rd =================================================================== --- pkg/inst/NEWS.Rd 2013-12-14 23:47:22 UTC (rev 544) +++ pkg/inst/NEWS.Rd 2013-12-15 00:27:42 UTC (rev 545) @@ -12,6 +12,8 @@ \item Change object table lookup slightly to allow users to use the '<<-' operator in code using RProtoBuf without hitting a stop() error in the lookup routine. + \item Add missing enum_type method and improve show method for + EnumValueDescriptors. \item Improve documentation and tests for all of the above. } } From noreply at r-forge.r-project.org Sun Dec 15 01:29:52 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Dec 2013 01:29:52 +0100 (CET) Subject: [Rprotobuf-commits] r546 - pkg/inst/unitTests Message-ID: <20131215002952.D3E0B1861EB@r-forge.r-project.org> Author: murray Date: 2013-12-15 01:29:52 +0100 (Sun, 15 Dec 2013) New Revision: 546 Modified: pkg/inst/unitTests/runit.bytes.R Log: Fix typo. Modified: pkg/inst/unitTests/runit.bytes.R =================================================================== --- pkg/inst/unitTests/runit.bytes.R 2013-12-15 00:27:42 UTC (rev 545) +++ pkg/inst/unitTests/runit.bytes.R 2013-12-15 00:29:52 UTC (rev 546) @@ -24,5 +24,5 @@ # Test raw(10) can be set to a single req field. test$req <- raw(10) checkEquals(length(test$req), 10) - checkTrue(all(blob$content == raw(10))) + checkTrue(all(test$req == raw(10))) } From noreply at r-forge.r-project.org Sun Dec 15 06:19:42 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Dec 2013 06:19:42 +0100 (CET) Subject: [Rprotobuf-commits] r547 - in pkg: . R src Message-ID: <20131215051942.AE6DD18488A@r-forge.r-project.org> Author: edd Date: 2013-12-15 06:19:37 +0100 (Sun, 15 Dec 2013) New Revision: 547 Modified: pkg/ChangeLog pkg/R/lookup.R pkg/src/lookup.cpp pkg/src/rprotobuf.h Log: minor update to attaching descriptor pool Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-15 00:29:52 UTC (rev 546) +++ pkg/ChangeLog 2013-12-15 05:19:37 UTC (rev 547) @@ -1,3 +1,9 @@ +2013-12-14 Dirk Eddelbuettel + + * src/lookup.cpp (rprotobuf): Descrictor pools attached directly + * R/lookup.R (attachDescriptorPool): No longer attach them here + * src/rprotobuf.h: Updated function declaration + 2013-12-14 Murray Stokely * src/mutators.cpp (rprotobuf): Fix a bug which incorrectly Modified: pkg/R/lookup.R =================================================================== --- pkg/R/lookup.R 2013-12-15 00:29:52 UTC (rev 546) +++ pkg/R/lookup.R 2013-12-15 05:19:37 UTC (rev 547) @@ -5,17 +5,14 @@ OTABLE <- NULL NAMESPACE <- environment() -attachDescriptorPool <- function( pos = 2){ +attachDescriptorPool <- function(pos = 2) { + if (is.null(OTABLE)) { + ##unlockBinding( "OTABLE", NAMESPACE ) + otable <- .Call("newProtocolBufferLookup", pos, PACKAGE = "RProtoBuf") + #attach(otable, pos=pos, name="RProtoBuf:DescriptorPool") + assign("OTABLE", otable, envir = NAMESPACE, inherits = FALSE) + lockBinding("OTABLE", NAMESPACE ) + } - if( is.null( OTABLE ) ){ - #unlockBinding( "OTABLE", NAMESPACE ) - - otable <- .Call( "newProtocolBufferLookup" , PACKAGE = "RProtoBuf" ) - attach( otable, pos = pos, name = "RProtoBuf:DescriptorPool" ) - - assign( "OTABLE", otable, envir = NAMESPACE, inherits = FALSE) - lockBinding( "OTABLE", NAMESPACE ) - } - } Modified: pkg/src/lookup.cpp =================================================================== --- pkg/src/lookup.cpp 2013-12-15 00:29:52 UTC (rev 546) +++ pkg/src/lookup.cpp 2013-12-15 05:19:37 UTC (rev 547) @@ -1,3 +1,5 @@ +// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- + #include "rprotobuf.h" #include "DescriptorPoolLookup.h" @@ -196,42 +198,47 @@ return( objects ); } -SEXP newProtocolBufferLookup(){ +SEXP newProtocolBufferLookup(SEXP possexp){ #ifdef LOOKUP_DEBUG - Rprintf( "\n" ); + Rprintf( "\n" ); #endif - R_ObjectTable *tb; - SEXP val, klass; + R_ObjectTable *tb; + SEXP val, klass; - tb = (R_ObjectTable *) malloc(sizeof(R_ObjectTable)); - if(!tb) - Rf_error( "cannot allocate space for an internal R object table" ); + tb = (R_ObjectTable *) malloc(sizeof(R_ObjectTable)); + if(!tb) + Rf_error( "cannot allocate space for an internal R object table" ); + + tb->type = RPROTOBUF_LOOKUP ; /* FIXME: not sure what this should be */ + tb->cachedNames = NULL; - tb->type = RPROTOBUF_LOOKUP ; /* FIXME: not sure what this should be */ - tb->cachedNames = NULL; - - tb->privateData = (void*)0 ; + tb->privateData = (void*)0 ; - tb->exists = rProtoBufTable_exists; - tb->get = rProtoBufTable_get; - tb->remove = rProtoBufTable_remove; - tb->assign = rProtoBufTable_assign; - tb->objects = rProtoBufTable_objects; - tb->canCache = rProtoBufTable_canCache; + tb->exists = rProtoBufTable_exists; + tb->get = rProtoBufTable_get; + tb->remove = rProtoBufTable_remove; + tb->assign = rProtoBufTable_assign; + tb->objects = rProtoBufTable_objects; + tb->canCache = rProtoBufTable_canCache; - tb->onAttach = NULL; - tb->onDetach = NULL; + tb->onAttach = NULL; + tb->onDetach = NULL; - PROTECT(val = R_MakeExternalPtr(tb, Rf_install("UserDefinedDatabase"), R_NilValue)); - PROTECT(klass = Rf_mkString( "UserDefinedDatabase" ) ); - Rf_setAttrib(val, R_ClassSymbol, klass) ; - UNPROTECT(2); /* val, klass */ - + PROTECT(val = R_MakeExternalPtr(tb, Rf_install("UserDefinedDatabase"), R_NilValue)); + PROTECT(klass = Rf_mkString( "UserDefinedDatabase" ) ); + Rf_setAttrib(val, R_ClassSymbol, klass) ; + UNPROTECT(2); /* val, klass */ + #ifdef LOOKUP_DEBUG - Rprintf( "\n" ); + Rprintf( "\n" ); #endif - return(val); + + Rcpp::Function fun("attach"); + int pos = Rcpp::as(possexp); + fun(val, Rcpp::Named("pos")=pos, Rcpp::Named("name")="RProtoBuf:DescriptorPool"); + + return(val); } Modified: pkg/src/rprotobuf.h =================================================================== --- pkg/src/rprotobuf.h 2013-12-15 00:29:52 UTC (rev 546) +++ pkg/src/rprotobuf.h 2013-12-15 05:19:37 UTC (rev 547) @@ -133,7 +133,7 @@ RcppExport SEXP throwException( const char*, const char*) ; /* in lookup.cpp */ -RcppExport SEXP newProtocolBufferLookup() ; +RcppExport SEXP newProtocolBufferLookup(SEXP) ; /* in mutators.cpp */ RcppExport SEXP setMessageField( SEXP, SEXP, SEXP ) ; From noreply at r-forge.r-project.org Sun Dec 15 16:48:10 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Dec 2013 16:48:10 +0100 (CET) Subject: [Rprotobuf-commits] r548 - in pkg: . inst tests Message-ID: <20131215154810.DAF5D181050@r-forge.r-project.org> Author: edd Date: 2013-12-15 16:48:10 +0100 (Sun, 15 Dec 2013) New Revision: 548 Added: pkg/tests/runUnitTests.R Removed: pkg/tests/doRUnit.R Modified: pkg/ChangeLog pkg/inst/NEWS.Rd Log: Minor rewrite (as runUnitTests.R) and cleanup (from doRUnit.R) with a tip of the hat to Murray's version in his HistogramTools package Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-15 05:19:37 UTC (rev 547) +++ pkg/ChangeLog 2013-12-15 15:48:10 UTC (rev 548) @@ -1,3 +1,8 @@ +2013-12-15 Dirk Eddelbuettel + + * tests/runUnitTests.R: Minor rewrite and cleanup from doRUnit.R with + a tip of the hat to Murray's version in his HistogramTools package + 2013-12-14 Dirk Eddelbuettel * src/lookup.cpp (rprotobuf): Descrictor pools attached directly Modified: pkg/inst/NEWS.Rd =================================================================== --- pkg/inst/NEWS.Rd 2013-12-15 05:19:37 UTC (rev 547) +++ pkg/inst/NEWS.Rd 2013-12-15 15:48:10 UTC (rev 548) @@ -15,6 +15,7 @@ \item Add missing enum_type method and improve show method for EnumValueDescriptors. \item Improve documentation and tests for all of the above. + \item Rewrote \code{tests/} script calling \cpkg{RUnit} tests } } Deleted: pkg/tests/doRUnit.R =================================================================== --- pkg/tests/doRUnit.R 2013-12-15 05:19:37 UTC (rev 547) +++ pkg/tests/doRUnit.R 2013-12-15 15:48:10 UTC (rev 548) @@ -1,27 +0,0 @@ -#### doRUnit.R --- Run RUnit tests -####------------------------------------------------------------------------ - -### borrowed from package fUtilities in RMetrics -### http://r-forge.r-project.org/plugins/scmsvn/viewcvs.php/pkg/fUtilities/tests/doRUnit.R?rev=1958&root=rmetrics&view=markup - -### Originally follows Gregor Gojanc's example in CRAN package 'gdata' -### and the corresponding section in the R Wiki: -### http://wiki.r-project.org/rwiki/doku.php?id=developers:runit - -### MM: Vastly changed: This should also be "runnable" for *installed* -## package which has no ./tests/ -## ----> put the bulk of the code e.g. in ../inst/unitTests/runTests.R : - -if(require("RUnit", quietly = TRUE)) { - - ## --- Setup --- - pkg <- "RProtoBuf" - - require( pkg, character.only=TRUE) - - path <- system.file("unitTests", package = pkg) - - stopifnot(file.exists(path), file.info(path.expand(path))$isdir) - - source(file.path(path, "runTests.R"), echo = TRUE) -} Copied: pkg/tests/runUnitTests.R (from rev 547, pkg/tests/doRUnit.R) =================================================================== --- pkg/tests/runUnitTests.R (rev 0) +++ pkg/tests/runUnitTests.R 2013-12-15 15:48:10 UTC (rev 548) @@ -0,0 +1,36 @@ + +## doRUnit.R --- Run RUnit tests +## +## with credits to package fUtilities in RMetrics +## which credits Gregor Gojanc's example in CRAN package 'gdata' +## as per the R Wiki http://wiki.r-project.org/rwiki/doku.php?id=developers:runit +## and changed further by Martin Maechler +## and more changes by Murray Stokely in HistogramTools +## +## Dirk Eddelbuettel, Dec 2013 + +stopifnot(require("RUnit", quietly=TRUE)) +stopifnot(require("RProtoBuf", quietly=TRUE)) + +# path <- system.file("unitTests", package = pkg) +# stopifnot(file.exists(path), file.info(path.expand(path))$isdir) +# source(file.path(path, "runTests.R"), echo = TRUE) + +## Set a seed to make the test deterministic +set.seed(42) + +## Define tests +testSuite <- defineTestSuite(name="RProtoBuf Unit Tests", + dirs=system.file("unitTests", package = "RProtoBuf"), + testFuncRegexp = "^[Tt]est.+") + +## Run tests +tests <- runTestSuite(testSuite) + +## Print results +printTextProtocol(tests) + +## Return success or failure to R CMD CHECK +if (getErrors(tests)$nFail > 0) { + stop("TEST FAILED!") +} From noreply at r-forge.r-project.org Sun Dec 15 23:57:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Dec 2013 23:57:35 +0100 (CET) Subject: [Rprotobuf-commits] r549 - in pkg: . inst Message-ID: <20131215225735.31F481865EB@r-forge.r-project.org> Author: edd Date: 2013-12-15 23:57:34 +0100 (Sun, 15 Dec 2013) New Revision: 549 Modified: pkg/ChangeLog pkg/DESCRIPTION pkg/inst/NEWS.Rd Log: Release 0.3.2 Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-15 15:48:10 UTC (rev 548) +++ pkg/ChangeLog 2013-12-15 22:57:34 UTC (rev 549) @@ -1,5 +1,7 @@ 2013-12-15 Dirk Eddelbuettel + * DESCRIPTION (Version): Release 0.3.2 + * tests/runUnitTests.R: Minor rewrite and cleanup from doRUnit.R with a tip of the hat to Murray's version in his HistogramTools package Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-12-15 15:48:10 UTC (rev 548) +++ pkg/DESCRIPTION 2013-12-15 22:57:34 UTC (rev 549) @@ -1,5 +1,5 @@ Package: RProtoBuf -Version: 0.3.2 +Version: 0.3. Date: $Date$ Author: Romain Francois, Dirk Eddelbuettel and Murray Stokely Maintainer: Dirk Eddelbuettel @@ -7,7 +7,7 @@ Description: Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats. -Depends: R (>= 2.11.0), methods +Depends: R, methods LinkingTo: Rcpp Suggests: RUnit, highlight, Rcpp Imports: utils, stats, tools, RCurl Modified: pkg/inst/NEWS.Rd =================================================================== --- pkg/inst/NEWS.Rd 2013-12-15 15:48:10 UTC (rev 548) +++ pkg/inst/NEWS.Rd 2013-12-15 22:57:34 UTC (rev 549) @@ -10,9 +10,9 @@ a message of the wrong type instead of causing a C++ check failure that terminates the Rsession. \item Change object table lookup slightly to allow users to use the - '<<-' operator in code using RProtoBuf without hitting a stop() error - in the lookup routine. - \item Add missing enum_type method and improve show method for + \code{<<-} operator in code using \cpkg{RProtoBuf} without hitting a + \code{stop()} error in the lookup routine. + \item Add missing \code{enum_type} method and improve show method for EnumValueDescriptors. \item Improve documentation and tests for all of the above. \item Rewrote \code{tests/} script calling \cpkg{RUnit} tests From noreply at r-forge.r-project.org Sun Dec 15 23:58:03 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sun, 15 Dec 2013 23:58:03 +0100 (CET) Subject: [Rprotobuf-commits] r550 - pkg Message-ID: <20131215225803.9F69918662E@r-forge.r-project.org> Author: edd Date: 2013-12-15 23:58:03 +0100 (Sun, 15 Dec 2013) New Revision: 550 Modified: pkg/DESCRIPTION Log: typo fix Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-12-15 22:57:34 UTC (rev 549) +++ pkg/DESCRIPTION 2013-12-15 22:58:03 UTC (rev 550) @@ -1,5 +1,5 @@ Package: RProtoBuf -Version: 0.3. +Version: 0.3.2 Date: $Date$ Author: Romain Francois, Dirk Eddelbuettel and Murray Stokely Maintainer: Dirk Eddelbuettel From noreply at r-forge.r-project.org Mon Dec 16 00:04:49 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 16 Dec 2013 00:04:49 +0100 (CET) Subject: [Rprotobuf-commits] r551 - pkg Message-ID: <20131215230450.085A5186A2A@r-forge.r-project.org> Author: edd Date: 2013-12-16 00:04:49 +0100 (Mon, 16 Dec 2013) New Revision: 551 Modified: pkg/DESCRIPTION Log: revert back to having a versioned Depends on R (even if the version number is by today's standard prehistoric) Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-12-15 22:58:03 UTC (rev 550) +++ pkg/DESCRIPTION 2013-12-15 23:04:49 UTC (rev 551) @@ -7,7 +7,7 @@ Description: Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats. -Depends: R, methods +Depends: R (>= 2.11), methods LinkingTo: Rcpp Suggests: RUnit, highlight, Rcpp Imports: utils, stats, tools, RCurl From noreply at r-forge.r-project.org Mon Dec 16 15:37:00 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 16 Dec 2013 15:37:00 +0100 (CET) Subject: [Rprotobuf-commits] r552 - in pkg: . src Message-ID: <20131216143700.C6F191869F3@r-forge.r-project.org> Author: edd Date: 2013-12-16 15:37:00 +0100 (Mon, 16 Dec 2013) New Revision: 552 Modified: pkg/ChangeLog pkg/DESCRIPTION pkg/src/rprotobuf.h Log: do not use 'extern "C"' on two functions returning std::string Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-15 23:04:49 UTC (rev 551) +++ pkg/ChangeLog 2013-12-16 14:37:00 UTC (rev 552) @@ -1,3 +1,8 @@ +2013-12-16 Dirk Eddelbuettel + + * src/rprotobuf.h (RCPP_ENUM_TRAITS): Don't use extern "C" on two + internal functions returning a C++ type + 2013-12-15 Dirk Eddelbuettel * DESCRIPTION (Version): Release 0.3.2 Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-12-15 23:04:49 UTC (rev 551) +++ pkg/DESCRIPTION 2013-12-16 14:37:00 UTC (rev 552) @@ -1,5 +1,5 @@ Package: RProtoBuf -Version: 0.3.2 +Version: 0.3.2.1 Date: $Date$ Author: Romain Francois, Dirk Eddelbuettel and Murray Stokely Maintainer: Dirk Eddelbuettel Modified: pkg/src/rprotobuf.h =================================================================== --- pkg/src/rprotobuf.h 2013-12-15 23:04:49 UTC (rev 551) +++ pkg/src/rprotobuf.h 2013-12-16 14:37:00 UTC (rev 552) @@ -145,8 +145,8 @@ RcppExport uint32 GET_uint32( SEXP, int) ; RcppExport uint64 GET_uint64( SEXP, int ) ; RcppExport bool GET_bool( SEXP, int) ; -RcppExport std::string GET_stdstring( SEXP, int ) ; -RcppExport std::string GET_bytes( SEXP, int ) ; + std::string GET_stdstring( SEXP, int ) ; + std::string GET_bytes( SEXP, int ) ; RcppExport void CHECK_values_for_enum( GPB::FieldDescriptor*, SEXP) ; RcppExport void CHECK_messages( GPB::FieldDescriptor*, SEXP) ; From noreply at r-forge.r-project.org Mon Dec 16 17:26:21 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 16 Dec 2013 17:26:21 +0100 (CET) Subject: [Rprotobuf-commits] r553 - in papers: . rjournal Message-ID: <20131216162621.D34BB1862F6@r-forge.r-project.org> Author: murray Date: 2013-12-16 17:26:21 +0100 (Mon, 16 Dec 2013) New Revision: 553 Added: papers/rjournal/ papers/rjournal/Makefile papers/rjournal/RJournal.sty papers/rjournal/RJwrapper.brf papers/rjournal/RJwrapper.tex papers/rjournal/eddelbuettel-francois-stokely.bib papers/rjournal/eddelbuettel-francois-stokely.tex Log: Add boilerplate for an R Journal article. Hadley's ggmap one from the last issue was nearly 20 pages, so I think we'll be fine length wise. Added: papers/rjournal/Makefile =================================================================== --- papers/rjournal/Makefile (rev 0) +++ papers/rjournal/Makefile 2013-12-16 16:26:21 UTC (rev 553) @@ -0,0 +1,15 @@ +all: clean RJwrapper.pdf + +clean: + rm -fr RJwrapper.pdf + rm -fr RJwrapper.out + rm -fr RJwrapper.aux + rm -fr RJwrapper.log + rm -fr RJwrapper.bbl + rm -fr RJwrapper.blg + +RJwrapper.pdf: RJwrapper.tex eddelbuettel-francois-stokely.tex RJournal.sty + pdflatex RJwrapper.tex + bibtex RJwrapper + pdflatex RJwrapper.tex + pdflatex RJwrapper.tex Added: papers/rjournal/RJournal.sty =================================================================== --- papers/rjournal/RJournal.sty (rev 0) +++ papers/rjournal/RJournal.sty 2013-12-16 16:26:21 UTC (rev 553) @@ -0,0 +1,335 @@ +% Package `RJournal' to use with LaTeX2e +% Copyright (C) 2010 by the R Foundation +% Copyright (C) 2013 by the R Journal +% +% Originally written by Kurt Hornik and Friedrich Leisch with subsequent +% edits by the editorial board + +\NeedsTeXFormat{LaTeX2e}[1995/12/01] +\ProvidesPackage{RJournal}[2013/08/27 v0.13 RJournal package] + +\RequirePackage{tikz} + +% Overall page layout, fonts etc ----------------------------------------------- + +% Issues of of \emph{The R Journal} are created from the standard \LaTeX{} +% document class \pkg{report}. + +\RequirePackage{geometry} +\geometry{a4paper, + textwidth=14cm, top=1cm, bottom=1cm, + includehead,includefoot,centering, + footskip=1.5cm} +\raggedbottom + +\RequirePackage{fancyhdr} +\fancyhead{} +\fancyheadoffset{2cm} +\fancyhead[L]{\textsc{\RJ at sectionhead}} +\fancyhead[R]{\thepage} +\fancyfoot{} +\fancyfoot[L]{The R Journal Vol. \RJ at volume/\RJ at number, \RJ at month} +\fancyfoot[R]{ISSN 2073-4859} +\pagestyle{fancy} + +% We use the following fonts (all with T1 encoding): +% +% rm & palatino +% tt & inconsolata +% sf & helvetica +% math & palatino + +\RequirePackage{microtype} + +\RequirePackage[scaled=0.92]{helvet} +\RequirePackage{palatino,mathpazo} +\RequirePackage[scaled=1.02]{inconsolata} +\RequirePackage[T1]{fontenc} + +\RequirePackage[hyphens]{url} +\RequirePackage[pagebackref]{hyperref} +\renewcommand{\backref}[1]{[p#1]} + +% Dark blue colour for all links +\RequirePackage{color} +\definecolor{link}{rgb}{0.45,0.51,0.67} +\hypersetup{ + colorlinks,% + citecolor=link,% + filecolor=link,% + linkcolor=link,% + urlcolor=link +} + +% Give the text a little room to breath +\setlength{\parskip}{3pt} +\RequirePackage{setspace} +\setstretch{1.05} + +% Issue and article metadata --------------------------------------------------- + +% Basic front matter information about the issue: volume, number, and +% date. + +\newcommand{\volume}[1]{\def\RJ at volume{#1}} +\newcommand{\volnumber}[1]{\def\RJ at number{#1}} +\renewcommand{\month}[1]{\def\RJ at month{#1}} +\renewcommand{\year}[1]{\def\RJ at year{#1}} + + +% Individual articles correspond to +% chapters, and are contained in |article| environments. This makes it +% easy to have figures counted within articles and hence hyperlinked +% correctly. + +% An article has an author, a title, and optionally a subtitle. We use +% the obvious commands for specifying these. Articles will be put in certain +% journal sections, named by \sectionhead. + +\newcommand {\sectionhead} [1]{\def\RJ at sectionhead{#1}} +\renewcommand{\author} [1]{\def\RJ at author{#1}} +\renewcommand{\title} [1]{\def\RJ at title{#1}} +\newcommand {\subtitle} [1]{\def\RJ at subtitle{#1}} + +% Control appearance of titles: make slightly smaller than usual, and +% suppress section numbering. See http://tex.stackexchange.com/questions/69749 +% for why we don't use \setcounter{secnumdepth}{-1} + +\usepackage[medium]{titlesec} +\usepackage{titletoc} +\titleformat{\section} {\normalfont\large\bfseries}{}{0em}{} +\titleformat{\subsection}{\normalfont\normalsize\bfseries}{}{0em}{} +\titlecontents{chapter} [0em]{}{}{}{\titlerule*[1em]{.}\contentspage} + +% Article layout --------------------------------------------------------------- + +% Environment |article| clears the article header information at its beginning. +% We use |\FloatBarrier| from the placeins package to keep floats within +% the article. +\RequirePackage{placeins} +\newenvironment{article}{\author{}\title{}\subtitle{}\FloatBarrier}{\FloatBarrier} + +% Refereed articles should have an abstract, so we redefine |\abstract| to +% give the desired style + +\renewcommand{\abstract}[1]{% +\setstretch{1}% +\noindent% +\small% +\textbf{Abstract} #1 +} + +% The real work is done by a redefined version of |\maketitle|. Note +% that even though we do not want chapters (articles) numbered, we +% need to increment the chapter counter, so that figures get correct +% labelling. + +\renewcommand{\maketitle}{% +\noindent + \chapter{\RJ at title}\refstepcounter{chapter} + \ifx\empty\RJ at subtitle + \else + \noindent\textbf{\RJ at subtitle} + \par\nobreak\addvspace{\baselineskip} + \fi + \ifx\empty\RJ at author + \else + \noindent\textit{\RJ at author} + \par\nobreak\addvspace{\baselineskip} + \fi + \@afterindentfalse\@nobreaktrue\@afterheading +} + +% Now for some ugly redefinitions. We do not want articles to start a +% new page. (Actually, we do, but this is handled via explicit +% \newpage +% +% The name at of@eq is a hack to get hyperlinks to equations to work +% within each article, even though there may be multiple eq.(1) +% \begin{macrocode} +\renewcommand\chapter{\secdef\RJ at chapter\@schapter} +\providecommand{\nohyphens}{% + \hyphenpenalty=10000\exhyphenpenalty=10000\relax} +\newcommand{\RJ at chapter}{% + \edef\name at of@eq{equation.\@arabic{\c at chapter}}% + \renewcommand{\@seccntformat}[1]{}% + \@startsection{chapter}{0}{0mm}{% + -2\baselineskip \@plus -\baselineskip \@minus -.2ex}{\p@}{% + \phantomsection\normalfont\huge\bfseries\raggedright}} + +% Book reviews should appear as sections in the text and in the pdf bookmarks, +% however we wish them to appear as chapters in the TOC. Thus we define an +% alternative to |\maketitle| for reviews. +\newcommand{\review}[1]{ + \pdfbookmark[1]{#1}{#1} + \section*{#1} + \addtocontents{toc}{\protect\contentsline{chapter}{#1}{\thepage}{#1.1}} +} + +% We want bibliographies as starred sections within articles. +% +\RequirePackage[sectionbib,round]{natbib} +\bibliographystyle{abbrvnat} + +% Equations, figures and tables are counted within articles, but we do +% not show the article number. For equations it becomes a bit messy to avoid +% having hyperref getting it wrong. + +% \numberwithin{equation}{chapter} +\renewcommand{\theequation}{\@arabic\c at equation} +\renewcommand{\thefigure}{\@arabic\c at figure} +\renewcommand{\thetable}{\@arabic\c at table} + +% Issue layout ----------------------------------------------------------------- + +% Need to provide our own version of |\tableofcontents|. We use the +% tikz package to get the rounded rectangle. Notice that |\section*| +% is really the same as |\chapter*|. +\renewcommand{\contentsname}{Contents} +\renewcommand\tableofcontents{% + \vspace{1cm} + \section*{\contentsname} + { \@starttoc{toc} } +} + +\renewcommand{\titlepage}{% + \thispagestyle{empty} + \hypersetup{ + pdftitle={The R Journal Volume \RJ at volume/\RJ at number, \RJ at month \RJ at year},% + pdfauthor={R Foundation for Statistical Computing},% + } + \noindent + \begin{center} + \fontsize{50pt}{50pt}\selectfont + The \raisebox{-8pt}{\includegraphics[height=77pt]{Rlogo-4}}\hspace{10pt} + Journal + + \end{center} + {\large \hfill Volume \RJ at volume/\RJ at number, \RJ at month{} \RJ at year \quad} + + \rule{\textwidth}{1pt} + \begin{center} + {\Large A peer-reviewed, open-access publication of the \\ + R Foundation for Statistical Computing} + \end{center} + + % And finally, put in the TOC box. Note the way |tocdepth| is adjusted + % before and after producing the TOC: thus, we can ensure that only + % articles show up in the printed TOC, but that in the PDF version, + % bookmarks are created for sections and subsections as well (provided + % that the non-starred forms are used). + \setcounter{tocdepth}{0} + \tableofcontents + \setcounter{tocdepth}{2} + \clearpage +} + +% Text formatting -------------------------------------------------------------- + +\newcommand{\R}{R} +\newcommand{\address}[1]{\addvspace{\baselineskip}\noindent\emph{#1}} +\newcommand{\email}[1]{\href{mailto:#1}{\normalfont\texttt{#1}}} + +% Simple font selection is not good enough. For example, |\texttt{--}| +% gives `\texttt{--}', i.e., an endash in typewriter font. Hence, we +% need to turn off ligatures, which currently only happens for commands +% |\code| and |\samp| and the ones derived from them. Hyphenation is +% another issue; it should really be turned off inside |\samp|. And +% most importantly, \LaTeX{} special characters are a nightmare. E.g., +% one needs |\~{}| to produce a tilde in a file name marked by |\file|. +% Perhaps a few years ago, most users would have agreed that this may be +% unfortunate but should not be changed to ensure consistency. But with +% the advent of the WWW and the need for getting `|~|' and `|#|' into +% URLs, commands which only treat the escape and grouping characters +% specially have gained acceptance + +\DeclareRobustCommand\code{\bgroup\@noligs\@codex} +\def\@codex#1{\texorpdfstring% +{{\normalfont\ttfamily\hyphenchar\font=-1 #1}}% +{#1}\egroup} +\newcommand{\kbd}[1]{{\normalfont\texttt{#1}}} +\newcommand{\key}[1]{{\normalfont\texttt{\uppercase{#1}}}} +\DeclareRobustCommand\samp{`\bgroup\@noligs\@sampx} +\def\@sampx#1{{\normalfont\texttt{#1}}\egroup'} +\newcommand{\var}[1]{{\normalfont\textsl{#1}}} +\let\env=\code +\newcommand{\file}[1]{{`\normalfont\textsf{#1}'}} +\let\command=\code +\let\option=\samp +\newcommand{\dfn}[1]{{\normalfont\textsl{#1}}} +% \acronym is effectively disabled since not used consistently +\newcommand{\acronym}[1]{#1} +\newcommand{\strong}[1]{\texorpdfstring% +{{\normalfont\fontseries{b}\selectfont #1}}% +{#1}} +\let\pkg=\strong +\newcommand{\CRANpkg}[1]{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}% +\let\cpkg=\CRANpkg +\newcommand{\ctv}[1]{\href{http://CRAN.R-project.org/view=#1}{\emph{#1}}} +\newcommand{\BIOpkg}[1]{\href{http://www.bioconductor.org/packages/release/bioc/html/#1.html}{\pkg{#1}}} + +% Example environments --------------------------------------------------------- +\RequirePackage{fancyvrb} +\RequirePackage{alltt} + +\DefineVerbatimEnvironment{example}{Verbatim}{} +\renewenvironment{example*}{\begin{alltt}}{\end{alltt}} + +% Support for output from Sweave, and generic session style code +% These used to have fontshape=sl for Sinput/Scode/Sin, but pslatex +% won't use a condensed font in that case. + +\DefineVerbatimEnvironment{Sinput}{Verbatim}{fontsize=\small} +\DefineVerbatimEnvironment{Soutput}{Verbatim}{fontsize=\small} +\DefineVerbatimEnvironment{Scode}{Verbatim}{fontsize=\small} +\DefineVerbatimEnvironment{Sin}{Verbatim}{fontsize=\small} +\DefineVerbatimEnvironment{Sout}{Verbatim}{fontsize=\small} +\newenvironment{Schunk}{}{} + +% Mathematics ------------------------------------------------------------------ + +% The implementation of |\operatorname| is similar to the mechanism +% \LaTeXe{} uses for functions like sin and cos, and simpler than the +% one of \AmSLaTeX{}. We use |\providecommand| for the definition in +% order to keep the one of the \pkg{amstex} if this package has +% already been loaded. +% \begin{macrocode} +\providecommand{\operatorname}[1]{% + \mathop{\operator at font#1}\nolimits} +\RequirePackage{amsfonts} + +\renewcommand{\P}{% + \mathop{\operator at font I\hspace{-1.5pt}P\hspace{.13pt}}} +\newcommand{\E}{% + \mathop{\operator at font I\hspace{-1.5pt}E\hspace{.13pt}}} +\newcommand{\VAR}{\operatorname{var}} +\newcommand{\COV}{\operatorname{cov}} +\newcommand{\COR}{\operatorname{cor}} + +% Figures ---------------------------------------------------------------------- + +\RequirePackage[font=small,labelfont=bf]{caption} + +% Wide environments for figures and tables ------------------------------------- +\RequirePackage{environ} + +% An easy way to make a figure span the full width of the page +\NewEnviron{widefigure}[1][]{ +\begin{figure}[#1] +\advance\leftskip-2cm +\begin{minipage}{\dimexpr\textwidth+4cm\relax}% + \captionsetup{margin=2cm} + \BODY +\end{minipage}% +\end{figure} +} + +\NewEnviron{widetable}[1][]{ +\begin{table}[#1] +\advance\leftskip-2cm +\begin{minipage}{\dimexpr\textwidth+4cm\relax}% + \captionsetup{margin=2cm} + \BODY +\end{minipage}% +\end{table} +} Added: papers/rjournal/RJwrapper.brf =================================================================== --- papers/rjournal/RJwrapper.brf (rev 0) +++ papers/rjournal/RJwrapper.brf 2013-12-16 16:26:21 UTC (rev 553) @@ -0,0 +1,2 @@ +\backcite {R}{{1}{2.1}{section.2.1}} +\backcite {R}{{1}{2.1}{section.2.1}} Added: papers/rjournal/RJwrapper.tex =================================================================== --- papers/rjournal/RJwrapper.tex (rev 0) +++ papers/rjournal/RJwrapper.tex 2013-12-16 16:26:21 UTC (rev 553) @@ -0,0 +1,24 @@ +\documentclass[a4paper]{report} +\usepackage[utf8]{inputenc} +\usepackage[T1]{fontenc} +\usepackage{RJournal} +\usepackage{amsmath,amssymb,array} +\usepackage{booktabs} + +%% load any required packages here + +\begin{document} + +%% do not edit, for illustration only +\sectionhead{Contributed research article} +\volume{XX} +\volnumber{YY} +\year{20ZZ} +\month{AAAA} + +%% replace RJtemplate with your article +\begin{article} + \input{eddelbuettel-francois-stokely} +\end{article} + +\end{document} Added: papers/rjournal/eddelbuettel-francois-stokely.bib =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.bib (rev 0) +++ papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-16 16:26:21 UTC (rev 553) @@ -0,0 +1,168 @@ + at inproceedings{cantrill2004dynamic, + title={Dynamic Instrumentation of Production Systems.}, + author={Cantrill, Bryan and Shapiro, Michael W and Leventhal, Adam H and others}, + booktitle={USENIX Annual Technical Conference, General Track}, + pages={15--28}, + year={2004} +} + at article{swain1991color, + title={Color indexing}, + author={Swain, Michael J and Ballard, Dana H}, + journal={International journal of computer vision}, + volume={7}, + number={1}, + pages={11--32}, + year={1991}, + publisher={Springer} +} + at article{rubner2000earth, + title={The earth mover's distance as a metric for image retrieval}, + author={Rubner, Yossi and Tomasi, Carlo and Guibas, Leonidas J}, + journal={International Journal of Computer Vision}, + volume={40}, + number={2}, + pages={99--121}, + year={2000}, + publisher={Springer} +} + at book{kullback1997information, + title={Information theory and statistics}, + author={Kullback, Solomon}, + year={1997}, + publisher={Courier Dover Publications} +} + at inproceedings{puzicha1997non, + title={Non-parametric similarity measures for unsupervised texture segmentation and image retrieval}, + author={Puzicha, Jan and Hofmann, Thomas and Buhmann, Joachim M}, + booktitle={Computer Vision and Pattern Recognition, 1997. Proceedings., 1997 IEEE Computer Society Conference on}, + pages={267--272}, + year={1997}, + organization={IEEE} +} + at inproceedings{fang1999computing, + title={Computing Iceberg Queries Efficiently.}, + author={Fang, Min and Shivakumar, Narayanan and Garcia-Molina, Hector and Motwani, Rajeev and Ullman, Jeffrey D}, + booktitle={Internaational Conference on Very Large Databases (VLDB'98), New York, August 1998}, + year={1999}, + organization={Stanford InfoLab} +} + at Manual{emdist, + title = {emdist: Earth Mover's Distance}, + author = {Simon Urbanek and Yossi Rubner}, + year = {2012}, + note = {R package version 0.3-1}, + url = {http://CRAN.R-project.org/package=emdist}, +} + at article{pearson1895contributions, + title={Contributions to the mathematical theory of evolution. II. Skew variation in homogeneous material}, + author={Pearson, Karl}, + journal={Philosophical Transactions of the Royal Society of London. A}, + volume={186}, + pages={343--414}, + year={1895}, + publisher={JSTOR} +} + at Manual{rprotobuf, + title = {RProtoBuf: R Interface to the Protocol Buffers API}, + author = {Romain Francois and Dirk Eddelbuettel and Murray Stokely}, + note = {R package version 0.2.6}, + year = {2012}, + url = {http://cran.r-project.org/web/packages/RProtoBuf/index.html}, +} + at Manual{r, + title = {R: A Language and Environment for Statistical Computing}, + author = {{R Core Team}}, + organization = {R Foundation for Statistical Computing}, + address = {Vienna, Austria}, + year = {2012}, + note = {{ISBN} 3-900051-07-0}, + url = {http://www.R-project.org/}, + } + at article{dean2008mapreduce, + title={MapReduce: simplified data processing on large clusters}, + author={Dean, Jeffrey and Ghemawat, Sanjay}, + journal={Communications of the ACM}, + volume={51}, + number={1}, + pages={107--113}, + year={2008}, + publisher={ACM} +} + at article{bostock2011d3, + title={D$^3$ Data-Driven Documents}, + author={Bostock, Michael and Ogievetsky, Vadim and Heer, Jeffrey}, + journal={Visualization and Computer Graphics, IEEE Transactions on}, + volume={17}, + number={12}, + pages={2301--2309}, + year={2011}, + publisher={IEEE} +} +% celebrated article in this field. Also see the parallel paragraph. + at article{Manku:1998:AMO:276305.276342, + author = {Manku, Gurmeet Singh and Rajagopalan, Sridhar and Lindsay, Bruce G.}, + title = {Approximate medians and other quantiles in one pass and with limited memory}, + journal = {SIGMOD Rec.}, + issue_date = {June 1998}, + volume = {27}, + number = {2}, + month = jun, + year = {1998}, + issn = {0163-5808}, + pages = {426--435}, + numpages = {10}, + url = {http://doi.acm.org/10.1145/276305.276342}, + doi = {10.1145/276305.276342}, + acmid = {276342}, + publisher = {ACM}, + address = {New York, NY, USA}, +} +% Has a section on protocol buffers + at article{Pike:2005:IDP:1239655.1239658, + author = {Pike, Rob and Dorward, Sean and Griesemer, Robert and Quinlan, Sean}, + title = {Interpreting the data: Parallel analysis with Sawzall}, + journal = {Sci. Program.}, + issue_date = {October 2005}, + volume = {13}, + number = {4}, + month = oct, + year = {2005}, + issn = {1058-9244}, + pages = {277--298}, + numpages = {22}, + acmid = {1239658}, + publisher = {IOS Press}, + address = {Amsterdam, The Netherlands, The Netherlands}, +} + at Manual{protobuf, + title = {Protocol Buffers: Developer Guide}, + author = {Google}, + year = {2012}, + url = {http://code.google.com/apis/protocolbuffers/docs/overview.html} +} + at article{sturges1926choice, + title={The choice of a class interval}, + author={Sturges, Herbert A}, + journal={Journal of the American Statistical Association}, + volume={21}, + number={153}, + pages={65--66}, + year={1926} +} + at article{scott1979optimal, + title={On optimal and data-based histograms}, + author={Scott, David W}, + journal={Biometrika}, + volume={66}, + number={3}, + pages={605--610}, + year={1979}, + publisher={Biometrika Trust} +} + at book{scott2009multivariate, + title={Multivariate density estimation: theory, practice, and visualization}, + author={Scott, David W}, + volume={383}, + year={2009}, + publisher={Wiley. com} +} Added: papers/rjournal/eddelbuettel-francois-stokely.tex =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.tex (rev 0) +++ papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-16 16:26:21 UTC (rev 553) @@ -0,0 +1,156 @@ +% !TeX root = RJwrapper.tex +\title{RProtoBuf: Efficient Cross-Language Data Serialization in R} +\author{by Dirk Eddelbuettel, Romain Fran\c{c}ois, and Murray Stokely} + +\maketitle + +\abstract{Modern data collection and analysis pipelines often involve + a sophisticated mix of applications written in general purpose and + specialized programming languages. Protocol Buffers are a popular + method of serializing structured data between applications. The + \textbf{RProtoBuf} package provides a complete interface to this + library. +TODO keep it less than 150 words. +} + +\section{Introduction} + +Comparison with what people start with in R : CSV +comparison with what is only slightly better: JSON + +Introductory section which may include references in parentheses +\citep{R}, or cite a reference such as \citet{R} in the text. + +Protocol buffers are a language-neutral, platform-neutral, extensible +way of serializing structured data for use in communications +protocols, data storage, and more. + +Protocol Buffers offer key features such as an efficient data interchange +format that is both language- and operating system-agnostic yet uses a +lightweight and highly performant encoding, object serialization and +de-serialization as well data and configuration management. Protocol +buffers are also forward compatible: updates to the \texttt{proto} +files do not break programs built against the previous specification. + +While benchmarks are not available, Google states on the project page that in +comparison to XML, protocol buffers are at the same time \textsl{simpler}, +between three to ten times \textsl{smaller}, between twenty and one hundred +times \textsl{faster}, as well as less ambiguous and easier to program. + +The protocol buffers code is released under an open-source (BSD) license. The +protocol buffer project (\url{http://code.google.com/p/protobuf/}) +contains a C++ library and a set of runtime libraries and compilers for +C++, Java and Python. + +With these languages, the workflow follows standard practice of so-called +Interface Description Languages (IDL) +(c.f. \href{http://en.wikipedia.org/wiki/Interface_description_language}{Wikipedia + on IDL}). This consists of compiling a protocol buffer description file +(ending in \texttt{.proto}) into language specific classes that can be used +to create, read, write and manipulate protocol buffer messages. In other +words, given the 'proto' description file, code is automatically generated +for the chosen target language(s). The project page contains a tutorial for +each of these officially supported languages: +\url{http://code.google.com/apis/protocolbuffers/docs/tutorials.html} + +Besides the officially supported C++, Java and Python implementations, several projects have been +created to support protocol buffers for many languages. The list of known +languages to support protocol buffers is compiled as part of the +project page: \url{http://code.google.com/p/protobuf/wiki/ThirdPartyAddOns} + +The protocol buffer project page contains a comprehensive +description of the language: \url{http://code.google.com/apis/protocolbuffers/docs/proto.html} + +%This section may contain a figure such as Figure~\ref{figure:rlogo}. +% +%\begin{figure}[htbp] +% \centering +% \includegraphics{Rlogo} +% \caption{The logo of R.} +% \label{figure:rlogo} +%\end{figure} + +\section{Dynamic use: Protocol Buffers and R} + +This section describes how to use the R API to create and manipulate +protocol buffer messages in R, and how to read and write the +binary \emph{payload} of the messages to files and arbitrary binary +R connections. + +\subsection{Importing proto files} + +In contrast to the other languages (Java, C++, Python) that are officially +supported by Google, the implementation used by the \texttt{RProtoBuf} +package does not rely on the \texttt{protoc} compiler (with the exception of +the two functions discussed in the previous section). This means that no +initial step of statically compiling the proto file into C++ code that is +then accessed by R code is necessary. Instead, \texttt{proto} files are +parsed and processed \textsl{at runtime} by the protobuf C++ library---which +is much more appropriate for a dynamic language. + +The \texttt{readProtoFiles} function allows importing \texttt{proto} +files in several ways. + +% Example code snippet. +% TODO(mstokely): Remove this. +\begin{example} + x <- 1:10 + result <- myFunction(x) +\end{example} + +\section{Related work on IDLs (greatly expanded from what you have)} + +\section{Design tradeoffs: reflection vs proto compiler (not addressed + at all in current vignettes)} + +\subsection{Performance considerations} + +TODO RProtoBuf is quite flexible and easy to use for interactive +analysis, but it is not designed for certain classes of operations one +might like to do with protocol buffers. For example, taking a list of +10,000 protocol buffers, extracting a named field from each one, and +computing a aggregate statistics on those values would be extremely +slow with RProtoBuf, and while this is a useful class of operations, +it is outside of the scope of RProtoBuf. We should be very clear +about this to clarify the goals and strengths of RProtoBuf and its +reflection and object mapping. + +\subsection{Serialization comparison} + +TODO comparison of protobuf serialization sizes/times for various vectors. Compared to R's native serialization. Discussion of the RHIPE approach of serializing any/all R objects, vs more specific protocol buffers for specific R objects. + +\section{Basic usage example - tutorial.Person} + +\section{Application: distributed Data Collection with MapReduce} + +We could describe a common MapReduce pattern of having the MR written +in another language output protocol buffers that are later pulled into +R. There is some text about this in section 2 of +http://cran.r-project.org/web/packages/HistogramTools/vignettes/HistogramTools.pdf + +\section{Application: Sending/receiving Interaction With Servers} + +\section{Summary} + +This file is only a basic article template. For full details of \emph{The R Journal} style and information on how to prepare your article for submission, see the \href{http://journal.r-project.org/latex/RJauthorguide.pdf}{Instructions for Authors}. + +\bibliography{eddelbuettel-francois-stokely} + +\address{Author One\\ + Affiliation\\ + Address\\ + Country} +\email{author1 at work} + +\address{Author Two\\ + Affiliation\\ + Address\\ + Country} +\email{author2 at work} + +\address{Murray Stokely\\ + Google, Inc.\\ + 1600 Amphitheatre Parkway\\ + Mountain View, CA 94043\\ + USA} +\email{mstokely at google.com} From noreply at r-forge.r-project.org Tue Dec 17 01:20:47 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Dec 2013 01:20:47 +0100 (CET) Subject: [Rprotobuf-commits] r554 - in pkg: . src Message-ID: <20131217002047.851BC185CCC@r-forge.r-project.org> Author: edd Date: 2013-12-17 01:20:47 +0100 (Tue, 17 Dec 2013) New Revision: 554 Modified: pkg/ChangeLog pkg/src/rprotobuf.h Log: do not use 'extern "C"' on mutators.cpp functions returning atomistic or C++ types Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-16 16:26:21 UTC (rev 553) +++ pkg/ChangeLog 2013-12-17 00:20:47 UTC (rev 554) @@ -1,7 +1,7 @@ 2013-12-16 Dirk Eddelbuettel - * src/rprotobuf.h (RCPP_ENUM_TRAITS): Don't use extern "C" on two - internal functions returning a C++ type + * src/rprotobuf.h (RCPP_ENUM_TRAITS): Don't use extern "C" on + internal functions returning atomistic or C++ types 2013-12-15 Dirk Eddelbuettel Modified: pkg/src/rprotobuf.h =================================================================== --- pkg/src/rprotobuf.h 2013-12-16 16:26:21 UTC (rev 553) +++ pkg/src/rprotobuf.h 2013-12-17 00:20:47 UTC (rev 554) @@ -1,8 +1,9 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- +// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- // // rprotobuf.h: R/C++ interface class library // // Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2012 - 2013 Dirk Eddelbuettel, Romain Francois and Murray Stokely // // This file is part of RProtoBuf. // @@ -137,18 +138,18 @@ /* in mutators.cpp */ RcppExport SEXP setMessageField( SEXP, SEXP, SEXP ) ; -RcppExport int GET_int( SEXP, int ) ; -RcppExport double GET_double( SEXP, int ) ; -RcppExport float GET_float( SEXP, int ) ; -RcppExport int32 GET_int32( SEXP, int) ; -RcppExport int64 GET_int64( SEXP, int) ; -RcppExport uint32 GET_uint32( SEXP, int) ; -RcppExport uint64 GET_uint64( SEXP, int ) ; -RcppExport bool GET_bool( SEXP, int) ; - std::string GET_stdstring( SEXP, int ) ; - std::string GET_bytes( SEXP, int ) ; -RcppExport void CHECK_values_for_enum( GPB::FieldDescriptor*, SEXP) ; -RcppExport void CHECK_messages( GPB::FieldDescriptor*, SEXP) ; +int GET_int( SEXP, int ) ; +double GET_double( SEXP, int ) ; +float GET_float( SEXP, int ) ; +int32 GET_int32( SEXP, int) ; +int64 GET_int64( SEXP, int) ; +uint32 GET_uint32( SEXP, int) ; +uint64 GET_uint64( SEXP, int ) ; +bool GET_bool( SEXP, int) ; +std::string GET_stdstring( SEXP, int ) ; +std::string GET_bytes( SEXP, int ) ; +void CHECK_values_for_enum( GPB::FieldDescriptor*, SEXP) ; +void CHECK_messages( GPB::FieldDescriptor*, SEXP) ; /* in wrapper_ServiceDescriptor.cpp */ RcppExport SEXP ServiceDescriptor_length(SEXP); From noreply at r-forge.r-project.org Tue Dec 17 01:22:32 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Dec 2013 01:22:32 +0100 (CET) Subject: [Rprotobuf-commits] r555 - papers/rjournal Message-ID: <20131217002232.260F2185D84@r-forge.r-project.org> Author: edd Date: 2013-12-17 01:22:31 +0100 (Tue, 17 Dec 2013) New Revision: 555 Modified: papers/rjournal/eddelbuettel-francois-stokely.bib papers/rjournal/eddelbuettel-francois-stokely.tex Log: minor edits Modified: papers/rjournal/eddelbuettel-francois-stokely.bib =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-17 00:20:47 UTC (rev 554) +++ papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-17 00:22:31 UTC (rev 555) @@ -51,7 +51,7 @@ author = {Simon Urbanek and Yossi Rubner}, year = {2012}, note = {R package version 0.3-1}, - url = {http://CRAN.R-project.org/package=emdist}, + url = {http://cran.r-project.org/package=emdist}, } @article{pearson1895contributions, title={Contributions to the mathematical theory of evolution. II. Skew variation in homogeneous material}, @@ -65,8 +65,8 @@ @Manual{rprotobuf, title = {RProtoBuf: R Interface to the Protocol Buffers API}, author = {Romain Francois and Dirk Eddelbuettel and Murray Stokely}, - note = {R package version 0.2.6}, - year = {2012}, + note = {R package version 0.3.2}, + year = {2013}, url = {http://cran.r-project.org/web/packages/RProtoBuf/index.html}, } @Manual{r, @@ -74,8 +74,7 @@ author = {{R Core Team}}, organization = {R Foundation for Statistical Computing}, address = {Vienna, Austria}, - year = {2012}, - note = {{ISBN} 3-900051-07-0}, + year = {2013}, url = {http://www.R-project.org/}, } @article{dean2008mapreduce, Modified: papers/rjournal/eddelbuettel-francois-stokely.tex =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-17 00:20:47 UTC (rev 554) +++ papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-17 00:22:31 UTC (rev 555) @@ -7,17 +7,24 @@ \abstract{Modern data collection and analysis pipelines often involve a sophisticated mix of applications written in general purpose and specialized programming languages. Protocol Buffers are a popular - method of serializing structured data between applications. The + method of serializing structured data between applications---while remaining + indendent of programming languages or operating system. The \textbf{RProtoBuf} package provides a complete interface to this library. -TODO keep it less than 150 words. + %TODO(ms) keep it less than 150 words. } +%TODO(de) 'protocol buffers' or 'Protocol Buffers' ? + \section{Introduction} Comparison with what people start with in R : CSV -comparison with what is only slightly better: JSON +Comparison with what is only slightly better: JSON + +Maybe mention related, competing approaches such as BSON, Thrift, msgpack, +though we get carried away. + Introductory section which may include references in parentheses \citep{R}, or cite a reference such as \citet{R} in the text. @@ -136,11 +143,11 @@ \bibliography{eddelbuettel-francois-stokely} -\address{Author One\\ - Affiliation\\ - Address\\ - Country} -\email{author1 at work} +\address{Dirk Eddelbuettel\\ + Debian and R Projects\\ + 711 Monroe Avenue, River Forest, IL 60305\\ + USA} +\email{edd at debian.org} \address{Author Two\\ Affiliation\\ From noreply at r-forge.r-project.org Tue Dec 17 02:24:44 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Dec 2013 02:24:44 +0100 (CET) Subject: [Rprotobuf-commits] r556 - papers/rjournal Message-ID: <20131217012444.B4EEA18560F@r-forge.r-project.org> Author: murray Date: 2013-12-17 02:24:43 +0100 (Tue, 17 Dec 2013) New Revision: 556 Modified: papers/rjournal/RJwrapper.brf papers/rjournal/eddelbuettel-francois-stokely.tex Log: Improve/flesh-out introduction. Modified: papers/rjournal/RJwrapper.brf =================================================================== --- papers/rjournal/RJwrapper.brf 2013-12-17 00:22:31 UTC (rev 555) +++ papers/rjournal/RJwrapper.brf 2013-12-17 01:24:43 UTC (rev 556) @@ -1,2 +1,2 @@ -\backcite {R}{{1}{2.1}{section.2.1}} -\backcite {R}{{1}{2.1}{section.2.1}} +\backcite {R}{{1}{2.2}{section.2.2}} +\backcite {R}{{1}{2.2}{section.2.2}} Modified: papers/rjournal/eddelbuettel-francois-stokely.tex =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-17 00:22:31 UTC (rev 555) +++ papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-17 01:24:43 UTC (rev 556) @@ -9,7 +9,7 @@ specialized programming languages. Protocol Buffers are a popular method of serializing structured data between applications---while remaining indendent of programming languages or operating system. The - \textbf{RProtoBuf} package provides a complete interface to this + \CRANpkg{RProtoBuf} package provides a complete interface to this library. %TODO(ms) keep it less than 150 words. } @@ -18,13 +18,52 @@ \section{Introduction} -Comparison with what people start with in R : CSV +Modern data collection and analysis pipelines often involve a +sophisticated mix of applications used for collecting, cleaning, +analyzing, processing, and presenting data. Each stage of the data +analysis pipeline may involve storing intermediate results in a +file or sending them over the network. Programming langauges such as +Java, Ruby, Python, and R include built-in serialization support, but +these formats are tied to the specific programming language in use. +CSV files can be read and written by many applications and so are +often used for exporting tabular data. However, CSV files have a +number of disadvantages, such as a limitation of exporting only +tabular datasets, lack of type-safety, inefficient text representation +and parsing, and abiguities in the format involving special +characters. JSON is another widely supported format used mostly on +the web that removes many of these disadvantages, but it too suffers +from being too slow to parse and also does not provide strong typing +between integers and floating point. Large numbers of JSON messages +would also be required to duplicate the field names with each message. -Comparison with what is only slightly better: JSON +This article describes the basics of Google's Protocol Buffers through +an easy to use R package, \CRANpkg{RProtoBuf}. After describing the +basics of protocol buffers and \CRANpkg{RProtoBuf}, we illustrate +several common use cases for protocol buffers in data analysis. -Maybe mention related, competing approaches such as BSON, Thrift, msgpack, -though we get carried away. +\section{Protocol Bfufers} +Once the data serialization needs get complex enough, application +developers typically benefit from the use of an \emph{interface +description language}, or \emph{IDL}. IDLs like Google's Protocol +Buffers and Apache Thrift provide a compact well-documented schema for +cross-langauge data structures as well efficient binary interchange +formats. The schema can be used to generate model classes for +statically typed programming languages such as C++ and Java, or can be +used with reflection for dynamically typed programming languages. +Since the schema is provided separately from the encoded data, the +data can be efficiently encoded to minimize storage costs of the +stored data when compared with simple ``schema-less'' binary +interchange formats like BSON. + +%BSON, msgpack, Thrift, and Protocol Buffers take this latter approach, +%with the + +% There are references comparing these we should use here. + +TODO Also mention Thrift and msgpack and the references comparing some +of these tradeoffs. + Introductory section which may include references in parentheses \citep{R}, or cite a reference such as \citet{R} in the text. From noreply at r-forge.r-project.org Tue Dec 17 02:58:36 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Dec 2013 02:58:36 +0100 (CET) Subject: [Rprotobuf-commits] r557 - papers/rjournal Message-ID: <20131217015836.DF78C186199@r-forge.r-project.org> Author: murray Date: 2013-12-17 02:58:36 +0100 (Tue, 17 Dec 2013) New Revision: 557 Removed: papers/rjournal/RJwrapper.brf Modified: papers/rjournal/eddelbuettel-francois-stokely.bib papers/rjournal/eddelbuettel-francois-stokely.tex Log: Remove latex temporary file from revision control. Add more citations and text to intro. Deleted: papers/rjournal/RJwrapper.brf =================================================================== --- papers/rjournal/RJwrapper.brf 2013-12-17 01:24:43 UTC (rev 556) +++ papers/rjournal/RJwrapper.brf 2013-12-17 01:58:36 UTC (rev 557) @@ -1,2 +0,0 @@ -\backcite {R}{{1}{2.2}{section.2.2}} -\backcite {R}{{1}{2.2}{section.2.2}} Modified: papers/rjournal/eddelbuettel-francois-stokely.bib =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-17 01:24:43 UTC (rev 556) +++ papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-17 01:58:36 UTC (rev 557) @@ -53,15 +53,49 @@ note = {R package version 0.3-1}, url = {http://cran.r-project.org/package=emdist}, } - at article{pearson1895contributions, - title={Contributions to the mathematical theory of evolution. II. Skew variation in homogeneous material}, - author={Pearson, Karl}, - journal={Philosophical Transactions of the Royal Society of London. A}, - volume={186}, - pages={343--414}, - year={1895}, - publisher={JSTOR} + at article{Wegiel:2010:CTT:1932682.1869479, + author = {Wegiel, Michal and Krintz, Chandra}, + title = {Cross-language, Type-safe, and Transparent Object Sharing for Co-located Managed Runtimes}, + journal = {SIGPLAN Not.}, + issue_date = {October 2010}, + volume = {45}, + number = {10}, + month = oct, + year = {2010}, + issn = {0362-1340}, + pages = {223--240}, + numpages = {18}, + url = {http://doi.acm.org/10.1145/1932682.1869479}, + doi = {10.1145/1932682.1869479}, + acmid = {1869479}, + publisher = {ACM}, + address = {New York, NY, USA}, + keywords = {collection, communication, cross-language, garbage, managed, memory, model, object, rpc, runtimes, shared, synchronization, transparent, type-safe}, } + at inproceedings{Sumaray:2012:CDS:2184751.2184810, + author = {Sumaray, Audie and Makki, S. Kami}, + title = {A Comparison of Data Serialization Formats for Optimal Efficiency on a Mobile Platform}, + booktitle = {Proceedings of the 6th International Conference on Ubiquitous Information Management and Communication}, + series = {ICUIMC '12}, + year = {2012}, + isbn = {978-1-4503-1172-4}, + location = {Kuala Lumpur, Malaysia}, + pages = {48:1--48:6}, + articleno = {48}, + numpages = {6}, + url = {http://doi.acm.org/10.1145/2184751.2184810}, + doi = {10.1145/2184751.2184810}, + acmid = {2184810}, + publisher = {ACM}, + address = {New York, NY, USA}, + keywords = {Android, Dalvik, JSON, ProtoBuf, XML, data serialization, thrift}, +} + at Manual{RObjectTables, + title = {User-Defined Tables in the R Search Path}, + author = {Duncan Temple Lang}, + year = {2012}, + url = {http://www.omegahat.org/RObjectTables/RObjectTables.pdf}, +} @Manual{rprotobuf, title = {RProtoBuf: R Interface to the Protocol Buffers API}, author = {Romain Francois and Dirk Eddelbuettel and Murray Stokely}, Modified: papers/rjournal/eddelbuettel-francois-stokely.tex =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-17 01:24:43 UTC (rev 556) +++ papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-17 01:58:36 UTC (rev 557) @@ -8,7 +8,7 @@ a sophisticated mix of applications written in general purpose and specialized programming languages. Protocol Buffers are a popular method of serializing structured data between applications---while remaining - indendent of programming languages or operating system. The + independent of programming languages or operating system. The \CRANpkg{RProtoBuf} package provides a complete interface to this library. %TODO(ms) keep it less than 150 words. @@ -18,9 +18,15 @@ \section{Introduction} -Modern data collection and analysis pipelines often involve a -sophisticated mix of applications used for collecting, cleaning, -analyzing, processing, and presenting data. Each stage of the data +Modern data collection and analysis pipelines are increasingly being +built using collections of components to better manage software +complexity through reusability, modularity, and fault +isolation \citep{Wegiel:2010:CTT:1932682.1869479}. Different +programming languages are often used for the different phases of data +analysis -- collection, cleaning, analysis, post-processing, and +presentation in order to take advantage of the unique combination of +performance, speed of development, and library support offered by +different environments. Each stage of the data analysis pipeline may involve storing intermediate results in a file or sending them over the network. Programming langauges such as Java, Ruby, Python, and R include built-in serialization support, but @@ -41,7 +47,7 @@ basics of protocol buffers and \CRANpkg{RProtoBuf}, we illustrate several common use cases for protocol buffers in data analysis. -\section{Protocol Bfufers} +\section{Protocol Buffers} Once the data serialization needs get complex enough, application developers typically benefit from the use of an \emph{interface @@ -118,6 +124,13 @@ \section{Dynamic use: Protocol Buffers and R} +TODO(ms): random citations to work in: + +We make use of Object Tables \citep{RObjectTables} for lookup. +Many sources compare data serialization formats and show protocol +buffers very favorably to the alternatives, such +as \citep{Sumaray:2012:CDS:2184751.2184810} + This section describes how to use the R API to create and manipulate protocol buffer messages in R, and how to read and write the binary \emph{payload} of the messages to files and arbitrary binary From noreply at r-forge.r-project.org Tue Dec 17 03:09:43 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Dec 2013 03:09:43 +0100 (CET) Subject: [Rprotobuf-commits] r558 - papers/rjournal Message-ID: <20131217020943.D1D251800FB@r-forge.r-project.org> Author: murray Date: 2013-12-17 03:09:42 +0100 (Tue, 17 Dec 2013) New Revision: 558 Modified: papers/rjournal/Makefile Log: Add another temporary file to the clean list. Modified: papers/rjournal/Makefile =================================================================== --- papers/rjournal/Makefile 2013-12-17 01:58:36 UTC (rev 557) +++ papers/rjournal/Makefile 2013-12-17 02:09:42 UTC (rev 558) @@ -7,6 +7,7 @@ rm -fr RJwrapper.log rm -fr RJwrapper.bbl rm -fr RJwrapper.blg + rm -fr RJwrapper.brf RJwrapper.pdf: RJwrapper.tex eddelbuettel-francois-stokely.tex RJournal.sty pdflatex RJwrapper.tex From noreply at r-forge.r-project.org Tue Dec 17 03:12:56 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Dec 2013 03:12:56 +0100 (CET) Subject: [Rprotobuf-commits] r559 - papers/rjournal Message-ID: <20131217021256.D3DD4181050@r-forge.r-project.org> Author: murray Date: 2013-12-17 03:12:56 +0100 (Tue, 17 Dec 2013) New Revision: 559 Modified: papers/rjournal/eddelbuettel-francois-stokely.bib papers/rjournal/eddelbuettel-francois-stokely.tex Log: Also will want to cite Hadley's Split-Apply-Combine JSS paper as that pattern works much better with RProtoBuf and you remove the restriction that all phases must be done in R. Modified: papers/rjournal/eddelbuettel-francois-stokely.bib =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-17 02:09:42 UTC (rev 558) +++ papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-17 02:12:56 UTC (rev 559) @@ -72,6 +72,16 @@ address = {New York, NY, USA}, keywords = {collection, communication, cross-language, garbage, managed, memory, model, object, rpc, runtimes, shared, synchronization, transparent, type-safe}, } + at article{wickham2011split, + title={The split-apply-combine strategy for data analysis}, + author={Wickham, Hadley}, + journal={Journal of Statistical Software}, + volume={40}, + number={1}, + pages={1--29}, + year={2011}, + publisher={Citeseer} +} @inproceedings{Sumaray:2012:CDS:2184751.2184810, author = {Sumaray, Audie and Makki, S. Kami}, title = {A Comparison of Data Serialization Formats for Optimal Efficiency on a Mobile Platform}, Modified: papers/rjournal/eddelbuettel-francois-stokely.tex =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-17 02:09:42 UTC (rev 558) +++ papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-17 02:12:56 UTC (rev 559) @@ -42,6 +42,11 @@ between integers and floating point. Large numbers of JSON messages would also be required to duplicate the field names with each message. +TODO(ms): Also work in reference to Split-Apply-Combine pattern for +data analysis \citep{wickham2011split}, since that is a great pattern +but it seems overly optimistic to expect all of those phases to always +be done in the same language. + This article describes the basics of Google's Protocol Buffers through an easy to use R package, \CRANpkg{RProtoBuf}. After describing the basics of protocol buffers and \CRANpkg{RProtoBuf}, we illustrate @@ -125,7 +130,7 @@ \section{Dynamic use: Protocol Buffers and R} TODO(ms): random citations to work in: - +q We make use of Object Tables \citep{RObjectTables} for lookup. Many sources compare data serialization formats and show protocol buffers very favorably to the alternatives, such From noreply at r-forge.r-project.org Tue Dec 17 05:49:11 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Dec 2013 05:49:11 +0100 (CET) Subject: [Rprotobuf-commits] r560 - papers/rjournal Message-ID: <20131217044911.9EA22185F80@r-forge.r-project.org> Author: murray Date: 2013-12-17 05:49:10 +0100 (Tue, 17 Dec 2013) New Revision: 560 Added: papers/rjournal/eddelbuettel-francois-stokely.Rnw Removed: papers/rjournal/eddelbuettel-francois-stokely.tex Modified: papers/rjournal/Makefile Log: Move the TeX file over to Rnw and update the makefile to run Sweave so we can more quickly insert example usage sections in the document. Modified: papers/rjournal/Makefile =================================================================== --- papers/rjournal/Makefile 2013-12-17 02:12:56 UTC (rev 559) +++ papers/rjournal/Makefile 2013-12-17 04:49:10 UTC (rev 560) @@ -9,7 +9,8 @@ rm -fr RJwrapper.blg rm -fr RJwrapper.brf -RJwrapper.pdf: RJwrapper.tex eddelbuettel-francois-stokely.tex RJournal.sty +RJwrapper.pdf: RJwrapper.tex eddelbuettel-francois-stokely.Rnw RJournal.sty + R CMD Sweave eddelbuettel-francois-stokely.Rnw pdflatex RJwrapper.tex bibtex RJwrapper pdflatex RJwrapper.tex Copied: papers/rjournal/eddelbuettel-francois-stokely.Rnw (from rev 559, papers/rjournal/eddelbuettel-francois-stokely.tex) =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw (rev 0) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-17 04:49:10 UTC (rev 560) @@ -0,0 +1,220 @@ +% !TeX root = RJwrapper.tex +\title{RProtoBuf: Efficient Cross-Language Data Serialization in R} +\author{by Dirk Eddelbuettel, Romain Fran\c{c}ois, and Murray Stokely} + +\maketitle + +\abstract{Modern data collection and analysis pipelines often involve + a sophisticated mix of applications written in general purpose and + specialized programming languages. Protocol Buffers are a popular + method of serializing structured data between applications---while remaining + independent of programming languages or operating system. The + \CRANpkg{RProtoBuf} package provides a complete interface to this + library. + %TODO(ms) keep it less than 150 words. +} + +%TODO(de) 'protocol buffers' or 'Protocol Buffers' ? + +\section{Introduction} + +Modern data collection and analysis pipelines are increasingly being +built using collections of components to better manage software +complexity through reusability, modularity, and fault +isolation \citep{Wegiel:2010:CTT:1932682.1869479}. Different +programming languages are often used for the different phases of data +analysis -- collection, cleaning, analysis, post-processing, and +presentation in order to take advantage of the unique combination of +performance, speed of development, and library support offered by +different environments. Each stage of the data +analysis pipeline may involve storing intermediate results in a +file or sending them over the network. Programming langauges such as +Java, Ruby, Python, and R include built-in serialization support, but +these formats are tied to the specific programming language in use. +CSV files can be read and written by many applications and so are +often used for exporting tabular data. However, CSV files have a +number of disadvantages, such as a limitation of exporting only +tabular datasets, lack of type-safety, inefficient text representation +and parsing, and abiguities in the format involving special +characters. JSON is another widely supported format used mostly on +the web that removes many of these disadvantages, but it too suffers +from being too slow to parse and also does not provide strong typing +between integers and floating point. Large numbers of JSON messages +would also be required to duplicate the field names with each message. + +TODO(ms): Also work in reference to Split-Apply-Combine pattern for +data analysis \citep{wickham2011split}, since that is a great pattern +but it seems overly optimistic to expect all of those phases to always +be done in the same language. + +This article describes the basics of Google's Protocol Buffers through +an easy to use R package, \CRANpkg{RProtoBuf}. After describing the +basics of protocol buffers and \CRANpkg{RProtoBuf}, we illustrate +several common use cases for protocol buffers in data analysis. + +\section{Protocol Buffers} + +Once the data serialization needs get complex enough, application +developers typically benefit from the use of an \emph{interface +description language}, or \emph{IDL}. IDLs like Google's Protocol +Buffers and Apache Thrift provide a compact well-documented schema for +cross-langauge data structures as well efficient binary interchange +formats. The schema can be used to generate model classes for +statically typed programming languages such as C++ and Java, or can be +used with reflection for dynamically typed programming languages. +Since the schema is provided separately from the encoded data, the +data can be efficiently encoded to minimize storage costs of the +stored data when compared with simple ``schema-less'' binary +interchange formats like BSON. + +%BSON, msgpack, Thrift, and Protocol Buffers take this latter approach, +%with the + +% There are references comparing these we should use here. + +TODO Also mention Thrift and msgpack and the references comparing some +of these tradeoffs. + +Introductory section which may include references in parentheses +\citep{R}, or cite a reference such as \citet{R} in the text. + +Protocol buffers are a language-neutral, platform-neutral, extensible +way of serializing structured data for use in communications +protocols, data storage, and more. + +Protocol Buffers offer key features such as an efficient data interchange +format that is both language- and operating system-agnostic yet uses a +lightweight and highly performant encoding, object serialization and +de-serialization as well data and configuration management. Protocol +buffers are also forward compatible: updates to the \texttt{proto} +files do not break programs built against the previous specification. + +While benchmarks are not available, Google states on the project page that in +comparison to XML, protocol buffers are at the same time \textsl{simpler}, +between three to ten times \textsl{smaller}, between twenty and one hundred +times \textsl{faster}, as well as less ambiguous and easier to program. + +The protocol buffers code is released under an open-source (BSD) license. The +protocol buffer project (\url{http://code.google.com/p/protobuf/}) +contains a C++ library and a set of runtime libraries and compilers for +C++, Java and Python. + +With these languages, the workflow follows standard practice of so-called +Interface Description Languages (IDL) +(c.f. \href{http://en.wikipedia.org/wiki/Interface_description_language}{Wikipedia + on IDL}). This consists of compiling a protocol buffer description file +(ending in \texttt{.proto}) into language specific classes that can be used +to create, read, write and manipulate protocol buffer messages. In other +words, given the 'proto' description file, code is automatically generated +for the chosen target language(s). The project page contains a tutorial for +each of these officially supported languages: +\url{http://code.google.com/apis/protocolbuffers/docs/tutorials.html} + +Besides the officially supported C++, Java and Python implementations, several projects have been +created to support protocol buffers for many languages. The list of known +languages to support protocol buffers is compiled as part of the +project page: \url{http://code.google.com/p/protobuf/wiki/ThirdPartyAddOns} + +The protocol buffer project page contains a comprehensive +description of the language: \url{http://code.google.com/apis/protocolbuffers/docs/proto.html} + +%This section may contain a figure such as Figure~\ref{figure:rlogo}. +% +%\begin{figure}[htbp] +% \centering +% \includegraphics{Rlogo} +% \caption{The logo of R.} +% \label{figure:rlogo} +%\end{figure} + +\section{Dynamic use: Protocol Buffers and R} + +TODO(ms): random citations to work in: +q +We make use of Object Tables \citep{RObjectTables} for lookup. +Many sources compare data serialization formats and show protocol +buffers very favorably to the alternatives, such +as \citep{Sumaray:2012:CDS:2184751.2184810} + +This section describes how to use the R API to create and manipulate +protocol buffer messages in R, and how to read and write the +binary \emph{payload} of the messages to files and arbitrary binary +R connections. + +\subsection{Importing proto files} + +In contrast to the other languages (Java, C++, Python) that are officially +supported by Google, the implementation used by the \texttt{RProtoBuf} +package does not rely on the \texttt{protoc} compiler (with the exception of +the two functions discussed in the previous section). This means that no +initial step of statically compiling the proto file into C++ code that is +then accessed by R code is necessary. Instead, \texttt{proto} files are +parsed and processed \textsl{at runtime} by the protobuf C++ library---which +is much more appropriate for a dynamic language. + +The \texttt{readProtoFiles} function allows importing \texttt{proto} +files in several ways. + +% Example code snippet. +% TODO(mstokely): Remove this. +\begin{example} + x <- 1:10 + result <- myFunction(x) +\end{example} + +\section{Related work on IDLs (greatly expanded from what you have)} + +\section{Design tradeoffs: reflection vs proto compiler (not addressed + at all in current vignettes)} + +\subsection{Performance considerations} + +TODO RProtoBuf is quite flexible and easy to use for interactive +analysis, but it is not designed for certain classes of operations one +might like to do with protocol buffers. For example, taking a list of +10,000 protocol buffers, extracting a named field from each one, and +computing a aggregate statistics on those values would be extremely +slow with RProtoBuf, and while this is a useful class of operations, +it is outside of the scope of RProtoBuf. We should be very clear +about this to clarify the goals and strengths of RProtoBuf and its +reflection and object mapping. + +\subsection{Serialization comparison} + +TODO comparison of protobuf serialization sizes/times for various vectors. Compared to R's native serialization. Discussion of the RHIPE approach of serializing any/all R objects, vs more specific protocol buffers for specific R objects. + +\section{Basic usage example - tutorial.Person} + +\section{Application: distributed Data Collection with MapReduce} + +We could describe a common MapReduce pattern of having the MR written +in another language output protocol buffers that are later pulled into +R. There is some text about this in section 2 of +http://cran.r-project.org/web/packages/HistogramTools/vignettes/HistogramTools.pdf + +\section{Application: Sending/receiving Interaction With Servers} + +\section{Summary} + +This file is only a basic article template. For full details of \emph{The R Journal} style and information on how to prepare your article for submission, see the \href{http://journal.r-project.org/latex/RJauthorguide.pdf}{Instructions for Authors}. + +\bibliography{eddelbuettel-francois-stokely} + +\address{Dirk Eddelbuettel\\ + Debian and R Projects\\ + 711 Monroe Avenue, River Forest, IL 60305\\ + USA} +\email{edd at debian.org} + +\address{Author Two\\ + Affiliation\\ + Address\\ + Country} +\email{author2 at work} + +\address{Murray Stokely\\ + Google, Inc.\\ + 1600 Amphitheatre Parkway\\ + Mountain View, CA 94043\\ + USA} +\email{mstokely at google.com} Property changes on: papers/rjournal/eddelbuettel-francois-stokely.Rnw ___________________________________________________________________ Added: svn:mergeinfo + Deleted: papers/rjournal/eddelbuettel-francois-stokely.tex =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-17 02:12:56 UTC (rev 559) +++ papers/rjournal/eddelbuettel-francois-stokely.tex 2013-12-17 04:49:10 UTC (rev 560) @@ -1,220 +0,0 @@ -% !TeX root = RJwrapper.tex -\title{RProtoBuf: Efficient Cross-Language Data Serialization in R} -\author{by Dirk Eddelbuettel, Romain Fran\c{c}ois, and Murray Stokely} - -\maketitle - -\abstract{Modern data collection and analysis pipelines often involve - a sophisticated mix of applications written in general purpose and - specialized programming languages. Protocol Buffers are a popular - method of serializing structured data between applications---while remaining - independent of programming languages or operating system. The - \CRANpkg{RProtoBuf} package provides a complete interface to this - library. - %TODO(ms) keep it less than 150 words. -} - -%TODO(de) 'protocol buffers' or 'Protocol Buffers' ? - -\section{Introduction} - -Modern data collection and analysis pipelines are increasingly being -built using collections of components to better manage software -complexity through reusability, modularity, and fault -isolation \citep{Wegiel:2010:CTT:1932682.1869479}. Different -programming languages are often used for the different phases of data -analysis -- collection, cleaning, analysis, post-processing, and -presentation in order to take advantage of the unique combination of -performance, speed of development, and library support offered by -different environments. Each stage of the data -analysis pipeline may involve storing intermediate results in a -file or sending them over the network. Programming langauges such as -Java, Ruby, Python, and R include built-in serialization support, but -these formats are tied to the specific programming language in use. -CSV files can be read and written by many applications and so are -often used for exporting tabular data. However, CSV files have a -number of disadvantages, such as a limitation of exporting only -tabular datasets, lack of type-safety, inefficient text representation -and parsing, and abiguities in the format involving special -characters. JSON is another widely supported format used mostly on -the web that removes many of these disadvantages, but it too suffers -from being too slow to parse and also does not provide strong typing -between integers and floating point. Large numbers of JSON messages -would also be required to duplicate the field names with each message. - -TODO(ms): Also work in reference to Split-Apply-Combine pattern for -data analysis \citep{wickham2011split}, since that is a great pattern -but it seems overly optimistic to expect all of those phases to always -be done in the same language. - -This article describes the basics of Google's Protocol Buffers through -an easy to use R package, \CRANpkg{RProtoBuf}. After describing the -basics of protocol buffers and \CRANpkg{RProtoBuf}, we illustrate -several common use cases for protocol buffers in data analysis. - -\section{Protocol Buffers} - -Once the data serialization needs get complex enough, application -developers typically benefit from the use of an \emph{interface -description language}, or \emph{IDL}. IDLs like Google's Protocol -Buffers and Apache Thrift provide a compact well-documented schema for -cross-langauge data structures as well efficient binary interchange -formats. The schema can be used to generate model classes for -statically typed programming languages such as C++ and Java, or can be -used with reflection for dynamically typed programming languages. -Since the schema is provided separately from the encoded data, the -data can be efficiently encoded to minimize storage costs of the -stored data when compared with simple ``schema-less'' binary -interchange formats like BSON. - -%BSON, msgpack, Thrift, and Protocol Buffers take this latter approach, -%with the - -% There are references comparing these we should use here. - -TODO Also mention Thrift and msgpack and the references comparing some -of these tradeoffs. - -Introductory section which may include references in parentheses -\citep{R}, or cite a reference such as \citet{R} in the text. - -Protocol buffers are a language-neutral, platform-neutral, extensible -way of serializing structured data for use in communications -protocols, data storage, and more. - -Protocol Buffers offer key features such as an efficient data interchange -format that is both language- and operating system-agnostic yet uses a -lightweight and highly performant encoding, object serialization and -de-serialization as well data and configuration management. Protocol -buffers are also forward compatible: updates to the \texttt{proto} -files do not break programs built against the previous specification. - -While benchmarks are not available, Google states on the project page that in -comparison to XML, protocol buffers are at the same time \textsl{simpler}, -between three to ten times \textsl{smaller}, between twenty and one hundred -times \textsl{faster}, as well as less ambiguous and easier to program. - -The protocol buffers code is released under an open-source (BSD) license. The -protocol buffer project (\url{http://code.google.com/p/protobuf/}) -contains a C++ library and a set of runtime libraries and compilers for -C++, Java and Python. - -With these languages, the workflow follows standard practice of so-called -Interface Description Languages (IDL) -(c.f. \href{http://en.wikipedia.org/wiki/Interface_description_language}{Wikipedia - on IDL}). This consists of compiling a protocol buffer description file -(ending in \texttt{.proto}) into language specific classes that can be used -to create, read, write and manipulate protocol buffer messages. In other -words, given the 'proto' description file, code is automatically generated -for the chosen target language(s). The project page contains a tutorial for -each of these officially supported languages: -\url{http://code.google.com/apis/protocolbuffers/docs/tutorials.html} - -Besides the officially supported C++, Java and Python implementations, several projects have been -created to support protocol buffers for many languages. The list of known -languages to support protocol buffers is compiled as part of the -project page: \url{http://code.google.com/p/protobuf/wiki/ThirdPartyAddOns} - -The protocol buffer project page contains a comprehensive -description of the language: \url{http://code.google.com/apis/protocolbuffers/docs/proto.html} - -%This section may contain a figure such as Figure~\ref{figure:rlogo}. -% -%\begin{figure}[htbp] -% \centering -% \includegraphics{Rlogo} -% \caption{The logo of R.} -% \label{figure:rlogo} -%\end{figure} - -\section{Dynamic use: Protocol Buffers and R} - -TODO(ms): random citations to work in: -q -We make use of Object Tables \citep{RObjectTables} for lookup. -Many sources compare data serialization formats and show protocol -buffers very favorably to the alternatives, such -as \citep{Sumaray:2012:CDS:2184751.2184810} - -This section describes how to use the R API to create and manipulate -protocol buffer messages in R, and how to read and write the -binary \emph{payload} of the messages to files and arbitrary binary -R connections. - -\subsection{Importing proto files} - -In contrast to the other languages (Java, C++, Python) that are officially -supported by Google, the implementation used by the \texttt{RProtoBuf} -package does not rely on the \texttt{protoc} compiler (with the exception of -the two functions discussed in the previous section). This means that no -initial step of statically compiling the proto file into C++ code that is -then accessed by R code is necessary. Instead, \texttt{proto} files are -parsed and processed \textsl{at runtime} by the protobuf C++ library---which -is much more appropriate for a dynamic language. - -The \texttt{readProtoFiles} function allows importing \texttt{proto} -files in several ways. - -% Example code snippet. -% TODO(mstokely): Remove this. -\begin{example} - x <- 1:10 - result <- myFunction(x) -\end{example} - -\section{Related work on IDLs (greatly expanded from what you have)} - -\section{Design tradeoffs: reflection vs proto compiler (not addressed - at all in current vignettes)} - -\subsection{Performance considerations} - -TODO RProtoBuf is quite flexible and easy to use for interactive -analysis, but it is not designed for certain classes of operations one -might like to do with protocol buffers. For example, taking a list of -10,000 protocol buffers, extracting a named field from each one, and -computing a aggregate statistics on those values would be extremely -slow with RProtoBuf, and while this is a useful class of operations, -it is outside of the scope of RProtoBuf. We should be very clear -about this to clarify the goals and strengths of RProtoBuf and its -reflection and object mapping. - -\subsection{Serialization comparison} - -TODO comparison of protobuf serialization sizes/times for various vectors. Compared to R's native serialization. Discussion of the RHIPE approach of serializing any/all R objects, vs more specific protocol buffers for specific R objects. - -\section{Basic usage example - tutorial.Person} - -\section{Application: distributed Data Collection with MapReduce} - -We could describe a common MapReduce pattern of having the MR written -in another language output protocol buffers that are later pulled into -R. There is some text about this in section 2 of -http://cran.r-project.org/web/packages/HistogramTools/vignettes/HistogramTools.pdf - -\section{Application: Sending/receiving Interaction With Servers} - -\section{Summary} - -This file is only a basic article template. For full details of \emph{The R Journal} style and information on how to prepare your article for submission, see the \href{http://journal.r-project.org/latex/RJauthorguide.pdf}{Instructions for Authors}. - -\bibliography{eddelbuettel-francois-stokely} - -\address{Dirk Eddelbuettel\\ - Debian and R Projects\\ - 711 Monroe Avenue, River Forest, IL 60305\\ - USA} -\email{edd at debian.org} - -\address{Author Two\\ - Affiliation\\ - Address\\ - Country} -\email{author2 at work} - -\address{Murray Stokely\\ - Google, Inc.\\ - 1600 Amphitheatre Parkway\\ - Mountain View, CA 94043\\ - USA} -\email{mstokely at google.com} From noreply at r-forge.r-project.org Tue Dec 17 06:20:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Dec 2013 06:20:27 +0100 (CET) Subject: [Rprotobuf-commits] r561 - papers/rjournal Message-ID: <20131217052027.88376186286@r-forge.r-project.org> Author: murray Date: 2013-12-17 06:20:27 +0100 (Tue, 17 Dec 2013) New Revision: 561 Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw Log: Move over some sections from the introduction vignette that can be included here. I've started moving the pieces over piecemeal because the intro vignette is too much like a reference manual and needs more of a narrative which I'm attempting to provide here. Specifically, section 3 "Classes, Methods, and Pseudo-Methods" of the intro vignette is 20 pages on its own of reference material that would not be as appropriate for a writeup in R Journal or JSS or something. It is good content, but we need to replace much of that with very concise tables or similar. The number of classes and methods is quite high for RProtoBuf, and so I don't think we can describe each on in detail in this type of writeup without losing sight of the higher level point about why this is cool and useful. Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-17 04:49:10 UTC (rev 560) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-17 05:20:27 UTC (rev 561) @@ -141,6 +141,13 @@ binary \emph{payload} of the messages to files and arbitrary binary R connections. +\emph{TODO(mstokely): Remove this example code snippet} + +\begin{example} + x <- 1:10 + result <- myFunction(x) +\end{example} + \subsection{Importing proto files} In contrast to the other languages (Java, C++, Python) that are officially @@ -155,13 +162,210 @@ The \texttt{readProtoFiles} function allows importing \texttt{proto} files in several ways. -% Example code snippet. -% TODO(mstokely): Remove this. -\begin{example} - x <- 1:10 - result <- myFunction(x) -\end{example} +<<>>= +library(RProtoBuf) +args( readProtoFiles ) +@ +Using the \texttt{file} argument, one can specify one or several file +paths that ought to be proto files. + +<<>>= +proto.dir <- system.file( "proto", package = "RProtoBuf" ) +proto.file <- file.path( proto.dir, "addressbook.proto" ) +<>= +readProtoFiles( proto.file ) +@ + +With the \texttt{dir} argument, which is +ignored if the \texttt{file} is supplied, all files matching the +\texttt{.proto} extension will be imported. + +<<>>= +dir( proto.dir, pattern = "\\.proto$", full.names = TRUE ) +<>= +readProtoFiles( dir = proto.dir ) +@ + +Finally, with the +\texttt{package} argument (ignored if \texttt{file} or +\texttt{dir} is supplied), the function will import all \texttt{.proto} +files that are located in the \texttt{proto} sub-directory of the given +package. A typical use for this argument is in the \texttt{.onLoad} +function of a package. + +<>= +readProtoFiles( package = "RProtoBuf" ) +@ + +Once the proto files are imported, all message descriptors are +are available in the R search path in the \texttt{RProtoBuf:DescriptorPool} +special environment. The underlying mechanism used here is +described in more detail in section~\ref{sec-lookup}. + +<<>>= +ls( "RProtoBuf:DescriptorPool" ) +@ + + +\subsection{Creating a message} + +The objects contained in the special environment are +descriptors for their associated message types. Descriptors will be +discussed in detail in another part of this document, but for the +purpose of this section, descriptors are just used with the \texttt{new} +function to create messages. + +<<>>= +p <- new( tutorial.Person, name = "Romain", id = 1 ) +@ + +\subsection{Access and modify fields of a message} + +Once the message is created, its fields can be queried +and modified using the dollar operator of R, making protocol +buffer messages seem like lists. + +<<>>= +p$name +p$id +p$email <- "francoisromain at free.fr" +@ + +However, as opposed to R lists, no partial matching is performed +and the name must be given entirely. + +The \verb|[[| operator can also be used to query and set fields +of a mesages, supplying either their name or their tag number : + +<<>>= +p[["name"]] <- "Romain Francois" +p[[ 2 ]] <- 3 +p[[ "email" ]] +@ + +Protocol buffers include a 64-bit integer type, but R lacks native +64-bit integer support. A workaround is available and described in +Section~\ref{sec:int64} for working with large integer values. + +% TODO(mstokely): Document extensions here. +% There are none in addressbook.proto though. + +\subsection{Display messages} + +Protocol buffer messages and descriptors implement \texttt{show} +methods that provide basic information about the message : + +<<>>= +p +@ + +For additional information, such as for debugging purposes, +the \texttt{as.character} method provides a more complete ASCII +representation of the contents of a message. + +<<>>= +writeLines( as.character( p ) ) +@ + +\subsection{Serializing messages} + +However, the main focus of protocol buffer messages is +efficiency. Therefore, messages are transported as a sequence +of bytes. The \texttt{serialize} method is implemented for +protocol buffer messages to serialize a message into the sequence of +bytes (raw vector in R speech) that represents the message. + +<<>>= +serialize( p, NULL ) +@ + +The same method can also be used to serialize messages to files : + +<<>>= +tf1 <- tempfile() +tf1 +serialize( p, tf1 ) +readBin( tf1, raw(0), 500 ) +@ + +Or to arbitrary binary connections: + +<<>>= +tf2 <- tempfile() +con <- file( tf2, open = "wb" ) +serialize( p, con ) +close( con ) +readBin( tf2, raw(0), 500 ) +@ + +\texttt{serialize} can also be used in a more traditionnal +object oriented fashion using the dollar operator : + +<<>>= +# serialize to a file +p$serialize( tf1 ) +# serialize to a binary connection +con <- file( tf2, open = "wb" ) +p$serialize( con ) +close( con ) +@ + + +\subsection{Parsing messages} + +The \texttt{RProtoBuf} package defines the \texttt{read} +function to read messages from files, raw vector (the message payload) +and arbitrary binary connections. + +<<>>= +args( read ) +@ + + +The binary representation of the message (often called the payload) +does not contain information that can be used to dynamically +infer the message type, so we have to provide this information +to the \texttt{read} function in the form of a descriptor : + +<<>>= +message <- read( tutorial.Person, tf1 ) +writeLines( as.character( message ) ) +@ + +The \texttt{input} argument of \texttt{read} can also be a binary +readable R connection, such as a binary file connection: + +<<>>= +con <- file( tf2, open = "rb" ) +message <- read( tutorial.Person, con ) +close( con ) +writeLines( as.character( message ) ) +@ + +Finally, the payload of the message can be used : + +<<>>= +# reading the raw vector payload of the message +payload <- readBin( tf1, raw(0), 5000 ) +message <- read( tutorial.Person, payload ) +@ + + +\texttt{read} can also be used as a pseudo method of the descriptor +object : + +<<>>= +# reading from a file +message <- tutorial.Person$read( tf1 ) +# reading from a binary connection +con <- file( tf2, open = "rb" ) +message <- tutorial.Person$read( con ) +close( con ) +# read from the payload +message <- tutorial.Person$read( payload ) +@ + \section{Related work on IDLs (greatly expanded from what you have)} \section{Design tradeoffs: reflection vs proto compiler (not addressed @@ -183,6 +387,104 @@ TODO comparison of protobuf serialization sizes/times for various vectors. Compared to R's native serialization. Discussion of the RHIPE approach of serializing any/all R objects, vs more specific protocol buffers for specific R objects. + +\section{Descriptor lookup} +\label{sec-lookup} + +The \texttt{RProtoBuf} package uses the user defined tables framework +that is defined as part of the \texttt{RObjectTables} package available +from the OmegaHat project. + +The feature allows \texttt{RProtoBuf} to install the +special environment \emph{RProtoBuf:DescriptorPool} in the R search path. +The environment is special in that, instead of being associated with a +static hash table, it is dynamically queried by R as part of R's usual +variable lookup. In other words, it means that when the R interpreter +looks for a binding to a symbol (foo) in its search path, +it asks to our package if it knows the binding "foo", this is then +implemented by the \texttt{RProtoBuf} package by calling an internal +method of the \texttt{protobuf} C++ library. + +\section{64-bit integer issues} +\label{sec:int64} + +R does not have native 64-bit integer support. Instead, R treats +large integers as doubles which have limited precision. For example, +it loses the ability to distinguish some distinct integers: + +<<>>= +2^53 == (2^53 + 1) +@ + +Protocol Buffers are frequently used to pass data between different +systems, however, and most other systems these days have support for +64-bit integers. To work around this, RProtoBuf allows users to get +and set 64-bit integer types by treating them as characters. + +<>= +if (!exists("protobuf_unittest.TestAllTypes", + "RProtoBuf:DescriptorPool")) { + unittest.proto.file <- system.file("unitTests", "data", + "unittest.proto", + package="RProtoBuf") + readProtoFiles(file=unittest.proto.file) +} +@ + +If we try to set an int64 field in R to double values, we lose +precision: + +<<>>= +test <- new(protobuf_unittest.TestAllTypes) +test$repeated_int64 <- c(2^53, 2^53+1) +length(unique(test$repeated_int64)) +@ + +However, we can specify the values as character strings so that the +C++ library on which RProtoBuf is based can store a true 64-bit +integer representation of the data. + +<<>>= +test$repeated_int64 <- c("9007199254740992", "9007199254740993") +@ + +When reading the value back into R, numeric types are returned by +default, but when the full precision is required a character value +will be returned if the \texttt{RProtoBuf.int64AsString} option is set +to \texttt{TRUE}. + +<<>>= +options("RProtoBuf.int64AsString" = FALSE) +test$repeated_int64 +length(unique(test$repeated_int64)) +options("RProtoBuf.int64AsString" = TRUE) +test$repeated_int64 +length(unique(test$repeated_int64)) +@ + +<>= +options("RProtoBuf.int64AsString" = FALSE) +@ + +\section{Other approaches} + +Saptarshi Guha wrote another package that deals with integration +of protocol buffer messages with R, taking a different angle : +serializing any R object as a message, based on a single catch-all +\texttt{proto} file. Saptarshi's package is available at +\url{http://ml.stat.purdue.edu/rhipe/doc/html/ProtoBuffers.html}. + +Jeroen Ooms took a similar approach influenced by Saptarshi in his +\texttt{RProtoBufUtils} package. Unlike Saptarshi's package, +RProtoBufUtils depends on RProtoBuf for underlying message operations. +This package is available at +\url{https://github.com/jeroenooms/RProtoBufUtils}. + +% Phillip Yelland wrote another implementation, currently proprietary, +% that has significant speed advantages when querying fields from a +% large number of protocol buffers, but is less user friendly for the +% basic cases documented here. + \section{Basic usage example - tutorial.Person} \section{Application: distributed Data Collection with MapReduce} @@ -194,10 +496,20 @@ \section{Application: Sending/receiving Interaction With Servers} +Unlike Apache Thrift, Protocol Buffers do not include a concrete RPC +implementation. However, serialized protocol buffers can trivially be +sent over TCP or integrated with a proprietary RPC system. Combined +with an RPC system this means that one can interactively craft request +messages, send the serialized message to a remote server, read back a +response, and then parse the response protocol buffer interactively. + \section{Summary} -This file is only a basic article template. For full details of \emph{The R Journal} style and information on how to prepare your article for submission, see the \href{http://journal.r-project.org/latex/RJauthorguide.pdf}{Instructions for Authors}. +Its pretty useful. Murray to see if he can get approval to talk a +tiny bit about how much its used at Google. +%This file is only a basic article template. For full details of \emph{The R Journal} style and information on how to prepare your article for submission, see the \href{http://journal.r-project.org/latex/RJauthorguide.pdf}{Instructions for Authors}. + \bibliography{eddelbuettel-francois-stokely} \address{Dirk Eddelbuettel\\ From noreply at r-forge.r-project.org Tue Dec 17 07:48:51 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Dec 2013 07:48:51 +0100 (CET) Subject: [Rprotobuf-commits] r562 - papers/rjournal Message-ID: <20131217064851.240EF185E22@r-forge.r-project.org> Author: murray Date: 2013-12-17 07:48:50 +0100 (Tue, 17 Dec 2013) New Revision: 562 Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw Log: Include an example protocol buffer definition early in the file and example code accessing it. As with everything here, still very rough. Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-17 05:20:27 UTC (rev 561) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-17 06:48:50 UTC (rev 562) @@ -118,6 +118,32 @@ The protocol buffer project page contains a comprehensive description of the language: \url{http://code.google.com/apis/protocolbuffers/docs/proto.html} +\begin{example} +package tutorial; +message Person { + required string name = 1; + required int32 id = 2; // Unique ID number for person. + optional string email = 3; + enum PhoneType { + MOBILE = 0; HOME = 1; WORK = 2; + } + message PhoneNumber { + required string number = 1; + optional PhoneType type = 2 [default = HOME]; + } + repeated PhoneNumber phone = 4; +} +\end{example} + +<>= +library(RProtoBuf) +person <- new(tutorial.Person, id=1, name="Romain") +person$id +person$name +person$name <- "Dirk" +cat(as.character(person)) +@ + %This section may contain a figure such as Figure~\ref{figure:rlogo}. % %\begin{figure}[htbp] @@ -130,8 +156,8 @@ \section{Dynamic use: Protocol Buffers and R} TODO(ms): random citations to work in: -q -We make use of Object Tables \citep{RObjectTables} for lookup. + + Many sources compare data serialization formats and show protocol buffers very favorably to the alternatives, such as \citep{Sumaray:2012:CDS:2184751.2184810} @@ -162,11 +188,6 @@ The \texttt{readProtoFiles} function allows importing \texttt{proto} files in several ways. -<<>>= -library(RProtoBuf) -args( readProtoFiles ) -@ - Using the \texttt{file} argument, one can specify one or several file paths that ought to be proto files. @@ -393,7 +414,7 @@ The \texttt{RProtoBuf} package uses the user defined tables framework that is defined as part of the \texttt{RObjectTables} package available -from the OmegaHat project. +from the OmegaHat project \citep{RObjectTables}. The feature allows \texttt{RProtoBuf} to install the special environment \emph{RProtoBuf:DescriptorPool} in the R search path. @@ -475,7 +496,7 @@ \url{http://ml.stat.purdue.edu/rhipe/doc/html/ProtoBuffers.html}. Jeroen Ooms took a similar approach influenced by Saptarshi in his -\texttt{RProtoBufUtils} package. Unlike Saptarshi's package, +\pkg{RProtoBufUtils} package. Unlike Saptarshi's package, RProtoBufUtils depends on RProtoBuf for underlying message operations. This package is available at \url{https://github.com/jeroenooms/RProtoBufUtils}. @@ -505,8 +526,8 @@ \section{Summary} -Its pretty useful. Murray to see if he can get approval to talk a -tiny bit about how much its used at Google. +%Its pretty useful. Murray to see if he can get approval to talk a +%tiny bit about how much its used at Google. %This file is only a basic article template. For full details of \emph{The R Journal} style and information on how to prepare your article for submission, see the \href{http://journal.r-project.org/latex/RJauthorguide.pdf}{Instructions for Authors}. From noreply at r-forge.r-project.org Tue Dec 17 22:36:31 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 17 Dec 2013 22:36:31 +0100 (CET) Subject: [Rprotobuf-commits] r563 - papers/rjournal Message-ID: <20131217213631.9B9D11868DE@r-forge.r-project.org> Author: murray Date: 2013-12-17 22:36:31 +0100 (Tue, 17 Dec 2013) New Revision: 563 Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw Log: Add some new boilerplate for sections describing the basic abstractions and basic classes of RProtoBuf. Also, make the first example more concise by putting the example .proto file and example R session using it side by side (before we go into full detail about all the accessors in RProtoBuf, this just gives a preview) Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-17 06:48:50 UTC (rev 562) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-17 21:36:31 UTC (rev 563) @@ -118,31 +118,38 @@ The protocol buffer project page contains a comprehensive description of the language: \url{http://code.google.com/apis/protocolbuffers/docs/proto.html} +\noindent +\begin{tabular}{@{}p{.40\textwidth}|p{0.5\textwidth}@{}} +\begin{minipage}{.35\textwidth} \begin{example} package tutorial; message Person { required string name = 1; - required int32 id = 2; // Unique ID number for person. + required int32 id = 2; optional string email = 3; enum PhoneType { - MOBILE = 0; HOME = 1; WORK = 2; + MOBILE = 0; HOME = 1; + WORK = 2; } message PhoneNumber { required string number = 1; - optional PhoneType type = 2 [default = HOME]; + optional PhoneType type = 2; } repeated PhoneNumber phone = 4; } \end{example} - +\end{minipage} & \begin{minipage}{.45\textwidth} <>= library(RProtoBuf) -person <- new(tutorial.Person, id=1, name="Romain") -person$id +person <- new(tutorial.Person, id=1, + name="Romain") +person person$name person$name <- "Dirk" cat(as.character(person)) @ +\end{minipage} +\end{tabular} %This section may contain a figure such as Figure~\ref{figure:rlogo}. % @@ -167,13 +174,6 @@ binary \emph{payload} of the messages to files and arbitrary binary R connections. -\emph{TODO(mstokely): Remove this example code snippet} - -\begin{example} - x <- 1:10 - result <- myFunction(x) -\end{example} - \subsection{Importing proto files} In contrast to the other languages (Java, C++, Python) that are officially @@ -387,46 +387,55 @@ message <- tutorial.Person$read( payload ) @ -\section{Related work on IDLs (greatly expanded from what you have)} +\section{Basic Abstractions: Messages, Descriptors, and + DescriptorPools} -\section{Design tradeoffs: reflection vs proto compiler (not addressed - at all in current vignettes)} +The three basic abstractions of \CRANpkg{RProtoBuf} are Messages, +which encapsulate a data structure, Descriptors, which define the +schema used by one or more messages, and DescriptorPools, which +provide access to descriptors. -\subsection{Performance considerations} +\section{Under the hood: S4 Classes, Methods, and Pseudo Methods} -TODO RProtoBuf is quite flexible and easy to use for interactive -analysis, but it is not designed for certain classes of operations one -might like to do with protocol buffers. For example, taking a list of -10,000 protocol buffers, extracting a named field from each one, and -computing a aggregate statistics on those values would be extremely -slow with RProtoBuf, and while this is a useful class of operations, -it is outside of the scope of RProtoBuf. We should be very clear -about this to clarify the goals and strengths of RProtoBuf and its -reflection and object mapping. +The \CRANpkg{RProtoBuf} package uses the S4 system to store +information about descriptors and messages, but the information stored +in the R object is very minimal and mainly consists of an external +pointer to a C++ variable that is managed by the \texttt{protobuf} C++ +library. -\subsection{Serialization comparison} +Using the S4 system allows the \texttt{RProtoBuf} package to dispatch +methods that are not generic in the S3 sense, such as \texttt{new} and +\texttt{serialize}. -TODO comparison of protobuf serialization sizes/times for various vectors. Compared to R's native serialization. Discussion of the RHIPE approach of serializing any/all R objects, vs more specific protocol buffers for specific R objects. +The \texttt{RProtoBuf} package combines the \emph{R typical} dispatch +of the form \verb|method( object, arguments)| and the more traditional +object oriented notation \verb|object$method(arguments)|. +TODO(ms): Perhaps a table here of the different S4 classes, how many +methods they include, whether it dynamically does dispatch on other +strings, whether/how it is available in the search path, etc. -\section{Descriptor lookup} -\label{sec-lookup} +\subsection{Messages} -The \texttt{RProtoBuf} package uses the user defined tables framework -that is defined as part of the \texttt{RObjectTables} package available -from the OmegaHat project \citep{RObjectTables}. +The \texttt{Message} S4 class represents Protocol Buffer Messages and +is the core abstraction of \CRANpkg{RProtoBuf}. Each \texttt{Message} +has a \texttt{Descriptor} S4 class which defines the schema of the +data defined in the Message, as well as a number of +\texttt{FieldDescriptors} for the individual fields of the message. -The feature allows \texttt{RProtoBuf} to install the -special environment \emph{RProtoBuf:DescriptorPool} in the R search path. -The environment is special in that, instead of being associated with a -static hash table, it is dynamically queried by R as part of R's usual -variable lookup. In other words, it means that when the R interpreter -looks for a binding to a symbol (foo) in its search path, -it asks to our package if it knows the binding "foo", this is then -implemented by the \texttt{RProtoBuf} package by calling an internal -method of the \texttt{protobuf} C++ library. -\section{64-bit integer issues} + +represented in R using the \texttt{Message} +S4 class. The class contains the slots \texttt{pointer} and \texttt{type} as +described on the Table~\ref{Message-class-table}. + +\section{Type Coercion} + +\subsection{Booleans} +Bools +Int64s. + +\subsection{64-bit integers} \label{sec:int64} R does not have native 64-bit integer support. Instead, R treats @@ -487,6 +496,46 @@ options("RProtoBuf.int64AsString" = FALSE) @ + +\section{Related work on IDLs (greatly expanded from what you have)} + +\section{Design tradeoffs: reflection vs proto compiler (not addressed + at all in current vignettes)} + +\subsection{Performance considerations} + +TODO RProtoBuf is quite flexible and easy to use for interactive +analysis, but it is not designed for certain classes of operations one +might like to do with protocol buffers. For example, taking a list of +10,000 protocol buffers, extracting a named field from each one, and +computing a aggregate statistics on those values would be extremely +slow with RProtoBuf, and while this is a useful class of operations, +it is outside of the scope of RProtoBuf. We should be very clear +about this to clarify the goals and strengths of RProtoBuf and its +reflection and object mapping. + +\subsection{Serialization comparison} + +TODO comparison of protobuf serialization sizes/times for various vectors. Compared to R's native serialization. Discussion of the RHIPE approach of serializing any/all R objects, vs more specific protocol buffers for specific R objects. + + +\section{Descriptor lookup} +\label{sec-lookup} + +The \texttt{RProtoBuf} package uses the user defined tables framework +that is defined as part of the \texttt{RObjectTables} package available +from the OmegaHat project \citep{RObjectTables}. + +The feature allows \texttt{RProtoBuf} to install the +special environment \emph{RProtoBuf:DescriptorPool} in the R search path. +The environment is special in that, instead of being associated with a +static hash table, it is dynamically queried by R as part of R's usual +variable lookup. In other words, it means that when the R interpreter +looks for a binding to a symbol (foo) in its search path, +it asks to our package if it knows the binding "foo", this is then +implemented by the \texttt{RProtoBuf} package by calling an internal +method of the \texttt{protobuf} C++ library. + \section{Other approaches} Saptarshi Guha wrote another package that deals with integration From noreply at r-forge.r-project.org Wed Dec 18 03:51:38 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Dec 2013 03:51:38 +0100 (CET) Subject: [Rprotobuf-commits] r564 - papers/rjournal Message-ID: <20131218025138.DAF1A18613F@r-forge.r-project.org> Author: murray Date: 2013-12-18 03:51:36 +0100 (Wed, 18 Dec 2013) New Revision: 564 Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw Log: Improve typography of table 1, with the addressbook schema side by side with an example R session creating and manipulating a person object. Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-17 21:36:31 UTC (rev 563) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-18 02:51:36 UTC (rev 564) @@ -1,4 +1,13 @@ % !TeX root = RJwrapper.tex +% We don't want a left margin for Sinput or Soutput for our table 1. +%\DefineVerbatimEnvironment{Sinput}{Verbatim} {xleftmargin=0em} +%\DefineVerbatimEnvironment{Soutput}{Verbatim}{xleftmargin=0em} +%\DefineVerbatimEnvironment{Scode}{Verbatim}{xleftmargin=2em} +% Setting the topsep to 0 reduces spacing from input to output and +% improves table 1. +\fvset{listparameters={\setlength{\topsep}{0pt}}} +\renewenvironment{Schunk}{\vspace{\topsep}}{\vspace{\topsep}} + \title{RProtoBuf: Efficient Cross-Language Data Serialization in R} \author{by Dirk Eddelbuettel, Romain Fran\c{c}ois, and Murray Stokely} @@ -119,8 +128,13 @@ description of the language: \url{http://code.google.com/apis/protocolbuffers/docs/proto.html} \noindent -\begin{tabular}{@{}p{.40\textwidth}|p{0.5\textwidth}@{}} +\begin{table} +\begin{tabular}{@{\hskip .01\textwidth}p{.40\textwidth}@{\hskip .015\textwidth}|@{\hskip .015\textwidth}p{0.55\textwidth}@{\hskip .01\textwidth}} +\hline +Schema : \texttt{addressbook.proto} & Example R Session\\ +\hline \begin{minipage}{.35\textwidth} +\vspace{2mm} \begin{example} package tutorial; message Person { @@ -138,18 +152,25 @@ repeated PhoneNumber phone = 4; } \end{example} +\vspace{2mm} \end{minipage} & \begin{minipage}{.45\textwidth} <>= library(RProtoBuf) -person <- new(tutorial.Person, id=1, - name="Romain") +person <- new(tutorial.Person, id=1, name="Dirk") person person$name -person$name <- "Dirk" +person$name <- "Romain" cat(as.character(person)) +serialize(person, NULL) @ -\end{minipage} +\end{minipage} \\ +\hline \end{tabular} +\caption{The schema representation from a \texttt{.proto} file for the + \texttt{tutorial.Person} class (left) and simple R code for creating + an object of this class and accessing its fields (right).} +\label{tab:proto} +\end{table} %This section may contain a figure such as Figure~\ref{figure:rlogo}. % From noreply at r-forge.r-project.org Wed Dec 18 07:30:46 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Dec 2013 07:30:46 +0100 (CET) Subject: [Rprotobuf-commits] r565 - pkg/vignettes/RProtoBuf Message-ID: <20131218063046.360851868DC@r-forge.r-project.org> Author: murray Date: 2013-12-18 07:30:45 +0100 (Wed, 18 Dec 2013) New Revision: 565 Modified: pkg/vignettes/RProtoBuf/RProtoBuf.Rnw Log: Add missing as.list method to Table 2 and update the caption for this description of the methods of the Message S4 class. Modified: pkg/vignettes/RProtoBuf/RProtoBuf.Rnw =================================================================== --- pkg/vignettes/RProtoBuf/RProtoBuf.Rnw 2013-12-18 02:51:36 UTC (rev 564) +++ pkg/vignettes/RProtoBuf/RProtoBuf.Rnw 2013-12-18 06:30:45 UTC (rev 565) @@ -377,6 +377,8 @@ \texttt{str} & \ref{Message-method-str} & the R structure of the message\\ \texttt{as.character} & \ref{Message-method-ascharacter} & character representation of a message\\ \texttt{toString} & \ref{Message-method-toString} & character representation of a message (same as \texttt{as.character}) \\ +\texttt{as.list} & \ref{Message-method-aslist} & converts message to a +named R list\\ \texttt{update} & \ref{Message-method-update} & updates several fields of a message at once\\ \texttt{descriptor} & \ref{Message-method-descriptor} & get the descriptor of the message type of this message\\ \texttt{fileDescriptor} & \ref{Message-method-fileDescriptor} & get the file descriptor @@ -384,7 +386,7 @@ \hline \end{tabular} \end{small} -\caption{\label{Message-methods-table}Description of slots for the \texttt{Message} S4 class} +\caption{\label{Message-methods-table}Description of methods for the \texttt{Message} S4 class} \end{table} \subsubsection{Retrieve fields} From noreply at r-forge.r-project.org Wed Dec 18 08:02:52 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Dec 2013 08:02:52 +0100 (CET) Subject: [Rprotobuf-commits] r566 - in pkg: . R Message-ID: <20131218070253.03F811867E9@r-forge.r-project.org> Author: murray Date: 2013-12-18 08:02:51 +0100 (Wed, 18 Dec 2013) New Revision: 566 Modified: pkg/ChangeLog pkg/R/completion.R Log: Add missing 'fetch(' method to Dollar completion list for Messages. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-18 06:30:45 UTC (rev 565) +++ pkg/ChangeLog 2013-12-18 07:02:51 UTC (rev 566) @@ -1,3 +1,10 @@ +2013-12-17 Murray Stokely + + * R/completion.R (.DollarNames.Message): Add missing "fetch(" to + dollar completion list for Message objects. + * vignettes/RProtoBuf/RProtoBuf.Rnw (subsection{messages}): Minor + improvements, add a missing methods to Table 2. + 2013-12-16 Dirk Eddelbuettel * src/rprotobuf.h (RCPP_ENUM_TRAITS): Don't use extern "C" on Modified: pkg/R/completion.R =================================================================== --- pkg/R/completion.R 2013-12-18 06:30:45 UTC (rev 565) +++ pkg/R/completion.R 2013-12-18 07:02:51 UTC (rev 566) @@ -17,7 +17,7 @@ names <- c( .Call( "Message__fieldNames", x at pointer, PACKAGE = "RProtoBuf" ) , "has(", "clone()", "clone(", "isInitialized()", "serialize(", - "clear()", "clear(", "size(", "bytesize()", + "clear()", "clear(", "size(", "bytesize()", "fetch(", "swap(", "str()", "as.character()", "update(", "as.list()", "setExtension(", "getExtension(", "descriptor()", "set(", "toString(", "add(", "fileDescriptor()" ) From noreply at r-forge.r-project.org Wed Dec 18 08:53:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Dec 2013 08:53:35 +0100 (CET) Subject: [Rprotobuf-commits] r567 - papers/rjournal Message-ID: <20131218075335.E2D981867F8@r-forge.r-project.org> Author: murray Date: 2013-12-18 08:53:34 +0100 (Wed, 18 Dec 2013) New Revision: 567 Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw Log: Add basic tables of methods for Messages and Descriptors and improve the basic usage section. Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-18 07:02:51 UTC (rev 566) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-18 07:53:34 UTC (rev 567) @@ -40,6 +40,7 @@ file or sending them over the network. Programming langauges such as Java, Ruby, Python, and R include built-in serialization support, but these formats are tied to the specific programming language in use. +% TODO(ms): and they often don't support versioning among other faults. CSV files can be read and written by many applications and so are often used for exporting tabular data. However, CSV files have a number of disadvantages, such as a limitation of exporting only @@ -76,6 +77,8 @@ stored data when compared with simple ``schema-less'' binary interchange formats like BSON. +% TODO(ms) Also talk about versioning and why its useful. + %BSON, msgpack, Thrift, and Protocol Buffers take this latter approach, %with the @@ -124,9 +127,35 @@ languages to support protocol buffers is compiled as part of the project page: \url{http://code.google.com/p/protobuf/wiki/ThirdPartyAddOns} -The protocol buffer project page contains a comprehensive -description of the language: \url{http://code.google.com/apis/protocolbuffers/docs/proto.html} +\section{Basic Usage: Messages and Descriptors} +This section describes how to use the R API to create and manipulate +protocol buffer messages in R, and how to read and write the +binary \emph{payload} of the messages to files and arbitrary binary +R connections. + +The two fundamental building blocks of Protocol Buffers are Messages +and Descriptors. Messages provide a common abstract encapsulation of +structured data fields of the type specified in a Message Descriptor. +Message Descriptors are defined in \texttt{.proto} files and define a +schema for a particular named class of messages. This separation +between schema and the message objects is in contrast to +more verbose formats like JSON, and when combined with the efficient +binary representation of any Message object explains a large part of +the performance and storage-space advantage offered by Protocol +Buffers. TODO(ms): we already said some of this above. clean up. + +Table~\ref{tab:proto} shows an example \texttt{.proto} file which +defines the \texttt{tutorial.Person} type. The R code in the right +column shows an example of creating a new message of this type and +populating its fields. + +% lifted from protobuf page: +%With Protocol Buffers you define how you want your data to be +%structured once, and then you can read or write structured data to and +%from a variety of data streams using a variety of different +%languages. The definition + \noindent \begin{table} \begin{tabular}{@{\hskip .01\textwidth}p{.40\textwidth}@{\hskip .015\textwidth}|@{\hskip .015\textwidth}p{0.55\textwidth}@{\hskip .01\textwidth}} @@ -181,84 +210,57 @@ % \label{figure:rlogo} %\end{figure} -\section{Dynamic use: Protocol Buffers and R} +\subsection{Importing Message Descriptors from \texttt{.proto} files} -TODO(ms): random citations to work in: +%The three basic abstractions of \CRANpkg{RProtoBuf} are Messages, +%which encapsulate a data structure, Descriptors, which define the +%schema used by one or more messages, and DescriptorPools, which +%provide access to descriptors. +Before we can create a new Protocol Buffer Message or parse a +serialized stream of bytes as a Message, we must read in the message +type specification from a \texttt{.proto} file. -Many sources compare data serialization formats and show protocol -buffers very favorably to the alternatives, such -as \citep{Sumaray:2012:CDS:2184751.2184810} +New \texttt{.proto} files are imported with the \code{readProtoFiles} +function, which can import a single file, all files in a directory, or +all \texttt{.proto} files provided by another R package. -This section describes how to use the R API to create and manipulate -protocol buffer messages in R, and how to read and write the -binary \emph{payload} of the messages to files and arbitrary binary -R connections. +The \texttt{.proto} file syntax for defining the structure of protocol +buffer data is described comprehensively on Google Code: +\url{http://code.google.com/apis/protocolbuffers/docs/proto.html}. -\subsection{Importing proto files} - -In contrast to the other languages (Java, C++, Python) that are officially -supported by Google, the implementation used by the \texttt{RProtoBuf} -package does not rely on the \texttt{protoc} compiler (with the exception of -the two functions discussed in the previous section). This means that no -initial step of statically compiling the proto file into C++ code that is -then accessed by R code is necessary. Instead, \texttt{proto} files are -parsed and processed \textsl{at runtime} by the protobuf C++ library---which -is much more appropriate for a dynamic language. - -The \texttt{readProtoFiles} function allows importing \texttt{proto} -files in several ways. - -Using the \texttt{file} argument, one can specify one or several file -paths that ought to be proto files. - -<<>>= -proto.dir <- system.file( "proto", package = "RProtoBuf" ) -proto.file <- file.path( proto.dir, "addressbook.proto" ) -<>= -readProtoFiles( proto.file ) -@ - -With the \texttt{dir} argument, which is -ignored if the \texttt{file} is supplied, all files matching the -\texttt{.proto} extension will be imported. - -<<>>= -dir( proto.dir, pattern = "\\.proto$", full.names = TRUE ) -<>= -readProtoFiles( dir = proto.dir ) -@ - -Finally, with the -\texttt{package} argument (ignored if \texttt{file} or -\texttt{dir} is supplied), the function will import all \texttt{.proto} -files that are located in the \texttt{proto} sub-directory of the given -package. A typical use for this argument is in the \texttt{.onLoad} -function of a package. - -<>= -readProtoFiles( package = "RProtoBuf" ) -@ - Once the proto files are imported, all message descriptors are are available in the R search path in the \texttt{RProtoBuf:DescriptorPool} special environment. The underlying mechanism used here is -described in more detail in section~\ref{sec-lookup}. +described in more detail in Section~\ref{sec-lookup}. <<>>= ls( "RProtoBuf:DescriptorPool" ) @ +%\subsection{Importing proto files} +%In contrast to the other languages (Java, C++, Python) that are officially +%supported by Google, the implementation used by the \texttt{RProtoBuf} +%package does not rely on the \texttt{protoc} compiler (with the exception of +%the two functions discussed in the previous section). This means that no +%initial step of statically compiling the proto file into C++ code that is +%then accessed by R code is necessary. Instead, \texttt{proto} files are +%parsed and processed \textsl{at runtime} by the protobuf C++ library---which +%is much more appropriate for a dynamic language. \subsection{Creating a message} -The objects contained in the special environment are -descriptors for their associated message types. Descriptors will be -discussed in detail in another part of this document, but for the -purpose of this section, descriptors are just used with the \texttt{new} -function to create messages. +New messages are created with the \texttt{new} function which accepts +a Message Descriptor and optionally a list of ``name = value'' pairs +to set in the message. +%The objects contained in the special environment are +%descriptors for their associated message types. Descriptors will be +%discussed in detail in another part of this document, but for the +%purpose of this section, descriptors are just used with the \texttt{new} +%function to create messages. <<>>= +p1 <- new( tutorial.Person ) p <- new( tutorial.Person, name = "Romain", id = 1 ) @ @@ -315,8 +317,9 @@ However, the main focus of protocol buffer messages is efficiency. Therefore, messages are transported as a sequence of bytes. The \texttt{serialize} method is implemented for -protocol buffer messages to serialize a message into the sequence of -bytes (raw vector in R speech) that represents the message. +protocol buffer messages to serialize a message into a sequence of +bytes that represents the message. +%(raw vector in R speech) that represents the message. <<>>= serialize( p, NULL ) @@ -326,7 +329,6 @@ <<>>= tf1 <- tempfile() -tf1 serialize( p, tf1 ) readBin( tf1, raw(0), 500 ) @ @@ -356,23 +358,21 @@ \subsection{Parsing messages} -The \texttt{RProtoBuf} package defines the \texttt{read} -function to read messages from files, raw vector (the message payload) -and arbitrary binary connections. +The \texttt{RProtoBuf} package defines the \texttt{read} and +\texttt{readASCII} functions to read messages from files, raw vectors, +or arbitrary connections. \texttt{read} expects to read the message +payload from binary files or connections and \texttt{readASCII} parses +the human-readable ASCII output that is created with +\code{as.character}. -<<>>= -args( read ) -@ - - The binary representation of the message (often called the payload) does not contain information that can be used to dynamically infer the message type, so we have to provide this information to the \texttt{read} function in the form of a descriptor : <<>>= -message <- read( tutorial.Person, tf1 ) -writeLines( as.character( message ) ) +msg <- read( tutorial.Person, tf1 ) +writeLines( as.character( msg ) ) @ The \texttt{input} argument of \texttt{read} can also be a binary @@ -408,14 +408,7 @@ message <- tutorial.Person$read( payload ) @ -\section{Basic Abstractions: Messages, Descriptors, and - DescriptorPools} -The three basic abstractions of \CRANpkg{RProtoBuf} are Messages, -which encapsulate a data structure, Descriptors, which define the -schema used by one or more messages, and DescriptorPools, which -provide access to descriptors. - \section{Under the hood: S4 Classes, Methods, and Pseudo Methods} The \CRANpkg{RProtoBuf} package uses the S4 system to store @@ -445,11 +438,126 @@ \texttt{FieldDescriptors} for the individual fields of the message. - represented in R using the \texttt{Message} S4 class. The class contains the slots \texttt{pointer} and \texttt{type} as described on the Table~\ref{Message-class-table}. +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{l|l} +\textbf{Method} & \textbf{Description} \\ +\hline +\hline +\texttt{has} & Indicates if a message has a given field. \\ +\texttt{clone} & Creates a clone of the message \\ +\texttt{isInitialized} & Indicates if a message has all its required fields set\\ +\texttt{serialize} & serialize a message to a file, binary connection, or raw vector\\ +\texttt{clear} & Clear one or several fields of a message, or the entire message\\ +\texttt{size} & The number of elements in a message field\\ +\texttt{bytesize} & The number of bytes the message would take once serialized\\ +\hline +\texttt{swap} & swap elements of a repeated field of a message\\ +\texttt{set} & set elements of a repeated field\\ +\texttt{fetch} & fetch elements of a repeated field\\ +\texttt{setExtension} & set an extension of a message\\ +\texttt{getExtension} & get the value of an extension of a message\\ +\texttt{add} & add elements to a repeated field \\ +\hline +\texttt{str} & the R structure of the message\\ +\texttt{as.character} & character representation of a message\\ +\texttt{toString} & character representation of a message (same as \texttt{as.character}) \\ +\texttt{as.list} & converts message to a named R list\\ +\texttt{update} & updates several fields of a message at once\\ +\texttt{descriptor} & get the descriptor of the message type of this message\\ +\texttt{fileDescriptor} & get the file descriptor of this message's descriptor\\ +\hline +\end{tabular} +\end{small} +\caption{\label{Message-methods-table}Description of methods for the \texttt{Message} S4 class} +\end{table} + +\subsection{Descriptors} + +Message descriptors are represented in R with the +\emph{Descriptor} S4 class. The class contains +the slots \texttt{pointer} and \texttt{type} : + +\begin{table}[h] +\centering +\begin{tabular}{|cp{10cm}|} +\hline +\textbf{slot} & \textbf{description} \\ +\hline +\texttt{pointer} & external pointer to the \texttt{Descriptor} object of the C++ proto library. Documentation for the +\texttt{Descriptor} class is available from the protocol buffer project page: +\url{http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.descriptor.html#Descriptor} \\ +\hline +\texttt{type} & fully qualified path of the message type. \\ +\hline +\end{tabular} +\caption{\label{Descriptor-class-table}Description of slots for the \texttt{Descriptor} S4 class} +\end{table} + +Similarly to messages, the \verb|$| operator can be used to extract +information from the descriptor, or invoke pseuso-methods. + +\subsubsection{Extracting descriptors} + +The \verb|$| operator, when used on a descriptor object retrieves +descriptors that are contained in the descriptor. + +This can be a field descriptor (see section~\ref{subsec-field-descriptor} ), +an enum descriptor (see section~\ref{subsec-enum-descriptor}) or a descriptor +for a nested type + +<<>>= +# field descriptor +tutorial.Person$email + +# enum descriptor +tutorial.Person$PhoneType + +# nested type descriptor +tutorial.Person$PhoneNumber +# same as +tutorial.Person.PhoneNumber +@ + +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{l|l} +\textbf{Method} & \textbf{Description} \\ +\hline +\hline +\texttt{new} & Creates a prototype of a message described by this descriptor.\\ +\texttt{read} & Reads a message from a file or binary connection.\\ +\texttt{readASCII} & Read a message in ASCII format from a file or +text connection.\\ +\hline +\texttt{name} & Retrieve the name of the message type associated with +this descriptor.\\ +\texttt{as.character} & character representation of a descriptor\\ +\texttt{toString} & character representation of a descriptor (same as \texttt{as.character}) \\ +\hline +\texttt{fileDescriptor} & Retrieve the file descriptor of this +descriptor.\\ +\texttt{containing\_type} & Retrieve the descriptor describing the message type containing this descriptor.\\ +\texttt{field\_count} & Return the number of fields in this descriptor.\\ +\texttt{field} & Return the descriptor for the specified field in this descriptor.\\ +\texttt{nested\_type\_count} & The number of nested types in this descriptor.\\ +\texttt{nested\_type} & Return the descriptor for the specified nested +type in this descriptor.\\ +\texttt{enum\_type\_count} & The number of enum types in this descriptor.\\ +\texttt{enum\_type} & Return the descriptor for the specified enum +type in this descriptor.\\ +\hline +\end{tabular} +\end{small} +\caption{\label{Descriptor-methods-table}Description of methods for the \texttt{Descriptor} S4 class} +\end{table} + \section{Type Coercion} \subsection{Booleans} @@ -596,6 +704,12 @@ \section{Summary} +TODO(ms): random citations to work in: + +Many sources compare data serialization formats and show protocol +buffers very favorably to the alternatives, such +as \citep{Sumaray:2012:CDS:2184751.2184810} + %Its pretty useful. Murray to see if he can get approval to talk a %tiny bit about how much its used at Google. From noreply at r-forge.r-project.org Wed Dec 18 08:54:33 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Dec 2013 08:54:33 +0100 (CET) Subject: [Rprotobuf-commits] r568 - pkg/vignettes/RProtoBuf Message-ID: <20131218075433.CB760186814@r-forge.r-project.org> Author: murray Date: 2013-12-18 08:54:33 +0100 (Wed, 18 Dec 2013) New Revision: 568 Modified: pkg/vignettes/RProtoBuf/RProtoBuf.Rnw Log: Add a table of methods for the Descriptor class and add many subsubsections documenting and showing example usage of these methods which were previously not fully documented here. Modified: pkg/vignettes/RProtoBuf/RProtoBuf.Rnw =================================================================== --- pkg/vignettes/RProtoBuf/RProtoBuf.Rnw 2013-12-18 07:53:34 UTC (rev 567) +++ pkg/vignettes/RProtoBuf/RProtoBuf.Rnw 2013-12-18 07:54:33 UTC (rev 568) @@ -854,8 +854,45 @@ \end{table} Similarly to messages, the \verb|$| operator can be used to extract -information from the descriptor, or invoke pseuso-methods. +information from the descriptor, or invoke pseuso-methods. The +table~\ref{Descriptor-methods-table} describes the methods defined for the \texttt{Descriptor} class : +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{|ccp{8cm}|} +\hline +\textbf{Method} & \textbf{Section} & \textbf{Description} \\ +\hline +\hline +\texttt{new} & \ref{Descriptor-method-new} & Creates a prototype of a message described by this descriptor.\\ +\texttt{read} & \ref{Descriptor-method-read} & Reads a message from a file or binary connection.\\ +\texttt{readASCII} & \ref{Descriptor-method-readASCII} & Read a message in ASCII format from a file or +text connection.\\ +\hline +\texttt{name} & \ref{Descriptor-method-name} & Retrieve the name of the message type associated with +this descriptor.\\ +\texttt{as.character} & \ref{Descriptor-method-ascharacter} & character representation of a descriptor\\ +\texttt{toString} & \ref{Descriptor-method-tostring} & character representation of a descriptor (same as \texttt{as.character}) \\ +\hline +\texttt{fileDescriptor} & \ref{Descriptor-method-filedescriptor} & Retrieve the file descriptor of this +descriptor.\\ +\texttt{containing\_type} & \ref{Descriptor-method-containingtype} & Retrieve the descriptor describing the message type containing this descriptor.\\ +\texttt{field\_count} & \ref{Descriptor-method-fieldcount} & Return the number of fields in this descriptor.\\ +\texttt{field} & \ref{Descriptor-method-field} & Return the descriptor for the specified field in this descriptor.\\ +\texttt{nested\_type\_count} & \ref{Descriptor-method-nestedtypecount} +& The number of nested types in this descriptor.\\ +\texttt{nested\_type} & \ref{Descriptor-method-nestedtype} & Return the descriptor for the specified nested +type in this descriptor.\\ +\texttt{enum\_type\_count} & \ref{Descriptor-method-enumtypecount} & The number of enum types in this descriptor.\\ +\texttt{enum\_type} & \ref{Descriptor-method-enumtype} & Return the descriptor for the specified enum +type in this descriptor.\\ +\hline +\end{tabular} +\end{small} +\caption{\label{Descriptor-methods-table}Description of methods for the \texttt{Descriptor} S4 class} +\end{table} + \subsubsection{Extracting descriptors} The \verb|$| operator, when used on a descriptor object retrieves @@ -879,6 +916,7 @@ @ \subsubsection{The new method} +\label{Descriptor-method-new} The \texttt{new} method creates a prototype of a message described by the descriptor. @@ -899,6 +937,7 @@ @ \subsubsection{The read method} +\label{Descriptor-method-read} The \texttt{read} method is used to read a message from a file or a binary connection. @@ -919,11 +958,13 @@ @ \subsubsection{The toString method} +\label{Descriptor-method-tostring} \texttt{toString} currently is an alias to the \texttt{as.character} function. \subsubsection{The as.character method} +\label{Descriptor-method-ascharacter} \texttt{as.character} prints the text representation of the descriptor as it would be specified in the \texttt{.proto} file. @@ -936,6 +977,7 @@ @ \subsubsection{The fileDescriptor method} +\label{Descriptor-method-filedescriptor} The \texttt{fileDescriptor} method retrieves the file descriptor of the descriptor. See section~\ref{subsec-fileDescriptor} for more information @@ -948,6 +990,7 @@ @ \subsubsection{The name method} +\label{Descriptor-method-name} The \texttt{name} method can be used to retrieve the name of the message type associated with the descriptor. @@ -959,6 +1002,77 @@ tutorial.Person$name(full = TRUE) @ +\subsubsection{The containing\_type method} +\label{Descriptor-method-containingtype} + +The \texttt{containing\_type} method retrieves the descriptor +describing the message type containing this descriptor. + +<<>>= +tutorial.Person$containing_type() +tutorial.Person$PhoneNumber$containing_type() +@ + +\subsubsection{The field\_count method} +\label{Descriptor-method-fieldcount} + +Tme \texttt{field\_count} method retrieves the number of fields in +this descriptor. + +<<>>= +tutorial.Person$field_count() +@ + +\subsubsection{The field method} +\label{Descriptor-method-field} + +The \texttt{field} method returns the descriptor for the specified +field in this descriptor. + +<<>>= +tutorial.Person$field(1) +@ + +\subsubsection{The nested\_type\_count method} +\label{Descriptor-method-nestedtypecount} + +The \texttt{nested\_type\_count} method returns the number of nested +types in this descriptor. + +<<>>= +tutorial.Person$nested_type_count() +@ + +\subsubsection{The nested\_type method} +\label{Descriptor-method-nestedtype} + +The \texttt{nested\_type} method return the descriptor for the specified nested +type in this descriptor. + +<<>>= +tutorial.Person$nested_type(1) +@ + +\subsubsection{The enum\_type\_count method} +\label{Descriptor-method-enumtypecount} + +The \texttt{enum\_type\_count} method returns the number of enum types +in this descriptor. + +<<>>= +tutorial.Person$enum_type_count() +@ + +\subsubsection{The enum\_type method} +\label{Descriptor-method-enumtype} + +The \texttt{enum\_type} method returns the descriptor for the specified enum +type in this descriptor. + +<<>>= +tutorial.Person$enum_type(1) +@ + \subsection{field descriptors} \label{subsec-field-descriptor} From noreply at r-forge.r-project.org Wed Dec 18 08:57:01 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Dec 2013 08:57:01 +0100 (CET) Subject: [Rprotobuf-commits] r569 - in pkg: . R Message-ID: <20131218075701.5DFDD186975@r-forge.r-project.org> Author: murray Date: 2013-12-18 08:57:00 +0100 (Wed, 18 Dec 2013) New Revision: 569 Modified: pkg/ChangeLog pkg/R/completion.R Log: Add missing methods to Descriptor completion, and remove a duplicated item. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-18 07:54:33 UTC (rev 568) +++ pkg/ChangeLog 2013-12-18 07:57:00 UTC (rev 569) @@ -1,9 +1,10 @@ 2013-12-17 Murray Stokely - * R/completion.R (.DollarNames.Message): Add missing "fetch(" to - dollar completion list for Message objects. - * vignettes/RProtoBuf/RProtoBuf.Rnw (subsection{messages}): Minor - improvements, add a missing methods to Table 2. + * R/completion.R (.DollarNames.Message): Add missing methods to + dollar completion list for Message and Descriptor objects + * vignettes/RProtoBuf/RProtoBuf.Rnw (subsection{messages}): Add + missing methods to Table 2 (Messages) and add a table and new + sections of methods for Descriptor objects. 2013-12-16 Dirk Eddelbuettel Modified: pkg/R/completion.R =================================================================== --- pkg/R/completion.R 2013-12-18 07:54:33 UTC (rev 568) +++ pkg/R/completion.R 2013-12-18 07:57:00 UTC (rev 569) @@ -30,7 +30,8 @@ names <- c( .Call( "Descriptor__getMemberNames", x at pointer, PACKAGE = "RProtoBuf" ), - "new(", "read(", "readASCII(", "fileDescriptor()", "name(", "fileDescriptor()", + "new(", "read(", "readASCII(", "fileDescriptor()", "name(", + "toString()", "as.character()", "containing_type()", "field_count()", "nested_type_count()", "enum_type_count", "field(", "nested_type(", "enum_type(" ) grep( pattern, names, value = TRUE ) From noreply at r-forge.r-project.org Wed Dec 18 20:28:52 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Dec 2013 20:28:52 +0100 (CET) Subject: [Rprotobuf-commits] r570 - pkg/vignettes/RProtoBuf Message-ID: <20131218192852.B009D1862B6@r-forge.r-project.org> Author: murray Date: 2013-12-18 20:28:52 +0100 (Wed, 18 Dec 2013) New Revision: 570 Modified: pkg/vignettes/RProtoBuf/RProtoBuf.Rnw Log: Fix a typo and add a missing section about the readASCII method for descriptors. Modified: pkg/vignettes/RProtoBuf/RProtoBuf.Rnw =================================================================== --- pkg/vignettes/RProtoBuf/RProtoBuf.Rnw 2013-12-18 07:57:00 UTC (rev 569) +++ pkg/vignettes/RProtoBuf/RProtoBuf.Rnw 2013-12-18 19:28:52 UTC (rev 570) @@ -318,14 +318,14 @@ and \texttt{serialize}. The \texttt{RProtoBuf} package combines the \emph{R typical} dispatch -of the form \verb|method( object, arguments)| and the more traditionnal +of the form \verb|method( object, arguments)| and the more traditional object oriented notation \verb|object$method(arguments)|. \subsection{messages} Messages are represented in R using the \texttt{Message} S4 class. The class contains the slots \texttt{pointer} and \texttt{type} as -described on the table~\ref{Message-class-table} : +described on the Table~\ref{Message-class-table}. \begin{table}[h] \centering @@ -854,8 +854,8 @@ \end{table} Similarly to messages, the \verb|$| operator can be used to extract -information from the descriptor, or invoke pseuso-methods. The -table~\ref{Descriptor-methods-table} describes the methods defined for the \texttt{Descriptor} class : +information from the descriptor, or invoke pseuso-methods. +Table~\ref{Descriptor-methods-table} describes the methods defined for the \texttt{Descriptor} class : \begin{table}[h] \centering @@ -957,6 +957,21 @@ writeLines( as.character( m ) ) @ + +\subsubsection{The readASCII method} +\label{Descriptor-method-readASCII} + +The \texttt{readASCII} method is used to read a message +from a text file or a character vector. + +<<>>= +# start by generating the ASCII representation of a message +text <- as.character(new(tutorial.Person, id=1, name="Murray")) +text +# Then read the ascii representation in as a new message object. +msg <- tutorial.Person$readASCII(text) +@ + \subsubsection{The toString method} \label{Descriptor-method-tostring} From noreply at r-forge.r-project.org Wed Dec 18 21:43:26 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Wed, 18 Dec 2013 21:43:26 +0100 (CET) Subject: [Rprotobuf-commits] r571 - pkg/vignettes/RProtoBuf Message-ID: <20131218204326.7BB19185F37@r-forge.r-project.org> Author: murray Date: 2013-12-18 21:43:26 +0100 (Wed, 18 Dec 2013) New Revision: 571 Modified: pkg/vignettes/RProtoBuf/RProtoBuf.Rnw Log: This vignette is 34 pages now, add a table of contents to make the organization clearer. (tocdepth=2 to just pull in subsections, not subsubsections). Modified: pkg/vignettes/RProtoBuf/RProtoBuf.Rnw =================================================================== --- pkg/vignettes/RProtoBuf/RProtoBuf.Rnw 2013-12-18 19:28:52 UTC (rev 570) +++ pkg/vignettes/RProtoBuf/RProtoBuf.Rnw 2013-12-18 20:43:26 UTC (rev 571) @@ -5,7 +5,7 @@ \usepackage[colorlinks]{hyperref} \setlength{\oddsidemargin}{0pt} \setlength{\textwidth}{17cm} % uh-oh, I use letter :) - +\setcounter{tocdepth}{2} <>= library( "RProtoBuf" ) options("width"=65) @@ -35,6 +35,8 @@ } +\tableofcontents + \section{Protocol Buffers} Protocol buffers are a language-neutral, platform-neutral, extensible From noreply at r-forge.r-project.org Thu Dec 19 02:23:37 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 02:23:37 +0100 (CET) Subject: [Rprotobuf-commits] r572 - in pkg: . inst vignettes vignettes/inactive Message-ID: <20131219012337.9D1401862F7@r-forge.r-project.org> Author: edd Date: 2013-12-19 02:23:37 +0100 (Thu, 19 Dec 2013) New Revision: 572 Added: pkg/vignettes/RProtoBuf-intro.Rnw pkg/vignettes/RProtoBuf-quickref.Rnw pkg/vignettes/inactive/ pkg/vignettes/inactive/Makefile.in pkg/vignettes/inactive/static-use.Rnw Removed: pkg/vignettes/Makefile.in pkg/vignettes/RProtoBuf-quickref/ pkg/vignettes/RProtoBuf/ Modified: pkg/ChangeLog pkg/DESCRIPTION pkg/cleanup pkg/configure pkg/configure.in pkg/inst/NEWS.Rd Log: vignettes are now being built by R using the external vignette builder Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-18 20:43:26 UTC (rev 571) +++ pkg/ChangeLog 2013-12-19 01:23:37 UTC (rev 572) @@ -1,3 +1,11 @@ +2013-12-18 Dirk Eddelbuettel + + * vignettes/RProtoBuf-intro.Rnw: Use with vignette builder + * vignettes/RProtoBuf-quickref.Rnw: Idem + * DESCRIPTION: Increased dependency to R (>= 3.0.0) + + * configure.in: No longer create vignettes/Makefile + 2013-12-17 Murray Stokely * R/completion.R (.DollarNames.Message): Add missing methods to Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-12-18 20:43:26 UTC (rev 571) +++ pkg/DESCRIPTION 2013-12-19 01:23:37 UTC (rev 572) @@ -1,5 +1,5 @@ Package: RProtoBuf -Version: 0.3.2.1 +Version: 0.3.2.2 Date: $Date$ Author: Romain Francois, Dirk Eddelbuettel and Murray Stokely Maintainer: Dirk Eddelbuettel @@ -7,9 +7,10 @@ Description: Protocol Buffers are a way of encoding structured data in an efficient yet extensible format. Google uses Protocol Buffers for almost all of its internal RPC protocols and file formats. -Depends: R (>= 2.11), methods +Depends: R (>= 3.0.0), methods LinkingTo: Rcpp Suggests: RUnit, highlight, Rcpp +VignetteBuilder: highlight Imports: utils, stats, tools, RCurl SystemRequirements: Protocol Buffer compiler (to create C++ header and source files from .proto descriptions) and library (version 2.2.0 or later) Modified: pkg/cleanup =================================================================== --- pkg/cleanup 2013-12-18 20:43:26 UTC (rev 571) +++ pkg/cleanup 2013-12-19 01:23:37 UTC (rev 572) @@ -4,12 +4,9 @@ src/addressbook.pb.cc src/addressbook.pb.h \ src/protobufrpc.pb.cc src/protobufrpc.pb.h \ src/*.o src/*.d src/*.a src/*.dll src/*.so src/*.rc */*~ *~ \ - src/symbols.rds \ - inst/doc/RProtoBuf*.aux inst/doc/RProtoBuf*.log \ - inst/doc/RProtoBuf*.out inst/doc/RProtoBuf*.toc + src/symbols.rds rm -rf inst/doc/auto -[ -d vignettes ] && ( cd vignettes && make clean ) +( cd vignettes; rm -f RProtoBuf*.aux RProtoBuf*.log \ + RProtoBuf*.out RProtoBuf*.toc ) -[ -d inst/examples/HighFrequencyFinance ] && \ - ( cd inst/examples/HighFrequencyFinance && make clean ) Modified: pkg/configure =================================================================== --- pkg/configure 2013-12-18 20:43:26 UTC (rev 571) +++ pkg/configure 2013-12-19 01:23:37 UTC (rev 572) @@ -1,11 +1,11 @@ #! /bin/sh # Guess values for system-dependent variables and create Makefiles. -# Generated by GNU Autoconf 2.64 for RProtoBuf 0.3. +# Generated by GNU Autoconf 2.69 for RProtoBuf 0.3. # -# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001, -# 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software -# Foundation, Inc. # +# Copyright (C) 1992-1996, 1998-2012 Free Software Foundation, Inc. +# +# # This configure script is free software; the Free Software Foundation # gives unlimited permission to copy, distribute and modify it. ## -------------------- ## @@ -87,6 +87,7 @@ IFS=" "" $as_nl" # Find who we are. Look in the path if we contain no directory separator. +as_myself= case $0 in #(( *[\\/]* ) as_myself=$0 ;; *) as_save_IFS=$IFS; IFS=$PATH_SEPARATOR @@ -131,6 +132,31 @@ # CDPATH. (unset CDPATH) >/dev/null 2>&1 && unset CDPATH +# Use a proper internal environment variable to ensure we don't fall + # into an infinite loop, continuously re-executing ourselves. + if test x"${_as_can_reexec}" != xno && test "x$CONFIG_SHELL" != x; then + _as_can_reexec=no; export _as_can_reexec; + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +as_fn_exit 255 + fi + # We don't want this to propagate to other subprocesses. + { _as_can_reexec=; unset _as_can_reexec;} if test "x$CONFIG_SHELL" = x; then as_bourne_compatible="if test -n \"\${ZSH_VERSION+set}\" && (emulate sh) >/dev/null 2>&1; then : emulate sh @@ -164,7 +190,8 @@ else exitcode=1; echo positional parameters were not saved. fi -test x\$exitcode = x0 || exit 1" +test x\$exitcode = x0 || exit 1 +test -x / || exit 1" as_suggested=" as_lineno_1=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_1a=\$LINENO as_lineno_2=";as_suggested=$as_suggested$LINENO;as_suggested=$as_suggested" as_lineno_2a=\$LINENO eval 'test \"x\$as_lineno_1'\$as_run'\" != \"x\$as_lineno_2'\$as_run'\" && @@ -209,14 +236,25 @@ if test "x$CONFIG_SHELL" != x; then : - # We cannot yet assume a decent shell, so we have to provide a - # neutralization value for shells without unset; and this also - # works around shells that cannot unset nonexistent variables. - BASH_ENV=/dev/null - ENV=/dev/null - (unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV - export CONFIG_SHELL - exec "$CONFIG_SHELL" "$as_myself" ${1+"$@"} + export CONFIG_SHELL + # We cannot yet assume a decent shell, so we have to provide a +# neutralization value for shells without unset; and this also +# works around shells that cannot unset nonexistent variables. +# Preserve -v and -x to the replacement shell. +BASH_ENV=/dev/null +ENV=/dev/null +(unset BASH_ENV) >/dev/null 2>&1 && unset BASH_ENV ENV +case $- in # (((( + *v*x* | *x*v* ) as_opts=-vx ;; + *v* ) as_opts=-v ;; + *x* ) as_opts=-x ;; + * ) as_opts= ;; +esac +exec $CONFIG_SHELL $as_opts "$as_myself" ${1+"$@"} +# Admittedly, this is quite paranoid, since all the known shells bail +# out after a failed `exec'. +$as_echo "$0: could not re-execute with $CONFIG_SHELL" >&2 +exit 255 fi if test x$as_have_required = xno; then : @@ -314,10 +352,18 @@ test -d "$as_dir" && break done test -z "$as_dirs" || eval "mkdir $as_dirs" - } || test -d "$as_dir" || as_fn_error "cannot create directory $as_dir" + } || test -d "$as_dir" || as_fn_error $? "cannot create directory $as_dir" } # as_fn_mkdir_p + +# as_fn_executable_p FILE +# ----------------------- +# Test if FILE is an executable regular file. +as_fn_executable_p () +{ + test -f "$1" && test -x "$1" +} # as_fn_executable_p # as_fn_append VAR VALUE # ---------------------- # Append the text in VALUE to the end of the definition contained in VAR. Take @@ -354,19 +400,19 @@ fi # as_fn_arith -# as_fn_error ERROR [LINENO LOG_FD] -# --------------------------------- +# as_fn_error STATUS ERROR [LINENO LOG_FD] +# ---------------------------------------- # Output "`basename $0`: error: ERROR" to stderr. If LINENO and LOG_FD are # provided, also output the error to LOG_FD, referencing LINENO. Then exit the -# script with status $?, using 1 if that was 0. +# script with STATUS, using 1 if that was 0. as_fn_error () { - as_status=$?; test $as_status -eq 0 && as_status=1 - if test "$3"; then - as_lineno=${as_lineno-"$2"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - $as_echo "$as_me:${as_lineno-$LINENO}: error: $1" >&$3 + as_status=$1; test $as_status -eq 0 && as_status=1 + if test "$4"; then + as_lineno=${as_lineno-"$3"} as_lineno_stack=as_lineno_stack=$as_lineno_stack + $as_echo "$as_me:${as_lineno-$LINENO}: error: $2" >&$4 fi - $as_echo "$as_me: error: $1" >&2 + $as_echo "$as_me: error: $2" >&2 as_fn_exit $as_status } # as_fn_error @@ -439,6 +485,10 @@ chmod +x "$as_me.lineno" || { $as_echo "$as_me: error: cannot create $as_me.lineno; rerun with a POSIX shell" >&2; as_fn_exit 1; } + # If we had to re-execute with $CONFIG_SHELL, we're ensured to have + # already done that, so ensure we don't try to do so again and fall + # in an infinite loop. This has already happened in practice. + _as_can_reexec=no; export _as_can_reexec # Don't try to exec as it changes $[0], causing all sort of problems # (the dirname of $[0] is not the place where we might find the # original and so on. Autoconf is especially sensitive to this). @@ -473,16 +523,16 @@ # ... but there are two gotchas: # 1) On MSYS, both `ln -s file dir' and `ln file dir' fail. # 2) DJGPP < 2.04 has no symlinks; `ln -s' creates a wrapper executable. - # In both cases, we have to default to `cp -p'. + # In both cases, we have to default to `cp -pR'. ln -s conf$$.file conf$$.dir 2>/dev/null && test ! -f conf$$.exe || - as_ln_s='cp -p' + as_ln_s='cp -pR' elif ln conf$$.file conf$$ 2>/dev/null; then as_ln_s=ln else - as_ln_s='cp -p' + as_ln_s='cp -pR' fi else - as_ln_s='cp -p' + as_ln_s='cp -pR' fi rm -f conf$$ conf$$.exe conf$$.dir/conf$$.file conf$$.file rmdir conf$$.dir 2>/dev/null @@ -494,28 +544,8 @@ as_mkdir_p=false fi -if test -x / >/dev/null 2>&1; then - as_test_x='test -x' -else - if ls -dL / >/dev/null 2>&1; then - as_ls_L_option=L - else - as_ls_L_option= - fi - as_test_x=' - eval sh -c '\'' - if test -d "$1"; then - test -d "$1/."; - else - case $1 in #( - -*)set "./$1";; - esac; - case `ls -ld'$as_ls_L_option' "$1" 2>/dev/null` in #(( - ???[sx]*):;;*)false;;esac;fi - '\'' sh - ' -fi -as_executable_p=$as_test_x +as_test_x='test -x' +as_executable_p=as_fn_executable_p # Sed expression to map a string onto a valid CPP name. as_tr_cpp="eval sed 'y%*$as_cr_letters%P$as_cr_LETTERS%;s%[^_$as_cr_alnum]%_%g'" @@ -524,10 +554,11 @@ as_tr_sh="eval sed 'y%*+%pp%;s%[^_$as_cr_alnum]%_%g'" -exec 7<&0 &1 +test -n "$DJDIR" || exec 7<&0 &1 # Name of the host. -# hostname on some systems (SVR3.2, Linux) returns a bogus exit status, +# hostname on some systems (SVR3.2, old GNU/Linux) returns a bogus exit status, # so uname gets run too. ac_hostname=`(hostname || uname -n) 2>/dev/null | sed 1q` @@ -725,8 +756,9 @@ fi case $ac_option in - *=*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; - *) ac_optarg=yes ;; + *=?*) ac_optarg=`expr "X$ac_option" : '[^=]*=\(.*\)'` ;; + *=) ac_optarg= ;; + *) ac_optarg=yes ;; esac # Accept the important Cygnus configure options, so we can diagnose typos. @@ -771,7 +803,7 @@ ac_useropt=`expr "x$ac_option" : 'x-*disable-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error "invalid feature name: $ac_useropt" + as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in @@ -797,7 +829,7 @@ ac_useropt=`expr "x$ac_option" : 'x-*enable-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error "invalid feature name: $ac_useropt" + as_fn_error $? "invalid feature name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in @@ -1001,7 +1033,7 @@ ac_useropt=`expr "x$ac_option" : 'x-*with-\([^=]*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error "invalid package name: $ac_useropt" + as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in @@ -1017,7 +1049,7 @@ ac_useropt=`expr "x$ac_option" : 'x-*without-\(.*\)'` # Reject names that are not valid shell variable names. expr "x$ac_useropt" : ".*[^-+._$as_cr_alnum]" >/dev/null && - as_fn_error "invalid package name: $ac_useropt" + as_fn_error $? "invalid package name: $ac_useropt" ac_useropt_orig=$ac_useropt ac_useropt=`$as_echo "$ac_useropt" | sed 's/[-+.]/_/g'` case $ac_user_opts in @@ -1047,8 +1079,8 @@ | --x-librar=* | --x-libra=* | --x-libr=* | --x-lib=* | --x-li=* | --x-l=*) x_libraries=$ac_optarg ;; - -*) as_fn_error "unrecognized option: \`$ac_option' -Try \`$0 --help' for more information." + -*) as_fn_error $? "unrecognized option: \`$ac_option' +Try \`$0 --help' for more information" ;; *=*) @@ -1056,7 +1088,7 @@ # Reject names that are not valid shell variable names. case $ac_envvar in #( '' | [0-9]* | *[!_$as_cr_alnum]* ) - as_fn_error "invalid variable name: \`$ac_envvar'" ;; + as_fn_error $? "invalid variable name: \`$ac_envvar'" ;; esac eval $ac_envvar=\$ac_optarg export $ac_envvar ;; @@ -1066,7 +1098,7 @@ $as_echo "$as_me: WARNING: you should use --build, --host, --target" >&2 expr "x$ac_option" : ".*[^-._$as_cr_alnum]" >/dev/null && $as_echo "$as_me: WARNING: invalid host type: $ac_option" >&2 - : ${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option} + : "${build_alias=$ac_option} ${host_alias=$ac_option} ${target_alias=$ac_option}" ;; esac @@ -1074,13 +1106,13 @@ if test -n "$ac_prev"; then ac_option=--`echo $ac_prev | sed 's/_/-/g'` - as_fn_error "missing argument to $ac_option" + as_fn_error $? "missing argument to $ac_option" fi if test -n "$ac_unrecognized_opts"; then case $enable_option_checking in no) ;; - fatal) as_fn_error "unrecognized options: $ac_unrecognized_opts" ;; + fatal) as_fn_error $? "unrecognized options: $ac_unrecognized_opts" ;; *) $as_echo "$as_me: WARNING: unrecognized options: $ac_unrecognized_opts" >&2 ;; esac fi @@ -1103,7 +1135,7 @@ [\\/$]* | ?:[\\/]* ) continue;; NONE | '' ) case $ac_var in *prefix ) continue;; esac;; esac - as_fn_error "expected an absolute directory name for --$ac_var: $ac_val" + as_fn_error $? "expected an absolute directory name for --$ac_var: $ac_val" done # There might be people who depend on the old broken behavior: `$host' @@ -1117,8 +1149,6 @@ if test "x$host_alias" != x; then if test "x$build_alias" = x; then cross_compiling=maybe - $as_echo "$as_me: WARNING: If you wanted to set the --build type, don't use --host. - If a cross compiler is detected then cross compile mode will be used." >&2 elif test "x$build_alias" != "x$host_alias"; then cross_compiling=yes fi @@ -1133,9 +1163,9 @@ ac_pwd=`pwd` && test -n "$ac_pwd" && ac_ls_di=`ls -di .` && ac_pwd_ls_di=`cd "$ac_pwd" && ls -di .` || - as_fn_error "working directory cannot be determined" + as_fn_error $? "working directory cannot be determined" test "X$ac_ls_di" = "X$ac_pwd_ls_di" || - as_fn_error "pwd does not report name of working directory" + as_fn_error $? "pwd does not report name of working directory" # Find the source files, if location was not specified. @@ -1174,11 +1204,11 @@ fi if test ! -r "$srcdir/$ac_unique_file"; then test "$ac_srcdir_defaulted" = yes && srcdir="$ac_confdir or .." - as_fn_error "cannot find sources ($ac_unique_file) in $srcdir" + as_fn_error $? "cannot find sources ($ac_unique_file) in $srcdir" fi ac_msg="sources are in $srcdir, but \`cd $srcdir' does not work" ac_abs_confdir=`( - cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error "$ac_msg" + cd "$srcdir" && test -r "./$ac_unique_file" || as_fn_error $? "$ac_msg" pwd)` # When building in place, set srcdir=. if test "$ac_abs_confdir" = "$ac_pwd"; then @@ -1218,7 +1248,7 @@ --help=short display options specific to this package --help=recursive display the short help of all the included packages -V, --version display version information and exit - -q, --quiet, --silent do not print \`checking...' messages + -q, --quiet, --silent do not print \`checking ...' messages --cache-file=FILE cache test results in FILE [disabled] -C, --config-cache alias for \`--cache-file=config.cache' -n, --no-create do not create output files @@ -1275,7 +1305,7 @@ LDFLAGS linker flags, e.g. -L if you have libraries in a nonstandard directory LIBS libraries to pass to the linker, e.g. -l - CPPFLAGS C/C++/Objective C preprocessor flags, e.g. -I if + CPPFLAGS (Objective) C/C++ preprocessor flags, e.g. -I if you have headers in a nonstandard directory CXXCPP C++ preprocessor CC C compiler command @@ -1348,9 +1378,9 @@ if $ac_init_version; then cat <<\_ACEOF RProtoBuf configure 0.3 -generated by GNU Autoconf 2.64 +generated by GNU Autoconf 2.69 -Copyright (C) 2009 Free Software Foundation, Inc. +Copyright (C) 2012 Free Software Foundation, Inc. This configure script is free software; the Free Software Foundation gives unlimited permission to copy, distribute and modify it. _ACEOF @@ -1394,8 +1424,8 @@ ac_retval=1 fi - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} - return $ac_retval + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval } # ac_fn_cxx_try_compile @@ -1420,7 +1450,7 @@ mv -f conftest.er1 conftest.err fi $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; } >/dev/null && { + test $ac_status = 0; } > conftest.i && { test -z "$ac_cxx_preproc_warn_flag$ac_cxx_werror_flag" || test ! -s conftest.err }; then : @@ -1431,8 +1461,8 @@ ac_retval=1 fi - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} - return $ac_retval + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval } # ac_fn_cxx_try_cpp @@ -1469,8 +1499,8 @@ ac_retval=1 fi - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} - return $ac_retval + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval } # ac_fn_c_try_compile @@ -1482,10 +1512,10 @@ ac_fn_cxx_check_header_mongrel () { as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack - if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : + if eval \${$3+:} false; then : { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } -if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : +if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 fi eval ac_res=\$$3 @@ -1521,7 +1551,7 @@ else ac_header_preproc=no fi -rm -f conftest.err conftest.$ac_ext +rm -f conftest.err conftest.i conftest.$ac_ext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_header_preproc" >&5 $as_echo "$ac_header_preproc" >&6; } @@ -1548,7 +1578,7 @@ esac { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } -if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : +if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else eval "$3=\$ac_header_compiler" @@ -1557,7 +1587,7 @@ { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } fi - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_cxx_check_header_mongrel @@ -1598,8 +1628,8 @@ ac_retval=$ac_status fi rm -rf conftest.dSYM conftest_ipa8_conftest.oo - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} - return $ac_retval + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno + as_fn_set_status $ac_retval } # ac_fn_cxx_try_run @@ -1612,7 +1642,7 @@ as_lineno=${as_lineno-"$1"} as_lineno_stack=as_lineno_stack=$as_lineno_stack { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $2" >&5 $as_echo_n "checking for $2... " >&6; } -if { as_var=$3; eval "test \"\${$as_var+set}\" = set"; }; then : +if eval \${$3+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -1630,7 +1660,7 @@ eval ac_res=\$$3 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_res" >&5 $as_echo "$ac_res" >&6; } - eval $as_lineno_stack; test "x$as_lineno_stack" = x && { as_lineno=; unset as_lineno;} + eval $as_lineno_stack; ${as_lineno_stack:+:} unset as_lineno } # ac_fn_cxx_check_header_compile cat >config.log <<_ACEOF @@ -1638,7 +1668,7 @@ running configure, to aid debugging if configure makes a mistake. It was created by RProtoBuf $as_me 0.3, which was -generated by GNU Autoconf 2.64. Invocation command line was +generated by GNU Autoconf 2.69. Invocation command line was $ $0 $@ @@ -1748,11 +1778,9 @@ { echo - cat <<\_ASBOX -## ---------------- ## + $as_echo "## ---------------- ## ## Cache variables. ## -## ---------------- ## -_ASBOX +## ---------------- ##" echo # The following way of writing the cache mishandles newlines in values, ( @@ -1786,11 +1814,9 @@ ) echo - cat <<\_ASBOX -## ----------------- ## + $as_echo "## ----------------- ## ## Output variables. ## -## ----------------- ## -_ASBOX +## ----------------- ##" echo for ac_var in $ac_subst_vars do @@ -1803,11 +1829,9 @@ echo if test -n "$ac_subst_files"; then - cat <<\_ASBOX -## ------------------- ## + $as_echo "## ------------------- ## ## File substitutions. ## -## ------------------- ## -_ASBOX +## ------------------- ##" echo for ac_var in $ac_subst_files do @@ -1821,11 +1845,9 @@ fi if test -s confdefs.h; then - cat <<\_ASBOX -## ----------- ## + $as_echo "## ----------- ## ## confdefs.h. ## -## ----------- ## -_ASBOX +## ----------- ##" echo cat confdefs.h echo @@ -1880,7 +1902,12 @@ ac_site_file1=NONE ac_site_file2=NONE if test -n "$CONFIG_SITE"; then - ac_site_file1=$CONFIG_SITE + # We do not want a PATH search for config.site. + case $CONFIG_SITE in #(( + -*) ac_site_file1=./$CONFIG_SITE;; + */*) ac_site_file1=$CONFIG_SITE;; + *) ac_site_file1=./$CONFIG_SITE;; + esac elif test "x$prefix" != xNONE; then ac_site_file1=$prefix/share/config.site ac_site_file2=$prefix/etc/config.site @@ -1891,18 +1918,22 @@ for ac_site_file in "$ac_site_file1" "$ac_site_file2" do test "x$ac_site_file" = xNONE && continue - if test -r "$ac_site_file"; then + if test /dev/null != "$ac_site_file" && test -r "$ac_site_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading site script $ac_site_file" >&5 $as_echo "$as_me: loading site script $ac_site_file" >&6;} sed 's/^/| /' "$ac_site_file" >&5 - . "$ac_site_file" + . "$ac_site_file" \ + || { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "failed to load site script $ac_site_file +See \`config.log' for more details" "$LINENO" 5; } fi done if test -r "$cache_file"; then - # Some versions of bash will fail to source /dev/null (special - # files actually), so we avoid doing that. - if test -f "$cache_file"; then + # Some versions of bash will fail to source /dev/null (special files + # actually), so we avoid doing that. DJGPP emulates it as a regular file. + if test /dev/null != "$cache_file" && test -f "$cache_file"; then { $as_echo "$as_me:${as_lineno-$LINENO}: loading cache $cache_file" >&5 $as_echo "$as_me: loading cache $cache_file" >&6;} case $cache_file in @@ -1971,7 +2002,7 @@ $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} { $as_echo "$as_me:${as_lineno-$LINENO}: error: changes in the environment can compromise the build" >&5 $as_echo "$as_me: error: changes in the environment can compromise the build" >&2;} - as_fn_error "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 + as_fn_error $? "run \`make distclean' and/or \`rm $cache_file' and start over" "$LINENO" 5 fi ## -------------------- ## ## Main body of script. ## @@ -2053,7 +2084,7 @@ set dummy $ac_tool_prefix$ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_CXX+set}" = set; then : +if ${ac_cv_prog_CXX+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$CXX"; then @@ -2065,7 +2096,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_CXX="$ac_tool_prefix$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2097,7 +2128,7 @@ set dummy $ac_prog; ac_word=$2 { $as_echo "$as_me:${as_lineno-$LINENO}: checking for $ac_word" >&5 $as_echo_n "checking for $ac_word... " >&6; } -if test "${ac_cv_prog_ac_ct_CXX+set}" = set; then : +if ${ac_cv_prog_ac_ct_CXX+:} false; then : $as_echo_n "(cached) " >&6 else if test -n "$ac_ct_CXX"; then @@ -2109,7 +2140,7 @@ IFS=$as_save_IFS test -z "$as_dir" && as_dir=. for ac_exec_ext in '' $ac_executable_extensions; do - if { test -f "$as_dir/$ac_word$ac_exec_ext" && $as_test_x "$as_dir/$ac_word$ac_exec_ext"; }; then + if as_fn_executable_p "$as_dir/$ac_word$ac_exec_ext"; then ac_cv_prog_ac_ct_CXX="$ac_prog" $as_echo "$as_me:${as_lineno-$LINENO}: found $as_dir/$ac_word$ac_exec_ext" >&5 break 2 @@ -2167,32 +2198,30 @@ ... rest of stderr output deleted ... 10q' conftest.err >conftest.er1 cat conftest.er1 >&5 - rm -f conftest.er1 conftest.err fi + rm -f conftest.er1 conftest.err $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 test $ac_status = 0; } done cat confdefs.h - <<_ACEOF >conftest.$ac_ext /* end confdefs.h. */ -#include + int main () { -FILE *f = fopen ("conftest.out", "w"); - return ferror (f) || fclose (f) != 0; ; return 0; } _ACEOF ac_clean_files_save=$ac_clean_files -ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out conftest.out" +ac_clean_files="$ac_clean_files a.out a.out.dSYM a.exe b.out" # Try to create an executable without -o first, disregard a.out. # It will help us diagnose broken compilers, and finding out an intuition # of exeext. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler default output file name" >&5 -$as_echo_n "checking for C++ compiler default output file name... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C++ compiler works" >&5 +$as_echo_n "checking whether the C++ compiler works... " >&6; } ac_link_default=`$as_echo "$ac_link" | sed 's/ -o *conftest[^ ]*//'` # The possible output files: @@ -2254,62 +2283,28 @@ else ac_file='' fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 -$as_echo "$ac_file" >&6; } if test -z "$ac_file"; then : - $as_echo "$as_me: failed program was:" >&5 + { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5 +$as_echo "no" >&6; } +$as_echo "$as_me: failed program was:" >&5 sed 's/^/| /' conftest.$ac_ext >&5 { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -{ as_fn_set_status 77 -as_fn_error "C++ compiler cannot create executables -See \`config.log' for more details." "$LINENO" 5; }; } +as_fn_error 77 "C++ compiler cannot create executables +See \`config.log' for more details" "$LINENO" 5; } +else + { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 +$as_echo "yes" >&6; } fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for C++ compiler default output file name" >&5 +$as_echo_n "checking for C++ compiler default output file name... " >&6; } +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_file" >&5 +$as_echo "$ac_file" >&6; } ac_exeext=$ac_cv_exeext -# Check that the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether the C++ compiler works" >&5 -$as_echo_n "checking whether the C++ compiler works... " >&6; } -# If not cross compiling, check that we can run a simple program. -if test "$cross_compiling" != yes; then - if { ac_try='./$ac_file' - { { case "(($ac_try" in - *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; - *) ac_try_echo=$ac_try;; -esac -eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" -$as_echo "$ac_try_echo"; } >&5 - (eval "$ac_try") 2>&5 - ac_status=$? - $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 - test $ac_status = 0; }; }; then - cross_compiling=no - else - if test "$cross_compiling" = maybe; then - cross_compiling=yes - else - { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 -$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error "cannot run C++ compiled programs. -If you meant to cross compile, use \`--host'. -See \`config.log' for more details." "$LINENO" 5; } - fi - fi -fi -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5 -$as_echo "yes" >&6; } - -rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out conftest.out +rm -f -r a.out a.out.dSYM a.exe conftest$ac_cv_exeext b.out ac_clean_files=$ac_clean_files_save -# Check that the compiler produces executables we can run. If not, either -# the compiler is broken, or we cross compile. -{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 -$as_echo_n "checking whether we are cross compiling... " >&6; } -{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 -$as_echo "$cross_compiling" >&6; } - { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of executables" >&5 $as_echo_n "checking for suffix of executables... " >&6; } if { { ac_try="$ac_link" @@ -2339,19 +2334,78 @@ else { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error "cannot compute suffix of executables: cannot compile and link -See \`config.log' for more details." "$LINENO" 5; } +as_fn_error $? "cannot compute suffix of executables: cannot compile and link +See \`config.log' for more details" "$LINENO" 5; } fi -rm -f conftest$ac_cv_exeext +rm -f conftest conftest$ac_cv_exeext { $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_exeext" >&5 $as_echo "$ac_cv_exeext" >&6; } rm -f conftest.$ac_ext EXEEXT=$ac_cv_exeext ac_exeext=$EXEEXT +cat confdefs.h - <<_ACEOF >conftest.$ac_ext +/* end confdefs.h. */ +#include +int +main () +{ +FILE *f = fopen ("conftest.out", "w"); + return ferror (f) || fclose (f) != 0; + + ; + return 0; +} +_ACEOF +ac_clean_files="$ac_clean_files conftest.out" +# Check that the compiler produces executables we can run. If not, either +# the compiler is broken, or we cross compile. +{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether we are cross compiling" >&5 +$as_echo_n "checking whether we are cross compiling... " >&6; } +if test "$cross_compiling" != yes; then + { { ac_try="$ac_link" +case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_link") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; } + if { ac_try='./conftest$ac_cv_exeext' + { { case "(($ac_try" in + *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;; + *) ac_try_echo=$ac_try;; +esac +eval ac_try_echo="\"\$as_me:${as_lineno-$LINENO}: $ac_try_echo\"" +$as_echo "$ac_try_echo"; } >&5 + (eval "$ac_try") 2>&5 + ac_status=$? + $as_echo "$as_me:${as_lineno-$LINENO}: \$? = $ac_status" >&5 + test $ac_status = 0; }; }; then + cross_compiling=no + else + if test "$cross_compiling" = maybe; then + cross_compiling=yes + else + { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 +$as_echo "$as_me: error: in \`$ac_pwd':" >&2;} +as_fn_error $? "cannot run C++ compiled programs. +If you meant to cross compile, use \`--host'. +See \`config.log' for more details" "$LINENO" 5; } + fi + fi +fi +{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $cross_compiling" >&5 +$as_echo "$cross_compiling" >&6; } + +rm -f conftest.$ac_ext conftest$ac_cv_exeext conftest.out +ac_clean_files=$ac_clean_files_save { $as_echo "$as_me:${as_lineno-$LINENO}: checking for suffix of object files" >&5 $as_echo_n "checking for suffix of object files... " >&6; } -if test "${ac_cv_objext+set}" = set; then : +if ${ac_cv_objext+:} false; then : $as_echo_n "(cached) " >&6 else cat confdefs.h - <<_ACEOF >conftest.$ac_ext @@ -2391,8 +2445,8 @@ { { $as_echo "$as_me:${as_lineno-$LINENO}: error: in \`$ac_pwd':" >&5 $as_echo "$as_me: error: in \`$ac_pwd':" >&2;} -as_fn_error "cannot compute suffix of object files: cannot compile [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rprotobuf -r 572 From noreply at r-forge.r-project.org Thu Dec 19 03:02:23 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 03:02:23 +0100 (CET) Subject: [Rprotobuf-commits] r573 - in pkg: . vignettes Message-ID: <20131219020223.978DD1868AB@r-forge.r-project.org> Author: edd Date: 2013-12-19 03:02:22 +0100 (Thu, 19 Dec 2013) New Revision: 573 Removed: pkg/vignettes/unitTests/ Modified: pkg/ChangeLog pkg/cleanup pkg/vignettes/RProtoBuf-unitTests.Rnw Log: rewritten / simplified unitTests vignette Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-19 01:23:37 UTC (rev 572) +++ pkg/ChangeLog 2013-12-19 02:02:22 UTC (rev 573) @@ -2,6 +2,8 @@ * vignettes/RProtoBuf-intro.Rnw: Use with vignette builder * vignettes/RProtoBuf-quickref.Rnw: Idem + * vignettes/RProtoBuf-unitTests.Rnw: Rewritten / simplified + * DESCRIPTION: Increased dependency to R (>= 3.0.0) * configure.in: No longer create vignettes/Makefile Modified: pkg/cleanup =================================================================== --- pkg/cleanup 2013-12-19 01:23:37 UTC (rev 572) +++ pkg/cleanup 2013-12-19 02:02:22 UTC (rev 573) @@ -4,9 +4,11 @@ src/addressbook.pb.cc src/addressbook.pb.h \ src/protobufrpc.pb.cc src/protobufrpc.pb.h \ src/*.o src/*.d src/*.a src/*.dll src/*.so src/*.rc */*~ *~ \ - src/symbols.rds + src/symbols.rds \ + vignettes/RProtoBuf*.aux vignettes/RProtoBuf*.log \ + vignettes/RProtoBuf*.out vignettes/RProtoBuf*.toc \ + vignettes/RProtoBuf*.tex + rm -rf inst/doc/auto -( cd vignettes; rm -f RProtoBuf*.aux RProtoBuf*.log \ - RProtoBuf*.out RProtoBuf*.toc ) Modified: pkg/vignettes/RProtoBuf-unitTests.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-unitTests.Rnw 2013-12-19 01:23:37 UTC (rev 572) +++ pkg/vignettes/RProtoBuf-unitTests.Rnw 2013-12-19 02:02:22 UTC (rev 573) @@ -1,21 +1,63 @@ \documentclass[10pt]{article} %\VignetteIndexEntry{RProtoBuf-unitTests} +%\VignetteKeywords{RProtoBuf, Protocol Buffers, package} +%\VignetteDepends{RProtoBuf} + \usepackage{vmargin} \setmargrb{0.75in}{0.75in}{0.75in}{0.75in} +<>= +require(RProtoBuf) +prettyVersion <- packageDescription("RProtoBuf")$Version +prettyDate <- format(Sys.Date(), "%B %e, %Y") +library(RUnit) +@ + \usepackage[colorlinks]{hyperref} \author{Romain Fran\c{c}ois \and Dirk Eddelbuettel \and Murray Stokely} \title{RProtoBuf : Unit testing results} +\date{RProtoBuf version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}} + \begin{document} \maketitle +\section*{Test Execution} + +<>= +pkg <- "RProtoBuf" + +if (file.exists("unitTests-results")) unlink("unitTests-results", recursive = TRUE) +dir.create("unitTests-results") +pathRcppTests <<- system.file("unitTests", package = pkg) +path <- system.file("unitTests", package=pkg) +testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs=path) +tests <- runTestSuite(testSuite) +err <- getErrors(tests) +if (err$nFail > 0) cat(sprintf("unit test problems: %d failures", err$nFail)) +if (err$nErr > 0) cat(sprintf("unit test problems: %d errors", err$nErr)) +printHTMLProtocol(tests, fileName=sprintf("unitTests-results/%s-unitTests.html", pkg)) +printTextProtocol(tests, fileName=sprintf("unitTests-results/%s-unitTests.txt" , pkg)) + +if (file.exists("/tmp")) { + invisible(sapply(c("txt", "html"), function(ext) { + fname <- sprintf("unitTests-results/%s-unitTests.%s", pkg, ext) + file.copy(fname, "/tmp", overwrite=TRUE) + })) +} +@ + +\section*{Test Results} + \begin{verbatim} -<>= -results <- "unitTests-results/RProtoBuf-unitTests.txt" -if( file.exists( results ) ){ - writeLines( readLines( results ) ) +<>= +results <- sprintf("unitTests-results/%s-unitTests.txt", pkg) +if (file.exists(results)) { + writeLines(readLines(results)) +} else{ + writeLines("Unit test results not available") } @ + \end{verbatim} \end{document} From mstokely at google.com Thu Dec 19 03:04:39 2013 From: mstokely at google.com (Murray Stokely) Date: Wed, 18 Dec 2013 18:04:39 -0800 Subject: [Rprotobuf-commits] r573 - in pkg: . vignettes In-Reply-To: <20131219020223.978DD1868AB@r-forge.r-project.org> References: <20131219020223.978DD1868AB@r-forge.r-project.org> Message-ID: great. I'm working on section 3 of rprotobuf-intro now. - Murray On Wed, Dec 18, 2013 at 6:02 PM, wrote: > Author: edd > Date: 2013-12-19 03:02:22 +0100 (Thu, 19 Dec 2013) > New Revision: 573 > > Removed: > pkg/vignettes/unitTests/ > Modified: > pkg/ChangeLog > pkg/cleanup > pkg/vignettes/RProtoBuf-unitTests.Rnw > Log: > rewritten / simplified unitTests vignette > > > Modified: pkg/ChangeLog > =================================================================== > --- pkg/ChangeLog 2013-12-19 01:23:37 UTC (rev 572) > +++ pkg/ChangeLog 2013-12-19 02:02:22 UTC (rev 573) > @@ -2,6 +2,8 @@ > > * vignettes/RProtoBuf-intro.Rnw: Use with vignette builder > * vignettes/RProtoBuf-quickref.Rnw: Idem > + * vignettes/RProtoBuf-unitTests.Rnw: Rewritten / simplified > + > * DESCRIPTION: Increased dependency to R (>= 3.0.0) > > * configure.in: No longer create vignettes/Makefile > > Modified: pkg/cleanup > =================================================================== > --- pkg/cleanup 2013-12-19 01:23:37 UTC (rev 572) > +++ pkg/cleanup 2013-12-19 02:02:22 UTC (rev 573) > @@ -4,9 +4,11 @@ > src/addressbook.pb.cc src/addressbook.pb.h \ > src/protobufrpc.pb.cc src/protobufrpc.pb.h \ > src/*.o src/*.d src/*.a src/*.dll src/*.so src/*.rc */*~ *~ \ > - src/symbols.rds > + src/symbols.rds \ > + vignettes/RProtoBuf*.aux vignettes/RProtoBuf*.log \ > + vignettes/RProtoBuf*.out vignettes/RProtoBuf*.toc \ > + vignettes/RProtoBuf*.tex > + > rm -rf inst/doc/auto > > -( cd vignettes; rm -f RProtoBuf*.aux RProtoBuf*.log \ > - RProtoBuf*.out RProtoBuf*.toc ) > > > Modified: pkg/vignettes/RProtoBuf-unitTests.Rnw > =================================================================== > --- pkg/vignettes/RProtoBuf-unitTests.Rnw 2013-12-19 01:23:37 UTC > (rev 572) > +++ pkg/vignettes/RProtoBuf-unitTests.Rnw 2013-12-19 02:02:22 UTC > (rev 573) > @@ -1,21 +1,63 @@ > \documentclass[10pt]{article} > %\VignetteIndexEntry{RProtoBuf-unitTests} > +%\VignetteKeywords{RProtoBuf, Protocol Buffers, package} > +%\VignetteDepends{RProtoBuf} > + > \usepackage{vmargin} > \setmargrb{0.75in}{0.75in}{0.75in}{0.75in} > > +<>= > +require(RProtoBuf) > +prettyVersion <- packageDescription("RProtoBuf")$Version > +prettyDate <- format(Sys.Date(), "%B %e, %Y") > +library(RUnit) > +@ > + > \usepackage[colorlinks]{hyperref} > \author{Romain Fran\c{c}ois \and Dirk Eddelbuettel \and Murray Stokely} > \title{RProtoBuf : Unit testing results} > +\date{RProtoBuf version \Sexpr{prettyVersion} as of \Sexpr{prettyDate}} > + > \begin{document} > \maketitle > > +\section*{Test Execution} > + > +<>= > +pkg <- "RProtoBuf" > + > +if (file.exists("unitTests-results")) unlink("unitTests-results", > recursive = TRUE) > +dir.create("unitTests-results") > +pathRcppTests <<- system.file("unitTests", package = pkg) > +path <- system.file("unitTests", package=pkg) > +testSuite <- defineTestSuite(name=paste(pkg, "unit testing"), dirs=path) > +tests <- runTestSuite(testSuite) > +err <- getErrors(tests) > +if (err$nFail > 0) cat(sprintf("unit test problems: %d failures", > err$nFail)) > +if (err$nErr > 0) cat(sprintf("unit test problems: %d errors", err$nErr)) > +printHTMLProtocol(tests, > fileName=sprintf("unitTests-results/%s-unitTests.html", pkg)) > +printTextProtocol(tests, > fileName=sprintf("unitTests-results/%s-unitTests.txt" , pkg)) > + > +if (file.exists("/tmp")) { > + invisible(sapply(c("txt", "html"), function(ext) { > + fname <- sprintf("unitTests-results/%s-unitTests.%s", pkg, ext) > + file.copy(fname, "/tmp", overwrite=TRUE) > + })) > +} > +@ > + > +\section*{Test Results} > + > \begin{verbatim} > -<>= > -results <- "unitTests-results/RProtoBuf-unitTests.txt" > -if( file.exists( results ) ){ > - writeLines( readLines( results ) ) > +<>= > +results <- sprintf("unitTests-results/%s-unitTests.txt", pkg) > +if (file.exists(results)) { > + writeLines(readLines(results)) > +} else{ > + writeLines("Unit test results not available") > } > @ > + > \end{verbatim} > > \end{document} > > _______________________________________________ > Rprotobuf-commits mailing list > Rprotobuf-commits at lists.r-forge.r-project.org > > https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rprotobuf-commits > -------------- next part -------------- An HTML attachment was scrubbed... URL: From noreply at r-forge.r-project.org Thu Dec 19 03:20:07 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 03:20:07 +0100 (CET) Subject: [Rprotobuf-commits] r574 - in pkg: . vignettes Message-ID: <20131219022007.CBB8B185FBF@r-forge.r-project.org> Author: edd Date: 2013-12-19 03:20:05 +0100 (Thu, 19 Dec 2013) New Revision: 574 Modified: pkg/cleanup pkg/vignettes/RProtoBuf-intro.Rnw pkg/vignettes/RProtoBuf-quickref.Rnw pkg/vignettes/RProtoBuf-unitTests.Rnw Log: switched fonts in vignettes Modified: pkg/cleanup =================================================================== --- pkg/cleanup 2013-12-19 02:02:22 UTC (rev 573) +++ pkg/cleanup 2013-12-19 02:20:05 UTC (rev 574) @@ -7,7 +7,7 @@ src/symbols.rds \ vignettes/RProtoBuf*.aux vignettes/RProtoBuf*.log \ vignettes/RProtoBuf*.out vignettes/RProtoBuf*.toc \ - vignettes/RProtoBuf*.tex + vignettes/RProtoBuf*.tex vignettes/RProtoBuf*.pdf rm -rf inst/doc/auto Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 02:02:22 UTC (rev 573) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 02:20:05 UTC (rev 574) @@ -9,6 +9,11 @@ \setlength{\oddsidemargin}{0pt} \setlength{\textwidth}{17cm} % uh-oh, I use letter :) \setcounter{tocdepth}{2} + +\usepackage{microtype} %% cf http://www.khirevich.com/latex/microtype/ +\usepackage[T1]{fontenc} %% cf http://www.khirevich.com/latex/font/ +\usepackage[bitstream-charter]{mathdesign} %% cf http://www.khirevich.com/latex/font/ + <>= library("RProtoBuf") options("width"=65) Modified: pkg/vignettes/RProtoBuf-quickref.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-quickref.Rnw 2013-12-19 02:02:22 UTC (rev 573) +++ pkg/vignettes/RProtoBuf-quickref.Rnw 2013-12-19 02:20:05 UTC (rev 574) @@ -19,6 +19,10 @@ \usepackage[colorlinks]{hyperref} +\usepackage{microtype} %% cf http://www.khirevich.com/latex/microtype/ +\usepackage[T1]{fontenc} %% cf http://www.khirevich.com/latex/font/ +\usepackage[bitstream-charter]{mathdesign} %% cf http://www.khirevich.com/latex/font/ + <>= options(width= 50) library("RProtoBuf") Modified: pkg/vignettes/RProtoBuf-unitTests.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-unitTests.Rnw 2013-12-19 02:02:22 UTC (rev 573) +++ pkg/vignettes/RProtoBuf-unitTests.Rnw 2013-12-19 02:20:05 UTC (rev 574) @@ -13,6 +13,10 @@ library(RUnit) @ +\usepackage{microtype} %% cf http://www.khirevich.com/latex/microtype/ +\usepackage[T1]{fontenc} %% cf http://www.khirevich.com/latex/font/ +\usepackage[bitstream-charter]{mathdesign} %% cf http://www.khirevich.com/latex/font/ + \usepackage[colorlinks]{hyperref} \author{Romain Fran\c{c}ois \and Dirk Eddelbuettel \and Murray Stokely} \title{RProtoBuf : Unit testing results} From edd at debian.org Thu Dec 19 03:20:52 2013 From: edd at debian.org (Dirk Eddelbuettel) Date: Wed, 18 Dec 2013 20:20:52 -0600 Subject: [Rprotobuf-commits] r573 - in pkg: . vignettes In-Reply-To: References: <20131219020223.978DD1868AB@r-forge.r-project.org> Message-ID: <21170.22532.174871.682375@max.nulle.part> On 18 December 2013 at 18:04, Murray Stokely wrote: | great. ?I'm working on section 3 of rprotobuf-intro now. ? - Murray Splendid. I just made more commit (r574) and should now be done. Dirk -- Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com From noreply at r-forge.r-project.org Thu Dec 19 03:55:51 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 03:55:51 +0100 (CET) Subject: [Rprotobuf-commits] r575 - pkg/vignettes Message-ID: <20131219025551.3F3B81867ED@r-forge.r-project.org> Author: murray Date: 2013-12-19 03:55:50 +0100 (Thu, 19 Dec 2013) New Revision: 575 Modified: pkg/vignettes/RProtoBuf-intro.Rnw Log: Document all 10 methods of the EnumDescriptor class, and all 15 of the FieldDescriptor class and add the summary tables of methods, just as we do for the Message class. Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 02:20:05 UTC (rev 574) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 02:55:50 UTC (rev 575) @@ -1104,6 +1104,8 @@ The class \emph{FieldDescriptor} represents field descriptor in R. This is a wrapper S4 class around the \texttt{google::protobuf::FieldDescriptor} C++ class. +Table~\ref{fielddescriptor-methods-table} describes the methods +defined for the \texttt{FieldDescriptor} class. \begin{table}[h] \centering @@ -1123,7 +1125,41 @@ \caption{\label{FieldDescriptor-class-table}Description of slots for the \texttt{FieldDescriptor} S4 class} \end{table} + +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{|ccp{8cm}|} +\hline +\textbf{method} & \textbf{section} & \textbf{description} \\ +\hline +\hline +\texttt{as.character} & \ref{fielddescriptor-method-ascharacter} & character representation of a descriptor\\ +\texttt{toString} & \ref{fielddescriptor-method-tostring} & character +representation of a descriptor (same as \texttt{as.character}) \\ +\texttt{name} & \ref{fielddescriptor-method-name} & Return the name of the field descriptor.\\ +\texttt{fileDescriptor} & \ref{fielddescriptor-method-filedescriptor} +& Return the fileDescriptor where this field is defined.\\ +\texttt{containing\_type} & +\ref{fielddescriptor-method-containingtype} & Return the containing descriptor of this field.\\ +\texttt{is\_extension} & \ref{fielddescriptor-method-isextension} & Return TRUE if this field is an extension.\\ +\texttt{number} & \ref{fielddescriptor-method-number} & Gets the declared tag number of the field.\\ +\texttt{type} & \ref{fielddescriptor-method-type} & Gets the type of the field.\\ +\texttt{cpp\_type} & \ref{fielddescriptor-method-cpptype} & Gets the C++ type of the field.\\ +\texttt{label} & \ref{fielddescriptor-method-label} & Gets the label of a field (optional, required, or repeated).\\ +\texttt{is\_repeated} & \ref{fielddescriptor-method-isrepeated} & Return TRUE if this field is repeated.\\ +\texttt{is\_required} & \ref{fielddescriptor-method-isrequired} & Return TRUE if this field is required.\\ +\texttt{is\_optional} & \ref{fielddescriptor-method-isoptional} & Return TRUE if htis field is optional.\\ +\texttt{message\_type} & \ref{fielddescriptor-method-messagetype} & Return the message type if this is a message type field.\\ +\texttt{enum\_type} & \ref{fielddescriptor-method-enumtype} & Return the enum type if this is an enum type field.\\ +\hline +\end{tabular} +\end{small} +\caption{\label{fielddescriptor-methods-table}Description of methods for the \texttt{FieldDescriptor} S4 class} +\end{table} + \subsubsection{as.character} +\label{fielddescriptor-method-ascharacter} The \texttt{as.character} method brings the debug string of the field descriptor. @@ -1132,6 +1168,7 @@ @ \subsubsection{toString} +\label{fielddescriptor-method-tostring} \texttt{toString} is an alias of \texttt{as.character}. @@ -1140,6 +1177,7 @@ @ \subsubsection{name} +\label{fielddescriptor-method-name} The \texttt{name} method can be used to retrieve the name of the field descriptor. @@ -1151,11 +1189,140 @@ name( tutorial.Person$id, full=TRUE ) @ +\subsubsection{fileDescriptor} +\label{fielddescriptor-method-filedescriptor} + +The \texttt{fileDescriptor} method can be used to retrieve the file +descriptor of the field descriptor. + +<<>>= +fileDescriptor(tutorial.Person$id) +tutorial.Person$id$fileDescriptor() +@ + +\subsubsection{containing\_type} +\label{fielddescriptor-method-containingtype} + +The \texttt{containing\_type} method can be used to retrieve the +descriptor for the message type that contains this descriptor. + +<<>>= +containing_type(tutorial.Person$id) +tutorial.Person$id$containing_type() +@ + + +\subsubsection{is\_extension} +\label{fielddescriptor-method-isextension} + +The \texttt{is\_extension} method returns TRUE if this field is an extension. +% TODO(ms): cross reference to a to be written section on extensions. + +<<>>= +is_extension( tutorial.Person$id ) +tutorial.Person$id$is_extension() +@ + +\subsubsection{number} +\label{fielddescriptor-method-number} + +The \texttt{number} method returns the declared tag number of this field. + +<<>>= +number( tutorial.Person$id ) +tutorial.Person$id$number() +@ + +\subsubsection{type} +\label{fielddescriptor-method-type} + +The \texttt{type} method can be used to retrieve the type of the +field descriptor. + +<<>>= +type( tutorial.Person$id ) +tutorial.Person$id$type() +@ +\subsubsection{cpp\_type} +\label{fielddescriptor-method-cpptype} + +The \texttt{cpp\_type} method can be used to retrieve the C++ type of the +field descriptor. + +<<>>= +cpp_type( tutorial.Person$id ) +tutorial.Person$id$cpp_type() +@ + +\subsubsection{label} +\label{fielddescriptor-method-label} + +Gets the label of a field (optional, required, or repeated). +The \texttt{label} method returns the label of a field (optional, +required, or repeated). By defualt it returns a number value, but the +optional \texttt{as.string} argument can be provided to return a +human readable string representation. + +<<>>= +label( tutorial.Person$id ) +label( tutorial.Person$id , TRUE) +tutorial.Person$id$label(TRUE) +@ +\subsubsection{is\_repeated} +\label{fielddescriptor-method-isrepeated} + +The \texttt{is\_repeated} method returns TRUE if this field is repeated. + +<<>>= +is_repeated( tutorial.Person$id ) +tutorial.Person$id$is_repeated() +@ + +\subsubsection{is\_required} +\label{fielddescriptor-method-isrequired} + +The \texttt{is\_required} method returns TRUE if this field is required. + +<<>>= +is_required( tutorial.Person$id ) +tutorial.Person$id$is_required() +@ + +\subsubsection{is\_optional} +\label{fielddescriptor-method-isoptional} + +The \texttt{is\_optional} method returns TRUE if this field is optional. + +<<>>= +is_optional( tutorial.Person$id ) +tutorial.Person$id$is_optional() +@ +\subsubsection{message\_type} +\label{fielddescriptor-method-messagetype} + +The \texttt{message\_type} method returns the message type if this is +a message type field. + +<<>>= +message_type(tutorial.Person$phone) +tutorial.Person$phone$message_type() +@ +\subsubsection{enum\_type} +\label{fielddescriptor-method-enumtype} + +The \texttt{enum\_type} method returns the enum type if this is an enum type field. + +<<>>= +enum_type(tutorial.Person$PhoneNumber$type) +@ + \subsection{enum descriptors} \label{subsec-enum-descriptor} The class \emph{EnumDescriptor} is an R wrapper class around the C++ class \texttt{google::protobuf::EnumDescriptor}. +Table~\ref{enumdescriptor-methods-table} describes the methods +defined for the \texttt{EnumDescriptor} class. \begin{table}[h] \centering @@ -1175,7 +1342,51 @@ \caption{\label{EnumDescriptor-class-table}Description of slots for the \texttt{EnumDescriptor} S4 class} \end{table} +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{|ccp{8cm}|} +\hline +\textbf{method} & \textbf{section} & \textbf{description} \\ +\hline +\hline +\texttt{as.list} & \ref{enumdescriptor-method-aslist} & return a named +integer vector with the values of the enum and their names.\\ +\texttt{as.character} & \ref{enumdescriptor-method-ascharacter} & character representation of a descriptor\\ +\texttt{toString} & \ref{enumdescriptor-method-tostring} & character +representation of a descriptor (same as \texttt{as.character}) \\ +\texttt{name} & \ref{enumdescriptor-method-name} & Return the name of the enum descriptor.\\ +\texttt{fileDescriptor} & \ref{enumdescriptor-method-filedescriptor} +& Return the fileDescriptor where this field is defined.\\ +\texttt{containing\_type} & +\ref{enumdescriptor-method-containingtype} & Return the containing descriptor of this field.\\ +\texttt{length} & +\ref{enumdescriptor-method-length} & Return the number of constants in +this enum.\\ +\texttt{value\_count} & +\ref{enumdescriptor-method-valuecount} & Return the number of constants in +this enum (same as \texttt{length}).\\ +\texttt{value} & +\ref{enumdescriptor-method-value} & Return the +EnumValueDescriptor of an enum value of specified index, name, or number.\\ +\hline +\end{tabular} +\end{small} +\caption{\label{enumdescriptor-methods-table}Description of methods for the \texttt{EnumDescriptor} S4 class} +\end{table} + +\subsubsection{Extracting descriptors} + +The \verb|$| operator, when used on a EnumDescriptor object retrieves +EnumValueDescriptors that are contained in the descriptor. + +<<>>= +tutorial.Person$PhoneType$WORK +name(tutorial.Person$PhoneType$value(number=2)) +@ + \subsubsection{as.list} +\label{enumdescriptor-method-aslist} The \texttt{as.list} method creates a named R integer vector that captures the values of the enum and their names. @@ -1185,6 +1396,7 @@ @ \subsubsection{as.character} +\label{enumdescriptor-method-ascharacter} The \texttt{as.character} method brings the debug string of the enum type. @@ -1192,6 +1404,81 @@ writeLines( as.character( tutorial.Person$PhoneType ) ) @ +\subsubsection{toString} +\label{enumdescriptor-method-tostring} + +The \texttt{toString} method brings the debug string of the enum type. + +<<>>= +writeLines( toString( tutorial.Person$PhoneType ) ) +@ + +\subsubsection{name} +\label{enumdescriptor-method-name} + +The \texttt{name} method can be used to retrieve the name of the +enum descriptor. + +<<>>= +# simple name. +name( tutorial.Person$PhoneType ) +# name including scope. +name( tutorial.Person$PhoneType, full=TRUE ) +@ + +\subsubsection{fileDescriptor} +\label{enumdescriptor-method-filedescriptor} + +The \texttt{fileDescriptor} method can be used to retrieve the file +descriptor of the enum descriptor. + +<<>>= +fileDescriptor(tutorial.Person$PhoneType) +tutorial.Person$PhoneType$fileDescriptor() +@ + +\subsubsection{containing\_type} +\label{enumdescriptor-method-containingtype} + +The \texttt{containing\_type} method can be used to retrieve the +descriptor for the message type that contains this enum descriptor. + +TODO(ms): seems broken, fix it! + +\subsubsection{length} +\label{enumdescriptor-method-length} + +The \texttt{length} method returns the number of constants in this enum. + +<<>>= +length(tutorial.Person$PhoneType) +tutorial.Person$PhoneType$length() +@ + +\subsubsection{value\_count} +\label{enumdescriptor-method-valuecount} + +The \texttt{value\_count} method returnst he number of constants in +this enum. +%TODO(ms): Duplicate of length, just like tostring/as.character. +<<>>= +value_count(tutorial.Person$PhoneType) +tutorial.Person$PhoneType$value_count() +@ + +\subsubsection{value} +\label{enumdescriptor-method-value} + +The \texttt{value} method extracts an EnumValueDescriptor. Exactly +one argument of 'index', 'number', or 'name' must be specified to +identify which constant is desired. + +<<>>= +tutorial.Person$PhoneType$value(1) +tutorial.Person$PhoneType$value(name="HOME") +tutorial.Person$PhoneType$value(number=1) +@ + \subsection{file descriptors} \label{subsec-fileDescriptor} From noreply at r-forge.r-project.org Thu Dec 19 04:01:25 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 04:01:25 +0100 (CET) Subject: [Rprotobuf-commits] r576 - pkg/vignettes Message-ID: <20131219030125.8090B186888@r-forge.r-project.org> Author: murray Date: 2013-12-19 04:01:23 +0100 (Thu, 19 Dec 2013) New Revision: 576 Modified: pkg/vignettes/RProtoBuf-intro.Rnw Log: Add empty section on enumvaluedescriptors, which was missing from section 3. Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 02:55:50 UTC (rev 575) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 03:01:23 UTC (rev 576) @@ -1557,15 +1557,21 @@ tutorial.Person$fileDescriptor()$package() @ +\subsection{enum value descriptors} +\label{subsec-EnumValueDescriptor} + +TODO: add content + \subsection{service descriptors} \label{subsec-ServiceDescriptor} -TODO: add content +TODO: add content or remove? \subsection{method descriptors} \label{subsec-MethodDescriptor} -TODO: add content +TODO: add content or remove? + \section{Utilities} \subsection{coercing objects to messages} From noreply at r-forge.r-project.org Thu Dec 19 04:02:24 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 04:02:24 +0100 (CET) Subject: [Rprotobuf-commits] r577 - papers/rjournal Message-ID: <20131219030224.DD154186891@r-forge.r-project.org> Author: murray Date: 2013-12-19 04:02:20 +0100 (Thu, 19 Dec 2013) New Revision: 577 Modified: papers/rjournal/eddelbuettel-francois-stokely.bib Log: Add Rcpp JSS article, feel free to replace with the book if you prefer. will definitely need to cite this. Modified: papers/rjournal/eddelbuettel-francois-stokely.bib =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-19 03:01:23 UTC (rev 576) +++ papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-19 03:02:20 UTC (rev 577) @@ -1,3 +1,12 @@ + at article{eddelbuettel2011rcpp, + title={Rcpp: Seamless R and C++ integration}, + author={Eddelbuettel, Dirk and Fran{\c{c}}ois, Romain}, + journal={Journal of Statistical Software}, + volume={40}, + number={8}, + pages={1--18}, + year={2011} +} @inproceedings{cantrill2004dynamic, title={Dynamic Instrumentation of Production Systems.}, author={Cantrill, Bryan and Shapiro, Michael W and Leventhal, Adam H and others}, From noreply at r-forge.r-project.org Thu Dec 19 06:12:24 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 06:12:24 +0100 (CET) Subject: [Rprotobuf-commits] r578 - pkg/vignettes Message-ID: <20131219051224.7C0E0184F53@r-forge.r-project.org> Author: murray Date: 2013-12-19 06:12:23 +0100 (Thu, 19 Dec 2013) New Revision: 578 Modified: pkg/vignettes/RProtoBuf-intro.Rnw Log: Document EnumValueDescriptor and add the has method for EnumDescriptor. Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 03:02:20 UTC (rev 577) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 05:12:23 UTC (rev 578) @@ -1363,6 +1363,9 @@ \texttt{length} & \ref{enumdescriptor-method-length} & Return the number of constants in this enum.\\ +\texttt{has} & +\ref{enumdescriptor-method-has} & Return TRUE if this enum contains +the specified named constant string.\\ \texttt{value\_count} & \ref{enumdescriptor-method-valuecount} & Return the number of constants in this enum (same as \texttt{length}).\\ @@ -1455,6 +1458,17 @@ tutorial.Person$PhoneType$length() @ +\subsubsection{has} +\label{enumdescriptor-method-has} + +The \texttt{has} method returns TRUE if this enum contains the +specified named constant string. + +<<>>= +tutorial.Person$PhoneType$has("WORK") +tutorial.Person$PhoneType$has("nonexistant") +@ + \subsubsection{value\_count} \label{enumdescriptor-method-valuecount} @@ -1479,6 +1493,120 @@ tutorial.Person$PhoneType$value(number=1) @ +\subsection{enum value descriptors} +\label{subsec-EnumValueDescriptor} + +The class \emph{EnumValueDescriptor} is an R wrapper +class around the C++ class \texttt{google::protobuf::EnumValueDescriptor}. +Table~\ref{enumvaluedescriptor-methods-table} describes the methods +defined for the \texttt{EnumValueDescriptor} class. + +\begin{table}[h] +\centering +\begin{tabular}{|cp{10cm}|} +\hline +\textbf{slot} & \textbf{description} \\ +\hline +\texttt{pointer} & External pointer to the \texttt{EnumValueDescriptor} C++ variable \\ +\hline +\texttt{name} & simple name of the enum value \\ +\hline +\texttt{full\_name} & fully qualified name of the enum value \\ +\hline +\end{tabular} +\caption{\label{EnumValueDescriptor-class-table}Description of slots for the \texttt{EnumValueDescriptor} S4 class} +\end{table} + +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{|ccp{8cm}|} +\hline +\textbf{method} & \textbf{section} & \textbf{description} \\ +\hline +\hline +\texttt{number} & \ref{enumvaluedescriptor-method-number} & return the +number of this EnumValueDescriptor. \\ +\texttt{name} & \ref{enumvaluedescriptor-method-name} & Return the name of +the enum value descriptor.\\ +\texttt{enum\_type} & \ref{enumvaluedescriptor-method-enumtype} & +return the EnumDescriptor type of this EnumValueDescriptor. \\ +\texttt{as.character} & \ref{enumvaluedescriptor-method-ascharacter} & character +representation of a descriptor. \\ +\texttt{toString} & \ref{enumvaluedescriptor-method-tostring} & character +representation of a descriptor (same as \texttt{as.character}). \\ +\texttt{asMessage} & \ref{enumvaluedescriptor-method-asmessage} & +return EnumValueDescriptorProto message. \\ +\hline +\end{tabular} +\end{small} +\caption{\label{enumvaluedescriptor-methods-table}Description of methods for the \texttt{EnumValueDescriptor} S4 class} +\end{table} + +\subsubsection{number} +\label{enumvaluedescriptor-method-number} + +The \texttt{number} method can be used to retrieve the number of the +enum value descriptor. + +<<>>= +number( tutorial.Person$PhoneType$value(number=2) ) +@ + +\subsubsection{name} +\label{enumvaluedescriptor-method-name} + +The \texttt{name} method can be used to retrieve the name of the +enum value descriptor. + +<<>>= +# simple name. +name( tutorial.Person$PhoneType$value(number=2) ) +# name including scope. +name( tutorial.Person$PhoneType$value(number=2), full=TRUE ) +@ + +\subsubsection{enum\_type} +\label{enumvaluedescriptor-method-enumtype} + +The \texttt{enum\_type} method can be used to retrieve the EnumDescriptor of the +enum value descriptor. + +<<>>= +enum_type( tutorial.Person$PhoneType$value(number=2) ) +@ + +\subsubsection{as.character} +\label{enumvaluedescriptor-method-ascharacter} + +The \texttt{as.character} method brings the debug string of the enum +value type. + +<<>>= +writeLines( as.character( tutorial.Person$PhoneType$value(number=2) ) ) +@ + +\subsubsection{toString} +\label{enumvaluedescriptor-method-tostring} + +The \texttt{toString} method brings the debug string of the enum value +type. + +<<>>= +writeLines( toString( tutorial.Person$PhoneType$value(number=2) ) ) +@ + +\subsubsection{asMessage} +\label{enumvaluedescriptor-method-asmessage} + +The \texttt{asMessage} method returns a message of type +\texttt{google.protobuf.EnumValueDescriptorProto} of the EnumValueDescriptor. + +<<>>= +tutorial.Person$PhoneType$value(number=2)$asMessage() +writeLines(as.character(tutorial.Person$PhoneType$value(number=2)$asMessage())) +@ + \subsection{file descriptors} \label{subsec-fileDescriptor} @@ -1557,11 +1685,7 @@ tutorial.Person$fileDescriptor()$package() @ -\subsection{enum value descriptors} -\label{subsec-EnumValueDescriptor} -TODO: add content - \subsection{service descriptors} \label{subsec-ServiceDescriptor} From noreply at r-forge.r-project.org Thu Dec 19 06:13:16 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 06:13:16 +0100 (CET) Subject: [Rprotobuf-commits] r579 - in pkg: . R Message-ID: <20131219051316.8D98318535B@r-forge.r-project.org> Author: murray Date: 2013-12-19 06:13:16 +0100 (Thu, 19 Dec 2013) New Revision: 579 Modified: pkg/ChangeLog pkg/R/completion.R Log: Add missing completion class for EnumValueDescriptor, and also add missing 'has' method for EnumDescriptor. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-19 05:12:23 UTC (rev 578) +++ pkg/ChangeLog 2013-12-19 05:13:16 UTC (rev 579) @@ -1,3 +1,9 @@ +2013-12-18 Murray Stokely + + * R/completion.R (.DollarNames.EnumValueDescriptor): Add + $-completion for EnumValueDescriptor class as with other S4 + RProtoBuf classes here. + 2013-12-18 Dirk Eddelbuettel * vignettes/RProtoBuf-intro.Rnw: Use with vignette builder Modified: pkg/R/completion.R =================================================================== --- pkg/R/completion.R 2013-12-19 05:12:23 UTC (rev 578) +++ pkg/R/completion.R 2013-12-19 05:13:16 UTC (rev 579) @@ -44,11 +44,20 @@ names <- c( .Call( "EnumDescriptor__getConstantNames", x at pointer, PACKAGE = "RProtoBuf" ), "name(", "fileDescriptor()", "as.character()", "toString()", - "containing_type()", "length()", "value_count()", "value(" ) + "containing_type()", "length()", "value_count()", "value(", + "has(") grep( pattern, names, value = TRUE ) } # }}} +# {{{ EnumValueDescriptor +.DollarNames.EnumValueDescriptor <- function(x, pattern = "" ){ + names <- c("number()", "name()", "enum_type()", + "as.character()", "toString()", "asMessage()") + grep( pattern, names, value = TRUE ) +} +# }}} + # {{{ FieldDescriptor .DollarNames.FieldDescriptor <- function(x, pattern = "" ){ names <- c("as.character()", "toString()", "name(", From noreply at r-forge.r-project.org Thu Dec 19 06:22:03 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 06:22:03 +0100 (CET) Subject: [Rprotobuf-commits] r580 - pkg/R Message-ID: <20131219052203.350B81862C3@r-forge.r-project.org> Author: murray Date: 2013-12-19 06:22:02 +0100 (Thu, 19 Dec 2013) New Revision: 580 Modified: pkg/R/completion.R Log: Add more missing methods from EnumDescriptors and EnumValueDescriptors. Modified: pkg/R/completion.R =================================================================== --- pkg/R/completion.R 2013-12-19 05:13:16 UTC (rev 579) +++ pkg/R/completion.R 2013-12-19 05:22:02 UTC (rev 580) @@ -45,7 +45,7 @@ .Call( "EnumDescriptor__getConstantNames", x at pointer, PACKAGE = "RProtoBuf" ), "name(", "fileDescriptor()", "as.character()", "toString()", "containing_type()", "length()", "value_count()", "value(", - "has(") + "has(", "asMessage()") grep( pattern, names, value = TRUE ) } # }}} @@ -64,7 +64,8 @@ "fileDescriptor()", "containing_type()", "is_extension()", "number()", "type(", "cpp_type(", "label(", "is_repeated()", "is_required()", "is_optional()", - "message_type()", "enum_type()" + "message_type()", "enum_type()", + "has_default_value()", "default_value(", ) grep( pattern, names, value = TRUE ) } From noreply at r-forge.r-project.org Thu Dec 19 07:59:56 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 07:59:56 +0100 (CET) Subject: [Rprotobuf-commits] r581 - in pkg: . R Message-ID: <20131219065957.1E833186840@r-forge.r-project.org> Author: murray Date: 2013-12-19 07:59:56 +0100 (Thu, 19 Dec 2013) New Revision: 581 Modified: pkg/ChangeLog pkg/R/00classes.R pkg/R/completion.R Log: Add more missing $ completion methods, and pass ... for FileDescriptor$name() so it accepts the optional boolean for full paths as with the other name methods. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-19 05:22:02 UTC (rev 580) +++ pkg/ChangeLog 2013-12-19 06:59:56 UTC (rev 581) @@ -1,8 +1,11 @@ 2013-12-18 Murray Stokely * R/completion.R (.DollarNames.EnumValueDescriptor): Add - $-completion for EnumValueDescriptor class as with other S4 - RProtoBuf classes here. + $-completion for EnumValueDescriptor and FileDescriptor classes + as with other S4 RProtoBuf classes here. + * R/00classes.R (P): Ensure that the FileDescriptor $name() method + accepts a boolean for full paths just like the generic name() + method. 2013-12-18 Dirk Eddelbuettel Modified: pkg/R/00classes.R =================================================================== --- pkg/R/00classes.R 2013-12-19 05:22:02 UTC (rev 580) +++ pkg/R/00classes.R 2013-12-19 06:59:56 UTC (rev 581) @@ -288,7 +288,7 @@ "toString" = function(...) toString(x, ...) , "asMessage" = function() asMessage(x), "as.list" = function() as.list(x), - "name" = function() x at filename, + "name" = function(...) name(x, ... ), "package" = function() x at package, invisible(NULL) ) Modified: pkg/R/completion.R =================================================================== --- pkg/R/completion.R 2013-12-19 05:22:02 UTC (rev 580) +++ pkg/R/completion.R 2013-12-19 06:59:56 UTC (rev 581) @@ -31,7 +31,7 @@ names <- c( .Call( "Descriptor__getMemberNames", x at pointer, PACKAGE = "RProtoBuf" ), "new(", "read(", "readASCII(", "fileDescriptor()", "name(", - "toString()", "as.character()", + "toString()", "as.character()", "asMessage()", "containing_type()", "field_count()", "nested_type_count()", "enum_type_count", "field(", "nested_type(", "enum_type(" ) grep( pattern, names, value = TRUE ) @@ -64,7 +64,7 @@ "fileDescriptor()", "containing_type()", "is_extension()", "number()", "type(", "cpp_type(", "label(", "is_repeated()", "is_required()", "is_optional()", - "message_type()", "enum_type()", + "message_type()", "enum_type()", "asMessage()", "has_default_value()", "default_value(", ) grep( pattern, names, value = TRUE ) From noreply at r-forge.r-project.org Thu Dec 19 08:23:34 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 08:23:34 +0100 (CET) Subject: [Rprotobuf-commits] r582 - in pkg: . R Message-ID: <20131219072334.315F4186288@r-forge.r-project.org> Author: murray Date: 2013-12-19 08:23:33 +0100 (Thu, 19 Dec 2013) New Revision: 582 Modified: pkg/ChangeLog pkg/R/wrapper_EnumDescriptor.R Log: Add better error handling. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-19 06:59:56 UTC (rev 581) +++ pkg/ChangeLog 2013-12-19 07:23:33 UTC (rev 582) @@ -6,6 +6,9 @@ * R/00classes.R (P): Ensure that the FileDescriptor $name() method accepts a boolean for full paths just like the generic name() method. + * R/wrapper_EnumDescriptor.R: Add better error checking. Expect + exceptions if wrong types are provided for arguments rather than + just returning NULL. 2013-12-18 Dirk Eddelbuettel Modified: pkg/R/wrapper_EnumDescriptor.R =================================================================== --- pkg/R/wrapper_EnumDescriptor.R 2013-12-19 06:59:56 UTC (rev 581) +++ pkg/R/wrapper_EnumDescriptor.R 2013-12-19 07:23:33 UTC (rev 582) @@ -21,14 +21,17 @@ } if( has_index ){ + stopifnot(is.numeric(index)) return( .Call( "EnumDescriptor__getValueByIndex", object at pointer, as.integer(index)-1L, PACKAGE = "RProtoBuf" ) ) } if( has_number ){ + stopifnot(is.numeric(number)) return( .Call( "EnumDescriptor__getValueByNumber", object at pointer, as.integer(number), PACKAGE = "RProtoBuf" ) ) } if( has_name ){ + stopifnot(is.character(name)) return( .Call( "EnumDescriptor__getValueByName", object at pointer, as.character(name), PACKAGE = "RProtoBuf" ) ) } From noreply at r-forge.r-project.org Thu Dec 19 08:24:04 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 08:24:04 +0100 (CET) Subject: [Rprotobuf-commits] r583 - pkg/R Message-ID: <20131219072404.B08C01862B1@r-forge.r-project.org> Author: murray Date: 2013-12-19 08:24:04 +0100 (Thu, 19 Dec 2013) New Revision: 583 Modified: pkg/R/completion.R Log: Add missing methods for $ completion. Modified: pkg/R/completion.R =================================================================== --- pkg/R/completion.R 2013-12-19 07:23:33 UTC (rev 582) +++ pkg/R/completion.R 2013-12-19 07:24:04 UTC (rev 583) @@ -93,7 +93,8 @@ .DollarNames.FileDescriptor <- function(x, pattern = "" ){ names <- c( .Call( "FileDescriptor__getMemberNames", x at pointer, PACKAGE = "RProtoBuf" ), - "as.character()", "toString()", "name(" ) + "as.character()", "toString()", "name(", "as.list()", + "asMessage()", "package()") grep( pattern, names, value = TRUE ) } # }}} From noreply at r-forge.r-project.org Thu Dec 19 08:25:58 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 08:25:58 +0100 (CET) Subject: [Rprotobuf-commits] r584 - in pkg: src vignettes Message-ID: <20131219072559.15EB51862F6@r-forge.r-project.org> Author: murray Date: 2013-12-19 08:25:58 +0100 (Thu, 19 Dec 2013) New Revision: 584 Modified: pkg/src/Makevars.in pkg/vignettes/RProtoBuf-intro.Rnw Log: Add table of methods for FileDescriptors and add several missing methods to the other descriptor types. Modified: pkg/src/Makevars.in =================================================================== --- pkg/src/Makevars.in 2013-12-19 07:24:04 UTC (rev 583) +++ pkg/src/Makevars.in 2013-12-19 07:25:58 UTC (rev 584) @@ -4,5 +4,5 @@ ## both Rcpp (ie libRcpp.so and Rcpp.h) and ## ProtoBuf headers and library via the variables PKG_CPPFLAGS= @PKG_CPPFLAGS@ -PKG_LIBS= @PKG_LIBS@ +PKG_LIBS= /usr/local/lib/libprotobuf.a @PKG_LIBS@ Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 07:24:04 UTC (rev 583) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 07:25:58 UTC (rev 584) @@ -884,6 +884,8 @@ this descriptor.\\ \texttt{as.character} & \ref{Descriptor-method-ascharacter} & character representation of a descriptor\\ \texttt{toString} & \ref{Descriptor-method-tostring} & character representation of a descriptor (same as \texttt{as.character}) \\ +\texttt{asMessage} & \ref{Descriptor-method-asmessage} & +return DescriptorProto message. \\ \hline \texttt{fileDescriptor} & \ref{Descriptor-method-filedescriptor} & Retrieve the file descriptor of this descriptor.\\ @@ -1001,6 +1003,16 @@ writeLines( as.character(tutorial.Person) ) @ +\subsubsection{asMessage} +\label{Descriptor-method-asmessage} + +The \texttt{asMessage} method returns a message of type +\texttt{google.protobuf.DescriptorProto} of the Descriptor. + +<<>>= +tutorial.Person$asMessage() +@ + \subsubsection{The fileDescriptor method} \label{Descriptor-method-filedescriptor} @@ -1137,6 +1149,8 @@ \texttt{as.character} & \ref{fielddescriptor-method-ascharacter} & character representation of a descriptor\\ \texttt{toString} & \ref{fielddescriptor-method-tostring} & character representation of a descriptor (same as \texttt{as.character}) \\ +\texttt{asMessage} & \ref{fielddescriptor-method-asmessage} & +return FieldDescriptorProto message. \\ \texttt{name} & \ref{fielddescriptor-method-name} & Return the name of the field descriptor.\\ \texttt{fileDescriptor} & \ref{fielddescriptor-method-filedescriptor} & Return the fileDescriptor where this field is defined.\\ @@ -1150,6 +1164,11 @@ \texttt{is\_repeated} & \ref{fielddescriptor-method-isrepeated} & Return TRUE if this field is repeated.\\ \texttt{is\_required} & \ref{fielddescriptor-method-isrequired} & Return TRUE if this field is required.\\ \texttt{is\_optional} & \ref{fielddescriptor-method-isoptional} & Return TRUE if htis field is optional.\\ +\texttt{has\_default\_value} & \ref{fielddescriptor-method-hasdefaultvalue} & +Return TRUE if this field has a default value.\\ +\texttt{default\_value} & \ref{fielddescriptor-method-defaultvalue} & +Return the default value.\\ +\texttt{is\_optional} & \ref{fielddescriptor-method-isoptional} & Return TRUE if htis field is optional.\\ \texttt{message\_type} & \ref{fielddescriptor-method-messagetype} & Return the message type if this is a message type field.\\ \texttt{enum\_type} & \ref{fielddescriptor-method-enumtype} & Return the enum type if this is an enum type field.\\ \hline @@ -1176,6 +1195,17 @@ writeLines( tutorial.Person.PhoneNumber$toString() ) @ +\subsubsection{asMessage} +\label{fielddescriptor-method-asmessage} + +The \texttt{asMessage} method returns a message of type +\texttt{google.protobuf.FieldDescriptorProto} of the FieldDescriptor. + +<<>>= +tutorial.Person$id$asMessage() +writeLines(as.character(tutorial.Person$id$asMessage())) +@ + \subsubsection{name} \label{fielddescriptor-method-name} @@ -1297,6 +1327,35 @@ is_optional( tutorial.Person$id ) tutorial.Person$id$is_optional() @ + + +\texttt{has\_default\_value} & \ref{fielddescriptor-method-hasdefaultvalue} & +Return TRUE if this field has a default value.\\ +\subsubsection{has\_default\_value} +\label{fielddescriptor-method-hasdefaultvalue} + +The \texttt{has\_default\_value} method returns TRUE if this field has +a default value. + +<<>>= +has_default_value(tutorial.Person$PhoneNumber$type) +has_default_value(tutorial.Person$PhoneNumber$number) +@ + +\texttt{default\_value} & \ref{fielddescriptor-method-defaultvalue} & +Return the default value.\\ +\subsubsection{is\_optional} +\label{fielddescriptor-method-isoptional} + +The \texttt{is\_optional} method returns TRUE if this field is optional. + +<<>>= +is_optional( tutorial.Person$id ) +tutorial.Person$id$is_optional() +@ + + + \subsubsection{message\_type} \label{fielddescriptor-method-messagetype} @@ -1355,6 +1414,8 @@ \texttt{as.character} & \ref{enumdescriptor-method-ascharacter} & character representation of a descriptor\\ \texttt{toString} & \ref{enumdescriptor-method-tostring} & character representation of a descriptor (same as \texttt{as.character}) \\ +\texttt{asMessage} & \ref{enumdescriptor-method-asmessage} & +return EnumDescriptorProto message. \\ \texttt{name} & \ref{enumdescriptor-method-name} & Return the name of the enum descriptor.\\ \texttt{fileDescriptor} & \ref{enumdescriptor-method-filedescriptor} & Return the fileDescriptor where this field is defined.\\ @@ -1416,6 +1477,17 @@ writeLines( toString( tutorial.Person$PhoneType ) ) @ +\subsubsection{asMessage} +\label{enumdescriptor-method-asmessage} + +The \texttt{asMessage} method returns a message of type +\texttt{google.protobuf.EnumDescriptorProto} of the EnumDescriptor. + +<<>>= +tutorial.Person$PhoneType$asMessage() +writeLines(as.character(tutorial.Person$PhoneType$asMessage())) +@ + \subsubsection{name} \label{enumdescriptor-method-name} @@ -1634,16 +1706,45 @@ Similarly to messages, the \verb|$| operator can be used to extract information from the file descriptor, or invoke pseuso-methods. +Table~\ref{filedescriptor-methods-table} describes the methods +defined for the \texttt{FileDescriptor} class. +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{|ccp{8cm}|} +\hline +\textbf{method} & \textbf{section} & \textbf{description} \\ +\hline +\hline +\texttt{name} & \ref{filedescriptor-method-name} & Return the filename +for this FileDescriptorProto.\\ +\texttt{package} & \ref{filedescriptor-method-package} & Return the +file-level package name specified in this FileDescriptorProto.\\ +\texttt{as.character} & \ref{filedescriptor-method-ascharacter} & character +representation of a descriptor. \\ +\texttt{toString} & \ref{filedescriptor-method-tostring} & character +representation of a descriptor (same as \texttt{as.character}). \\ +\texttt{asMessage} & \ref{filedescriptor-method-asmessage} & +return FileDescriptorProto message. \\ +\texttt{as.list} & \ref{filedescriptor-method-aslist} & +return named list of descriptors defined in this file descriptor.\\ +\hline +\end{tabular} +\end{small} +\caption{\label{filedescriptor-methods-table}Description of methods for the \texttt{FileDescriptor} S4 class} +\end{table} + \subsubsection{as.character} +\label{filedescriptor-method-ascharacter} +The \texttt{as.character} method brings the debug string of the file descriptor. -The \texttt{as.character} method brings the debug string of the enum type. - <<>>= writeLines( as.character(fileDescriptor(tutorial.Person)) ) @ \subsubsection{toString} +\label{filedescriptor-method-tostring} \texttt{toString} is an alias of \texttt{as.character}. @@ -1652,6 +1753,7 @@ @ \subsubsection{asMessage} +\label{filedescriptor-method-asmessage} The \texttt{asMessage} method returns a protocol buffer message representation of the file descriptor. @@ -1661,6 +1763,7 @@ @ \subsubsection{as.list} +\label{filedescriptor-method-aslist} The \texttt{as.list} method creates a named R list that contains the descriptors defined in this file descriptor. @@ -1669,23 +1772,27 @@ @ \subsubsection{name} +\label{filedescriptor-method-name} The \texttt{name} method can be used to retrieve the file name associated with the -file descriptor. +file descriptor. The optional boolean argument can be specified if +full pathnames are desired. <<>>= name( tutorial.Person$fileDescriptor() ) -tutorial.Person$fileDescriptor()$name() +tutorial.Person$fileDescriptor()$name(TRUE) @ + \subsubsection{package} +\label{filedescriptor-method-package} -The \texttt{package} method can be used to retrieve the package scope associated with this file descriptor. +The \texttt{package} method can be used to retrieve the package scope +associated with this file descriptor. <<>>= tutorial.Person$fileDescriptor()$package() @ - \subsection{service descriptors} \label{subsec-ServiceDescriptor} From noreply at r-forge.r-project.org Thu Dec 19 08:32:03 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 08:32:03 +0100 (CET) Subject: [Rprotobuf-commits] r585 - pkg/vignettes Message-ID: <20131219073204.6403E186888@r-forge.r-project.org> Author: murray Date: 2013-12-19 08:32:03 +0100 (Thu, 19 Dec 2013) New Revision: 585 Modified: pkg/vignettes/RProtoBuf-intro.Rnw Log: Add a short note about how user-defined fields take precedence/mask any pseudo methods of the same name since we can always invoke the methods directly. Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 07:25:58 UTC (rev 584) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 07:32:03 UTC (rev 585) @@ -1840,6 +1840,11 @@ \item names for top-level extensions \end{itemize} +In the unlikely event that there is a user-defined field of exactly +the same name as one of the pseudo methods, the user-defined field +shall take precedence for completion purposes by design, since the +method name can always be invoked directly. + \subsection{with and within} The S3 generic \texttt{with} function is implemented for class From noreply at r-forge.r-project.org Thu Dec 19 08:44:38 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 08:44:38 +0100 (CET) Subject: [Rprotobuf-commits] r586 - in pkg: R vignettes Message-ID: <20131219074438.3F0BC185D16@r-forge.r-project.org> Author: murray Date: 2013-12-19 08:44:37 +0100 (Thu, 19 Dec 2013) New Revision: 586 Modified: pkg/R/containing_type.R pkg/vignettes/RProtoBuf-intro.Rnw Log: Fix a bug in containing_type() for EnumDescriptors which tries to reference a non-existant slot. Modified: pkg/R/containing_type.R =================================================================== --- pkg/R/containing_type.R 2013-12-19 07:32:03 UTC (rev 585) +++ pkg/R/containing_type.R 2013-12-19 07:44:37 UTC (rev 586) @@ -15,9 +15,9 @@ } ) setMethod( "containing_type", "EnumDescriptor", function(object){ retval <- .Call( "EnumDescriptor__containing_type", object at pointer, PACKAGE = "RProtoBuf" ) - if (length(retval at name) == 0) { - # If this enum type is nested in a message type, this is that message type. - # Otherwise, NULL. + if (length(name(retval)) == 0) { + # If this enum type is nested in a message type, this + # is that message type. Otherwise, NULL. return(NULL) } else { return(retval) Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 07:32:03 UTC (rev 585) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 07:44:37 UTC (rev 586) @@ -1518,7 +1518,9 @@ The \texttt{containing\_type} method can be used to retrieve the descriptor for the message type that contains this enum descriptor. -TODO(ms): seems broken, fix it! +<<>>= +tutorial.Person$PhoneType$containing_type() +@ \subsubsection{length} \label{enumdescriptor-method-length} From noreply at r-forge.r-project.org Thu Dec 19 08:55:15 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 19 Dec 2013 08:55:15 +0100 (CET) Subject: [Rprotobuf-commits] r587 - pkg/vignettes Message-ID: <20131219075516.09E70186824@r-forge.r-project.org> Author: murray Date: 2013-12-19 08:55:14 +0100 (Thu, 19 Dec 2013) New Revision: 587 Modified: pkg/vignettes/RProtoBuf-intro.Rnw Log: Address some TODOs, add a blurb about better documenting extensions in the plans for future releases. Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 07:44:37 UTC (rev 586) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 07:55:14 UTC (rev 587) @@ -1163,12 +1163,10 @@ \texttt{label} & \ref{fielddescriptor-method-label} & Gets the label of a field (optional, required, or repeated).\\ \texttt{is\_repeated} & \ref{fielddescriptor-method-isrepeated} & Return TRUE if this field is repeated.\\ \texttt{is\_required} & \ref{fielddescriptor-method-isrequired} & Return TRUE if this field is required.\\ -\texttt{is\_optional} & \ref{fielddescriptor-method-isoptional} & Return TRUE if htis field is optional.\\ -\texttt{has\_default\_value} & \ref{fielddescriptor-method-hasdefaultvalue} & -Return TRUE if this field has a default value.\\ +\texttt{is\_optional} & \ref{fielddescriptor-method-isoptional} & Return TRUE if this field is optional.\\ +\texttt{has\_default\_value} & \ref{fielddescriptor-method-hasdefaultvalue} & Return TRUE if this field has a default value.\\ \texttt{default\_value} & \ref{fielddescriptor-method-defaultvalue} & Return the default value.\\ -\texttt{is\_optional} & \ref{fielddescriptor-method-isoptional} & Return TRUE if htis field is optional.\\ \texttt{message\_type} & \ref{fielddescriptor-method-messagetype} & Return the message type if this is a message type field.\\ \texttt{enum\_type} & \ref{fielddescriptor-method-enumtype} & Return the enum type if this is an enum type field.\\ \hline @@ -1328,9 +1326,6 @@ tutorial.Person$id$is_optional() @ - -\texttt{has\_default\_value} & \ref{fielddescriptor-method-hasdefaultvalue} & -Return TRUE if this field has a default value.\\ \subsubsection{has\_default\_value} \label{fielddescriptor-method-hasdefaultvalue} @@ -1342,20 +1337,16 @@ has_default_value(tutorial.Person$PhoneNumber$number) @ -\texttt{default\_value} & \ref{fielddescriptor-method-defaultvalue} & -Return the default value.\\ -\subsubsection{is\_optional} -\label{fielddescriptor-method-isoptional} +\subsubsection{default\_value} +\label{fielddescriptor-method-defaultvalue} -The \texttt{is\_optional} method returns TRUE if this field is optional. +The \texttt{default\_value} method returns the default value of a field. <<>>= -is_optional( tutorial.Person$id ) -tutorial.Person$id$is_optional() +default_value( tutorial.Person$PhoneNumber$type ) +default_value( tutorial.Person$PhoneNumber$number ) @ - - \subsubsection{message\_type} \label{fielddescriptor-method-messagetype} @@ -1798,12 +1789,18 @@ \subsection{service descriptors} \label{subsec-ServiceDescriptor} -TODO: add content or remove? +Not fully implemented. Needs to be connected to a concrete RPC +implementation. The Google Protocol Buffers C++ open-source library +does not include an RPC implementation, but this can be connected +easily to others. \subsection{method descriptors} \label{subsec-MethodDescriptor} -TODO: add content or remove? +Not fully implemented. Needs to be connected to a concrete RPC +implementation. The Google Protocol Buffers C++ open-source library +does not include an RPC implementation, but this can be connected +easily to others. \section{Utilities} @@ -2022,6 +2019,11 @@ and client code as well, probably based on the functionality of the \texttt{Rserve} package. +Extensions have been implemented in RProtoBuf and have been +extensively used and tested, but they are not currently described in +this vignette. Additional examples and documentation are needed for +extensions. + % \section{Troubleshouting} \section{Acknowledgments} From noreply at r-forge.r-project.org Sat Dec 21 01:16:54 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 21 Dec 2013 01:16:54 +0100 (CET) Subject: [Rprotobuf-commits] r588 - in pkg: . R vignettes Message-ID: <20131221001654.AB5BD186102@r-forge.r-project.org> Author: murray Date: 2013-12-21 01:16:54 +0100 (Sat, 21 Dec 2013) New Revision: 588 Modified: pkg/ChangeLog pkg/R/00classes.R pkg/vignettes/RProtoBuf-intro.Rnw Log: Fix a bug in as.list() for descriptor objects, and document this method in the vignette. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-19 07:55:14 UTC (rev 587) +++ pkg/ChangeLog 2013-12-21 00:16:54 UTC (rev 588) @@ -1,3 +1,8 @@ +2013-12-20 Murray Stokely + + * R/00classes.R: Correct a bug that incorrectly dispatched + as.character() when as.list() was called on Descriptor objects. + 2013-12-18 Murray Stokely * R/completion.R (.DollarNames.EnumValueDescriptor): Add Modified: pkg/R/00classes.R =================================================================== --- pkg/R/00classes.R 2013-12-19 07:55:14 UTC (rev 587) +++ pkg/R/00classes.R 2013-12-21 00:16:54 UTC (rev 588) @@ -206,7 +206,7 @@ "readASCII" = function( input ) readASCII( x, input ), "toString" = function(...) toString(x, ...) , "as.character" = function(...) as.character(x, ...) , - "as.list" = function(...) as.character(x, ...) , + "as.list" = function(...) as.list(x, ...) , "asMessage" = function() asMessage(x), "fileDescriptor" = function() fileDescriptor(x ), "name" = function(...) name(x, ... ), Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-19 07:55:14 UTC (rev 587) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-21 00:16:54 UTC (rev 588) @@ -884,6 +884,8 @@ this descriptor.\\ \texttt{as.character} & \ref{Descriptor-method-ascharacter} & character representation of a descriptor\\ \texttt{toString} & \ref{Descriptor-method-tostring} & character representation of a descriptor (same as \texttt{as.character}) \\ +\texttt{as.list} & \ref{Descriptor-method-aslist} & return a named +list of the field, enum, and nested descriptors included in this descriptor.\\ \texttt{asMessage} & \ref{Descriptor-method-asmessage} & return DescriptorProto message. \\ \hline @@ -1003,6 +1005,16 @@ writeLines( as.character(tutorial.Person) ) @ +\subsubsection{as.list} +\label{Descriptor-method-aslist} + +The \texttt{as.list} method returns a named list of the field, enum, +and nested descriptors included in this descriptor. + +<<>>= +tutorial.Person$as.list() +@ + \subsubsection{asMessage} \label{Descriptor-method-asmessage} From noreply at r-forge.r-project.org Sat Dec 21 01:34:43 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 21 Dec 2013 01:34:43 +0100 (CET) Subject: [Rprotobuf-commits] r589 - papers/rjournal Message-ID: <20131221003443.622A31868CB@r-forge.r-project.org> Author: murray Date: 2013-12-21 01:34:42 +0100 (Sat, 21 Dec 2013) New Revision: 589 Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw papers/rjournal/eddelbuettel-francois-stokely.bib Log: Flesh out the "Under the hood: S4 Classes, Methods, and Pseudo Methods" section by describing how we wrap over 100 functions of 6 main classes with Rcpp. How this exercise partially motivated the development of Rcpp Modules, and add concise tables of the methods for descriptors and field descriptors rather than going through and providing examples of every function like we do in the other vignette. Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-21 00:16:54 UTC (rev 588) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-21 00:34:42 UTC (rev 589) @@ -412,35 +412,72 @@ \section{Under the hood: S4 Classes, Methods, and Pseudo Methods} The \CRANpkg{RProtoBuf} package uses the S4 system to store -information about descriptors and messages, but the information stored -in the R object is very minimal and mainly consists of an external -pointer to a C++ variable that is managed by the \texttt{protobuf} C++ -library. - -Using the S4 system allows the \texttt{RProtoBuf} package to dispatch -methods that are not generic in the S3 sense, such as \texttt{new} and +information about descriptors and messages. Using the S4 system +allows the \texttt{RProtoBuf} package to dispatch methods that are not +generic in the S3 sense, such as \texttt{new} and \texttt{serialize}. +Each R object stores an external pointer to an object managed by +the \texttt{protobuf} C++ library. +The \CRANpkg{Rcpp} \citep{eddelbuettel2011rcpp} package is used to +facilitate the integration of the R and C++ code for these objects. + +% Message, Descriptor, FieldDescriptor, EnumDescriptor, +% FileDescriptor, EnumValueDescriptor +% +% grep RPB_FUNC * | grep -v define|wc -l +% 84 +% grep RPB_ * | grep -v RPB_FUNCTION | grep METHOD|wc -l +% 33 + +There are over 100 C++ functions that provide the glue code between +the member functions of the 6 primary Message and Descriptor classes +in the protobuf library. Wrapping each method individually allows us +to add user friendly custom error handling, type coercion, and +performance improvements at the cost of a more verbose +implementation. The RProtoBuf implementation in many ways motivated +the development of Rcpp Modules \citep{eddelbuettel2010exposing}, +which provide a more concise way of wrapping C++ functions and classes +in a single entity. + The \texttt{RProtoBuf} package combines the \emph{R typical} dispatch of the form \verb|method( object, arguments)| and the more traditional object oriented notation \verb|object$method(arguments)|. -TODO(ms): Perhaps a table here of the different S4 classes, how many +\emph{TODO(ms): Perhaps a table here of the different S4 classes, how many methods they include, whether it dynamically does dispatch on other -strings, whether/how it is available in the search path, etc. +strings, whether/how it is available in the search path, etc.} \subsection{Messages} The \texttt{Message} S4 class represents Protocol Buffer Messages and -is the core abstraction of \CRANpkg{RProtoBuf}. Each \texttt{Message} -has a \texttt{Descriptor} S4 class which defines the schema of the -data defined in the Message, as well as a number of -\texttt{FieldDescriptors} for the individual fields of the message. +is the core abstraction of \CRANpkg{RProtoBuf}. The class contains +the slots \texttt{pointer} and \texttt{type} as described on the +Table~\ref{Message-class-table}. +\begin{table}[h] +\centering +\begin{tabular}{|cp{10cm}|} +\hline +\textbf{Slot} & \textbf{Description} \\ +\hline +\texttt{pointer} & External pointer to the \texttt{Message} object of the C++ proto library. Documentation for the +\texttt{Message} class is available from the protocol buffer project page: +\url{http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.message.html#Message} \\ +\hline +\texttt{type} & Fully qualified name of the message. For example a \texttt{Person} message +has its \texttt{type} slot set to \texttt{tutorial.Person} \\ +\hline +\end{tabular} +\caption{\label{Message-class-table}Description of slots for the \texttt{Message} S4 class} +\end{table} -represented in R using the \texttt{Message} -S4 class. The class contains the slots \texttt{pointer} and \texttt{type} as -described on the Table~\ref{Message-class-table}. +Each \texttt{Message} contains a pointer to a \texttt{Descriptor} +which defines the schema of the data defined in the Message, as well +as a number of \texttt{FieldDescriptors} for the individual fields of +the message. In addition to the field name extractors of +\texttt{Messages} introduced in the previous section, a complete list +of Message methods is available in Table~\ref{Message-methods-table}. \begin{table}[h] \centering @@ -487,30 +524,23 @@ \centering \begin{tabular}{|cp{10cm}|} \hline -\textbf{slot} & \textbf{description} \\ +\textbf{Slot} & \textbf{Description} \\ \hline -\texttt{pointer} & external pointer to the \texttt{Descriptor} object of the C++ proto library. Documentation for the +\texttt{pointer} & External pointer to the \texttt{Descriptor} object of the C++ proto library. Documentation for the \texttt{Descriptor} class is available from the protocol buffer project page: \url{http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.descriptor.html#Descriptor} \\ \hline -\texttt{type} & fully qualified path of the message type. \\ +\texttt{type} & Fully qualified path of the message type. \\ \hline \end{tabular} \caption{\label{Descriptor-class-table}Description of slots for the \texttt{Descriptor} S4 class} \end{table} -Similarly to messages, the \verb|$| operator can be used to extract -information from the descriptor, or invoke pseuso-methods. +Similarly to messages, the \verb|$| operator can be used to retrieve +descriptors that are contained in the descriptor, or invoke +pseudo-methods. Thise can be used to extract field descriptors, enum +descriptors, or descriptors for a nested type. -\subsubsection{Extracting descriptors} - -The \verb|$| operator, when used on a descriptor object retrieves -descriptors that are contained in the descriptor. - -This can be a field descriptor (see section~\ref{subsec-field-descriptor} ), -an enum descriptor (see section~\ref{subsec-enum-descriptor}) or a descriptor -for a nested type - <<>>= # field descriptor tutorial.Person$email @@ -524,6 +554,9 @@ tutorial.Person.PhoneNumber @ +Table~\ref{Descriptor-methods-table} provides a complete list of the +avalailable methods for Descriptors. + \begin{table}[h] \centering \begin{small} @@ -540,6 +573,9 @@ this descriptor.\\ \texttt{as.character} & character representation of a descriptor\\ \texttt{toString} & character representation of a descriptor (same as \texttt{as.character}) \\ +\texttt{as.list} & return a named +list of the field, enum, and nested descriptors included in this descriptor.\\ +\texttt{asMessage} & return DescriptorProto message. \\ \hline \texttt{fileDescriptor} & Retrieve the file descriptor of this descriptor.\\ @@ -558,6 +594,67 @@ \caption{\label{Descriptor-methods-table}Description of methods for the \texttt{Descriptor} S4 class} \end{table} +\subsection{field descriptors} +\label{subsec-field-descriptor} + +The class \emph{FieldDescriptor} represents field +descriptor in R. This is a wrapper S4 class around the +\texttt{google::protobuf::FieldDescriptor} C++ class. +Table~\ref{fielddescriptor-methods-table} describes the methods +defined for the \texttt{FieldDescriptor} class. + +\begin{table}[h] +\centering +\begin{tabular}{|cp{10cm}|} +\hline +\textbf{Slot} & \textbf{Description} \\ +\hline +\texttt{pointer} & External pointer to the \texttt{FieldDescriptor} C++ variable \\ +\hline +\texttt{name} & Simple name of the field \\ +\hline +\texttt{full\_name} & Fully qualified name of the field \\ +\hline +\texttt{type} & Name of the message type where the field is declared \\ +\hline +\end{tabular} +\caption{\label{FieldDescriptor-class-table}Description of slots for the \texttt{FieldDescriptor} S4 class} +\end{table} + + +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{l|l} +\hline +\textbf{Method} & \textbf{Description} \\ +\hline +\hline +\texttt{as.character} & Character representation of a descriptor\\ +\texttt{toString} & Character +representation of a descriptor (same as \texttt{as.character}) \\ +\texttt{asMessage} & Return FieldDescriptorProto message. \\ +\texttt{name} & Return the name of the field descriptor.\\ +\texttt{fileDescriptor} & Return the fileDescriptor where this field is defined.\\ +\texttt{containing\_type} & Return the containing descriptor of this field.\\ +\texttt{is\_extension} & Return TRUE if this field is an extension.\\ +\texttt{number} & Gets the declared tag number of the field.\\ +\texttt{type} & Gets the type of the field.\\ +\texttt{cpp\_type} & Gets the C++ type of the field.\\ +\texttt{label} & Gets the label of a field (optional, required, or repeated).\\ +\texttt{is\_repeated} & Return TRUE if this field is repeated.\\ +\texttt{is\_required} & Return TRUE if this field is required.\\ +\texttt{is\_optional} & Return TRUE if this field is optional.\\ +\texttt{has\_default\_value} & Return TRUE if this field has a default value.\\ +\texttt{default\_value} & Return the default value.\\ +\texttt{message\_type} & Return the message type if this is a message type field.\\ +\texttt{enum\_type} & Return the enum type if this is an enum type field.\\ +\hline +\end{tabular} +\end{small} +\caption{\label{fielddescriptor-methods-table}Description of methods for the \texttt{FieldDescriptor} S4 class} +\end{table} + \section{Type Coercion} \subsection{Booleans} Modified: papers/rjournal/eddelbuettel-francois-stokely.bib =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-21 00:16:54 UTC (rev 588) +++ papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-21 00:34:42 UTC (rev 589) @@ -7,6 +7,18 @@ pages={1--18}, year={2011} } + at book{eddelbuettel2013seamless, + title={Seamless R and C++ Integration with Rcpp}, + author={Eddelbuettel, Dirk}, + year={2013}, + publisher={Springer} +} + at article{eddelbuettel2010exposing, + title={Exposing C++ functions and classes with Rcpp modules}, + author={Eddelbuettel, Dirk and Fran{\c{c}}ois, Romain}, + year={2010}, + publisher={Citeseer} +} @inproceedings{cantrill2004dynamic, title={Dynamic Instrumentation of Production Systems.}, author={Cantrill, Bryan and Shapiro, Michael W and Leventhal, Adam H and others}, From noreply at r-forge.r-project.org Sat Dec 21 02:46:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 21 Dec 2013 02:46:35 +0100 (CET) Subject: [Rprotobuf-commits] r590 - papers/rjournal Message-ID: <20131221014635.A462F18630C@r-forge.r-project.org> Author: murray Date: 2013-12-21 02:46:35 +0100 (Sat, 21 Dec 2013) New Revision: 590 Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw Log: Add section on enumdescriptors. Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-21 00:34:42 UTC (rev 589) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-21 01:46:35 UTC (rev 590) @@ -655,6 +655,72 @@ \caption{\label{fielddescriptor-methods-table}Description of methods for the \texttt{FieldDescriptor} S4 class} \end{table} +% TODO(ms): Useful distinction to make -- FieldDescriptor does not do +% separate '$' dispatch like Messages, Descriptors, and +% EnumDescriptors do. Should it? + +\subsection{enum descriptors} +\label{subsec-enum-descriptor} + +The class \emph{EnumDescriptor} is an R wrapper +class around the C++ class \texttt{google::protobuf::EnumDescriptor}. +Table~\ref{enumdescriptor-methods-table} describes the methods +defined for the \texttt{EnumDescriptor} class. + +The \verb|$| operator can be used to retrieve the value of enum +constants contained in the EnumDescriptor, or to invoke +pseudo-methods. + +<<>>= +tutorial.Person$PhoneType +tutorial.Person$PhoneType$WORK +@ + +\begin{table}[h] +\centering +\begin{tabular}{|cp{10cm}|} +\hline +\textbf{Slot} & \textbf{Description} \\ +\hline +\texttt{pointer} & External pointer to the \texttt{EnumDescriptor} C++ variable \\ +\hline +\texttt{name} & Simple name of the enum \\ +\hline +\texttt{full\_name} & Fully qualified name of the enum \\ +\hline +\texttt{type} & Name of the message type where the enum is declared \\ +\hline +\end{tabular} +\caption{\label{EnumDescriptor-class-table}Description of slots for the \texttt{EnumDescriptor} S4 class} +\end{table} + +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{l|l} +\hline +\textbf{Method} & \textbf{Description} \\ +\hline +\hline +\texttt{as.list} & return a named +integer vector with the values of the enum and their names.\\ +\texttt{as.character} & character representation of a descriptor\\ +\texttt{toString} & character +representation of a descriptor (same as \texttt{as.character}) \\ +\texttt{asMessage} & return EnumDescriptorProto message. \\ +\texttt{name} & Return the name of the enum descriptor.\\ +\texttt{fileDescriptor} & Return the fileDescriptor where this field is defined.\\ +\texttt{containing\_type} & Return the containing descriptor of this field.\\ +\texttt{length} & Return the number of constants in this enum.\\ +\texttt{has} & Return TRUE if this enum contains the specified named constant string.\\ +\texttt{value\_count} & Return the number of constants in this enum (same as \texttt{length}).\\ +\texttt{value} & Return the EnumValueDescriptor of an enum value of specified index, name, or number.\\ +\hline +\end{tabular} +\end{small} +\caption{\label{enumdescriptor-methods-table}Description of methods for the \texttt{EnumDescriptor} S4 class} +\end{table} + \section{Type Coercion} \subsection{Booleans} From noreply at r-forge.r-project.org Tue Dec 24 01:36:32 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 24 Dec 2013 01:36:32 +0100 (CET) Subject: [Rprotobuf-commits] r591 - in pkg: . inst inst/proto src vignettes Message-ID: <20131224003632.2E2A718681D@r-forge.r-project.org> Author: murray Date: 2013-12-24 01:36:31 +0100 (Tue, 24 Dec 2013) New Revision: 591 Modified: pkg/ChangeLog pkg/DESCRIPTION pkg/inst/NEWS.Rd pkg/inst/proto/addressbook.proto pkg/src/lookup.cpp pkg/vignettes/RProtoBuf-intro.Rnw Log: Reserve fields for extensions in the example addressbook.proto and use this to better document extensions in the intro vignette (which might be more accurately called a 'complete reference' than a 45-page intro doc). Also update a comment, document other changes made since last release in the NEWS file, and increment the version number. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-21 01:46:35 UTC (rev 590) +++ pkg/ChangeLog 2013-12-24 00:36:31 UTC (rev 591) @@ -1,3 +1,11 @@ +2013-12-23 Murray Stokely + + * DESCRIPTION (Version): increment. + * inst/proto/addressbook.proto: Reserved extension fields in + tutorial.Person. + * vignettes/RProtoBuf-intro.Rnw (subsection{Extensions}): Added a + new section documenting protocol buffer extensions. + 2013-12-20 Murray Stokely * R/00classes.R: Correct a bug that incorrectly dispatched Modified: pkg/DESCRIPTION =================================================================== --- pkg/DESCRIPTION 2013-12-21 01:46:35 UTC (rev 590) +++ pkg/DESCRIPTION 2013-12-24 00:36:31 UTC (rev 591) @@ -1,5 +1,5 @@ Package: RProtoBuf -Version: 0.3.2.2 +Version: 0.3.2.3 Date: $Date$ Author: Romain Francois, Dirk Eddelbuettel and Murray Stokely Maintainer: Dirk Eddelbuettel Modified: pkg/inst/NEWS.Rd =================================================================== --- pkg/inst/NEWS.Rd 2013-12-21 01:46:35 UTC (rev 590) +++ pkg/inst/NEWS.Rd 2013-12-24 00:36:31 UTC (rev 591) @@ -2,10 +2,23 @@ \title{News for Package \pkg{RProtoBuf}} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} -\section{Changes in UNRELEASED RProtoBuf version 0.3.3 (2013-12-18)}{ +\section{Changes in UNRELEASED RProtoBuf version 0.3.3 (2013-12-23)}{ \itemize{ \item Vignettes have been converted to the R 3.0.0 or later use of external vignette builders, no longer need a \code{Makefile} + \item Added missing methods to dollar completion list for Message, + Descriptor, EnumValueDescriptor, and FileDescriptor classes. + \item Add more than 10 additional pages to the main Intro vignette + documenting better all of the S4 classes implemented by RProtoBuf and + advanced features such as Extensions. + \item Added better error checking in EnumDescriptors to catch the + case when wrong types are provided. + \item Updated the FileDescriptor \code{name()} method to accept a boolean + for full paths just like the generic \code{name()} method. + \item Correct a bug that incorrectly dispatched \code{as.character()} when + \code{as.list()} was called on Descriptor objects. + \item Added a reservation for extension fields in the example + tutorial.Person schema. } } Modified: pkg/inst/proto/addressbook.proto =================================================================== --- pkg/inst/proto/addressbook.proto 2013-12-21 01:46:35 UTC (rev 590) +++ pkg/inst/proto/addressbook.proto 2013-12-24 00:36:31 UTC (rev 591) @@ -15,6 +15,7 @@ optional PhoneType type = 2 [default = HOME]; } repeated PhoneNumber phone = 4; + extensions 100 to 199; } message AddressBook { repeated Person person = 1; Modified: pkg/src/lookup.cpp =================================================================== --- pkg/src/lookup.cpp 2013-12-21 01:46:35 UTC (rev 590) +++ pkg/src/lookup.cpp 2013-12-24 00:36:31 UTC (rev 591) @@ -171,7 +171,11 @@ } /** - * Generates an error. assign is not possible on this lookup table + * Previously this function returned a stop() error, but this has side + * effects such as preventing users from using '<<-' operator in any + * scripts that include RProtoBuf. So instead, we now simply return + * NULL to indicate assign is not possible on this lookup talbe + * without giving such a hard error. */ SEXP rProtoBufTable_assign(const char * const name, SEXP value, R_ObjectTable *tb){ #ifdef LOOKUP_DEBUG Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-21 01:46:35 UTC (rev 590) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-24 00:36:31 UTC (rev 591) @@ -87,14 +87,14 @@ The protocol buffer project page contains a comprehensive description of the language: \url{http://code.google.com/apis/protocolbuffers/docs/proto.html} -\section{Dynamic use: Protocol Buffers and R} +\section{Basic use: Protocol Buffers and R} This section describes how to use the R API to create and manipulate protocol buffer messages in R, and how to read and write the binary \emph{payload} of the messages to files and arbitrary binary R connections. -\subsection{Importing proto files} +\subsection{Importing proto files dynamically} In contrast to the other languages (Java, C++, Python) that are officially supported by Google, the implementation used by the \texttt{RProtoBuf} @@ -1927,7 +1927,62 @@ new( tutorial.Person ) @ -\section{Descriptor lookup} +\section{Advanced Features} +\subsection{Extensions} +\label{sec-extensions} + +Extensions allow you to declare a range of field numbers in a message +that are available for extension types. This allows others to declare +new fields for a given message type possibly in their own +\texttt{.proto} files without having to edit the original file. See +\url{https://developers.google.com/protocol-buffers/docs/proto#extensions}. + +Notice that the last line of the \texttt{Person} message schema in +\texttt{addressbook.proto} is the following line : + +\begin{verbatim} + extensions 100 to 199; +\end{verbatim} + +This specifies that other users in other .proto files can use tag +numbers between 100 and 199 for extention types of this message. + +For example, the following file \texttt{extend.proto}: + +<>= + extend.proto <- tempfile() + writeLines(c( + paste0('import "', system.file("proto/addressbook.proto", + package="RProtoBuf"), '";'), + "package tutorial;", + paste0("extend Person {\n optional string nationality = 100;\n}")), + extend.proto) +@ + +<>= +writeLines(readLines(extend.proto)) +@ + +After importing this new \texttt{.proto} file with an extension +defined, we can get or set the value of this extension in Messages of +type \texttt{Person}. + +<<>>= +library(RProtoBuf) +readProtoFiles(extend.proto) +person <- new(tutorial.Person, id=1, name="Murray") +person +person$setExtension(P("tutorial.nationality"), "USA") +cat(as.character(person)) +person$getExtension(P("tutorial.nationality")) +@ + +The character output of this message places the extension type in +brackets to differentiate it from other fields in the message, and so +we know we need to use the \texttt{getExtension} method rather than a +'\$' field extractor to get the value. + +\subsection{Descriptor lookup} \label{sec-lookup} The \texttt{RProtoBuf} package uses the user defined tables framework @@ -1944,7 +1999,7 @@ implemented by the \texttt{RProtoBuf} package by calling an internal method of the \texttt{protobuf} C++ library. -\section{64-bit integer issues} +\subsection{64-bit integer issues} \label{sec:int64} R does not have native 64-bit integer support. Instead, R treats From edd at debian.org Tue Dec 24 05:03:07 2013 From: edd at debian.org (Dirk Eddelbuettel) Date: Mon, 23 Dec 2013 22:03:07 -0600 Subject: [Rprotobuf-commits] r591 - in pkg: . inst inst/proto src vignettes In-Reply-To: <20131224003632.2E2A718681D@r-forge.r-project.org> References: <20131224003632.2E2A718681D@r-forge.r-project.org> Message-ID: <21177.1915.194241.623328@max.nulle.part> On 24 December 2013 at 01:36, noreply at r-forge.r-project.org wrote: | Author: murray | Date: 2013-12-24 01:36:31 +0100 (Tue, 24 Dec 2013) | New Revision: 591 | | Modified: | pkg/ChangeLog | pkg/DESCRIPTION | pkg/inst/NEWS.Rd | pkg/inst/proto/addressbook.proto | pkg/src/lookup.cpp | pkg/vignettes/RProtoBuf-intro.Rnw | Log: | Reserve fields for extensions in the example addressbook.proto and use | this to better document extensions in the intro vignette (which might | be more accurately called a 'complete reference' than a 45-page intro :-) I'd be fine with a renaming. | doc). Also update a comment, document other changes made since last | release in the NEWS file, and increment the version number. Thanks for all the continued support. I'll catch up. Dirk -- Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com From noreply at r-forge.r-project.org Thu Dec 26 23:42:30 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Thu, 26 Dec 2013 23:42:30 +0100 (CET) Subject: [Rprotobuf-commits] r592 - in pkg: . R vignettes Message-ID: <20131226224230.70CA5181273@r-forge.r-project.org> Author: murray Date: 2013-12-26 23:42:30 +0100 (Thu, 26 Dec 2013) New Revision: 592 Modified: pkg/ChangeLog pkg/R/00classes.R pkg/vignettes/RProtoBuf-intro.Rnw Log: Update FileDescriptor '$' dispatch to work properly for the names of fields defiend in the FileDescriptor, instead of just returning NULL even for types returend by $ completion. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-24 00:36:31 UTC (rev 591) +++ pkg/ChangeLog 2013-12-26 22:42:30 UTC (rev 592) @@ -1,3 +1,10 @@ +2013-12-26 Murray Stokely + + * R/00classes.R: Update FileDescriptor '$' dispatch to work + properly for the names of fields defined in the FileDescriptor, + instead of just returning NULL even for types returned by $ + completion. + 2013-12-23 Murray Stokely * DESCRIPTION (Version): increment. Modified: pkg/R/00classes.R =================================================================== --- pkg/R/00classes.R 2013-12-24 00:36:31 UTC (rev 591) +++ pkg/R/00classes.R 2013-12-26 22:42:30 UTC (rev 592) @@ -290,7 +290,7 @@ "as.list" = function() as.list(x), "name" = function(...) name(x, ... ), "package" = function() x at package, - invisible(NULL) + as.list(x)[[name]] ) }) Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-24 00:36:31 UTC (rev 591) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-26 22:42:30 UTC (rev 592) @@ -1710,10 +1710,16 @@ \end{table} Similarly to messages, the \verb|$| operator can be used to extract -information from the file descriptor, or invoke pseuso-methods. +fields from the file descriptor (in this case, types defined in the +file), or invoke pseuso-methods. Table~\ref{filedescriptor-methods-table} describes the methods defined for the \texttt{FileDescriptor} class. +<<>>= +f <- tutorial.Person$fileDescriptor() +f +f$Person +@ \begin{table}[h] \centering \begin{small} From noreply at r-forge.r-project.org Fri Dec 27 00:22:28 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 00:22:28 +0100 (CET) Subject: [Rprotobuf-commits] r593 - in pkg: . R Message-ID: <20131226232228.37ED218659F@r-forge.r-project.org> Author: murray Date: 2013-12-27 00:22:27 +0100 (Fri, 27 Dec 2013) New Revision: 593 Modified: pkg/ChangeLog pkg/NAMESPACE pkg/R/completion.R Log: Add missing export to allow $ completion of EnumValueDescriptor and fix a typo. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-26 22:42:30 UTC (rev 592) +++ pkg/ChangeLog 2013-12-26 23:22:27 UTC (rev 593) @@ -1,5 +1,7 @@ 2013-12-26 Murray Stokely + * NAMESPACE: Add missing export for .DollarNames + EnumValueDescriptor to allow completion on that class. * R/00classes.R: Update FileDescriptor '$' dispatch to work properly for the names of fields defined in the FileDescriptor, instead of just returning NULL even for types returned by $ Modified: pkg/NAMESPACE =================================================================== --- pkg/NAMESPACE 2013-12-26 22:42:30 UTC (rev 592) +++ pkg/NAMESPACE 2013-12-26 23:22:27 UTC (rev 593) @@ -83,6 +83,7 @@ S3method(.DollarNames, Message ) S3method(.DollarNames, Descriptor ) S3method(.DollarNames, EnumDescriptor ) +S3method(.DollarNames, EnumValueDescriptor ) S3method(.DollarNames, FileDescriptor ) S3method(.DollarNames, FieldDescriptor ) S3method(.DollarNames, ServiceDescriptor ) Modified: pkg/R/completion.R =================================================================== --- pkg/R/completion.R 2013-12-26 22:42:30 UTC (rev 592) +++ pkg/R/completion.R 2013-12-26 23:22:27 UTC (rev 593) @@ -65,7 +65,7 @@ "is_extension()", "number()", "type(", "cpp_type(", "label(", "is_repeated()", "is_required()", "is_optional()", "message_type()", "enum_type()", "asMessage()", - "has_default_value()", "default_value(", + "has_default_value()", "default_value(" ) grep( pattern, names, value = TRUE ) } From noreply at r-forge.r-project.org Fri Dec 27 00:42:33 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 00:42:33 +0100 (CET) Subject: [Rprotobuf-commits] r594 - papers/rjournal Message-ID: <20131226234233.637E5181372@r-forge.r-project.org> Author: murray Date: 2013-12-27 00:42:33 +0100 (Fri, 27 Dec 2013) New Revision: 594 Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw Log: Document file descriptors and enumvalue descriptors, and add a summary table showing the number of slots, methods, and dynamically dispatched fields of each class. Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-26 23:22:27 UTC (rev 593) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-26 23:42:33 UTC (rev 594) @@ -343,7 +343,7 @@ readBin( tf2, raw(0), 500 ) @ -\texttt{serialize} can also be used in a more traditionnal +\texttt{serialize} can also be used in a more traditional object oriented fashion using the dollar operator : <<>>= @@ -443,10 +443,33 @@ The \texttt{RProtoBuf} package combines the \emph{R typical} dispatch of the form \verb|method( object, arguments)| and the more traditional object oriented notation \verb|object$method(arguments)|. +Additionally, \texttt{RProtoBuf} implements the \texttt{.DollarNames} S3 generic function +(defined in the \texttt{utils} package) for all classes to enable tab +completion. Completion possibilities include pseudo method names for all +classes, plus dynamic dispatch on names or types specific to a given object. -\emph{TODO(ms): Perhaps a table here of the different S4 classes, how many -methods they include, whether it dynamically does dispatch on other -strings, whether/how it is available in the search path, etc.} +% TODO(ms): Add column check box for doing dynamic dispatch based on type. +\begin{table}[h] +\centering +\begin{tabular}{|l|c|c|l|} +\hline +\textbf{Class} & \textbf{Slots} & \textbf{Methods} & \textbf{Dynamic Dispatch}\\ +\hline +\hline +Message & 2 & 20 & yes (field names)\\ +\hline +Descriptor & 2 & 16 & yes (field names, enum types, nested types)\\ +\hline +FieldDescriptor & 4 & 18 & no\\ +\hline +EnumDescriptor & 4 & 11 & yes (enum constant names)\\ +\hline +FileDescriptor & 3 & 6 & yes (message/field definitions)\\ +\hline +EnumValueDescriptor & 3 & 6 & no\\ +\hline +\end{tabular} +\end{table} \subsection{Messages} @@ -721,6 +744,113 @@ \caption{\label{enumdescriptor-methods-table}Description of methods for the \texttt{EnumDescriptor} S4 class} \end{table} +\subsection{file descriptors} +\label{subsec-file-descriptor} + +The class \emph{FileDescriptor} is an R wrapper +class around the C++ class \texttt{google::protobuf::FileDescriptor}. +Table~\ref{filedescriptor-methods-table} describes the methods +defined for the \texttt{FileDescriptor} class. + +The \verb|$| operator can be used to retrieve named fields defined in +the FileDescriptor, or to invoke pseudo-methods. + +<<>>= +f <- tutorial.Person$fileDescriptor() +f +f$Person +@ + +\begin{table}[h] +\centering +\begin{tabular}{|cp{10cm}|} +\hline +\textbf{slot} & \textbf{description} \\ +\hline +\texttt{pointer} & external pointer to the \texttt{FileDescriptor} object of the C++ proto library. Documentation for the +\texttt{FileDescriptor} class is available from the protocol buffer project page: +\url{http://developers.google.com/protocol-buffers/docs/reference/cpp/google.protobuf.descriptor.html#FileDescriptor} \\ +\hline +\texttt{filename} & fully qualified pathname of the \texttt{.proto} file.\\ +\hline +\texttt{package} & package name defined in this \texttt{.proto} file.\\ +\hline +\end{tabular} +\caption{\label{FileDescriptor-class-table}Description of slots for the \texttt{FileDescriptor} S4 class} +\end{table} + +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{l|l} +\hline +\textbf{Method} & \textbf{Description} \\ +\hline +\hline +\texttt{name} & Return the filename for this FileDescriptorProto.\\ +\texttt{package} & Return the file-level package name specified in this FileDescriptorProto.\\ +\texttt{as.character} & character representation of a descriptor. \\ +\texttt{toString} & character representation of a descriptor (same as \texttt{as.character}). \\ +\texttt{asMessage} & return FileDescriptorProto message. \\ +\texttt{as.list} & return named list of descriptors defined in this file descriptor.\\ +\hline +\end{tabular} +\end{small} +\caption{\label{filedescriptor-methods-table}Description of methods for the \texttt{FileDescriptor} S4 class} +\end{table} + +\subsection{enum value descriptors} +\label{subsec-enumvalue-descriptor} + +The class \emph{EnumValueDescriptor} is an R wrapper +class around the C++ class \texttt{google::protobuf::EnumValueDescriptor}. +Table~\ref{EnumValueDescriptor-methods-table} describes the methods +defined for the \texttt{EnumValueDescriptor} class. + +The \verb|$| operator can be used to invoke pseudo-methods. + +<<>>= +tutorial.Person$PhoneType$value(1) +tutorial.Person$PhoneType$value(name="HOME") +tutorial.Person$PhoneType$value(number=1) +@ + +\begin{table}[h] +\centering +\begin{tabular}{|cp{10cm}|} +\hline +\textbf{slot} & \textbf{description} \\ +\hline +\texttt{pointer} & External pointer to the \texttt{EnumValueDescriptor} C++ variable \\ +\hline +\texttt{name} & simple name of the enum value \\ +\hline +\texttt{full\_name} & fully qualified name of the enum value \\ +\hline +\end{tabular} +\caption{\label{EnumValueDescriptor-class-table}Description of slots for the \texttt{EnumValueDescriptor} S4 class} +\end{table} + +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{l|l} +\hline +\textbf{Method} & \textbf{Description} \\ +\hline +\hline +\texttt{number} & return the number of this EnumValueDescriptor. \\ +\texttt{name} & Return the name of the enum value descriptor.\\ +\texttt{enum\_type} & return the EnumDescriptor type of this EnumValueDescriptor. \\ +\texttt{as.character} & character representation of a descriptor. \\ +\texttt{toString} & character representation of a descriptor (same as \texttt{as.character}). \\ +\texttt{asMessage} & return EnumValueDescriptorProto message. \\ +\hline +\end{tabular} +\end{small} +\caption{\label{enumvaluedescriptor-methods-table}Description of methods for the \texttt{EnumValueDescriptor} S4 class} +\end{table} + \section{Type Coercion} \subsection{Booleans} From noreply at r-forge.r-project.org Fri Dec 27 02:11:16 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 02:11:16 +0100 (CET) Subject: [Rprotobuf-commits] r595 - in pkg: . src Message-ID: <20131227011116.83DEA181372@r-forge.r-project.org> Author: murray Date: 2013-12-27 02:11:16 +0100 (Fri, 27 Dec 2013) New Revision: 595 Modified: pkg/ChangeLog pkg/src/mutators.cpp Log: Support setting optional and repested int32s from valid decimal character strings just like we do (by necessity) for int64s. Give a stop() error if the string isn't a valid number, as opposed to the current behavior of crashing R with uncaught exception even when a valid number is provided. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-26 23:42:33 UTC (rev 594) +++ pkg/ChangeLog 2013-12-27 01:11:16 UTC (rev 595) @@ -1,5 +1,7 @@ 2013-12-26 Murray Stokely + * src/mutators.cpp: Support setting int32 values with character + vectors of a decimal number, as we do by necessity for int64s. * NAMESPACE: Add missing export for .DollarNames EnumValueDescriptor to allow completion on that class. * R/00classes.R: Update FileDescriptor '$' dispatch to work Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-26 23:42:33 UTC (rev 594) +++ pkg/src/mutators.cpp 2013-12-27 01:11:16 UTC (rev 595) @@ -83,7 +83,30 @@ return 0 ; // -Wall, should not happen since we only call this when we know it works } +template +ValueType Int64FromString(const string &value) { + std::stringstream ss(value); + ValueType ret; + if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { + string message = "Provided character value '" + value + + "' cannot be cast to 64-bit integer."; + throwException(message.c_str(), "CastException"); + } + return ret; +} +template +ValueType Int32FromString(const string &value) { + std::stringstream ss(value); + ValueType ret; + if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { + string message = "Provided character value '" + value + + "' cannot be cast to 32-bit integer."; + throwException(message.c_str(), "CastException"); + } + return ret; +} + int32 GET_int32( SEXP x, int index ){ switch( TYPEOF(x) ){ case INTSXP: @@ -94,24 +117,14 @@ return( (int32)LOGICAL(x)[index] ); case RAWSXP: return( (int32)RAW(x)[index] ) ; + case STRSXP: + return Int32FromString(CHAR(STRING_ELT(x, index))); default: throwException( "cannot cast SEXP to int32", "CastException" ) ; } return (int32)0 ; // -Wall, should not happen since we only call this when we know it works } -template -ValueType Int64FromString(const string &value) { - std::stringstream ss(value); - ValueType ret; - if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { - string message = "Provided character value '" + value + - "' cannot be cast to 64-bit integer."; - throwException(message.c_str(), "CastException"); - } - return ret; -} - int64 GET_int64( SEXP x, int index ){ switch( TYPEOF(x) ){ case INTSXP: @@ -140,6 +153,8 @@ return( (uint32)LOGICAL(x)[index] ); case RAWSXP: return( (uint32)RAW(x)[index] ) ; + case STRSXP: + return Int32FromString(CHAR(STRING_ELT(x, index))); default: throwException( "cannot cast SEXP to uint32", "CastException" ) ; } @@ -583,6 +598,7 @@ case REALSXP: case LGLSXP: case RAWSXP: + case STRSXP: // For int32, we support chars. { int i = 0; /* in any case, fill the values up to field_size */ @@ -599,6 +615,7 @@ break ; } + default: { throwException( "Cannot convert to int32", "ConversionException" ) ; @@ -652,6 +669,7 @@ case REALSXP: case LGLSXP: case RAWSXP: + case STRSXP: // For int32, we support chars. { int i = 0; /* in any case, fill the values up to field_size */ @@ -667,6 +685,7 @@ } break ; } + default: throwException( "Cannot convert to uint32", "ConversionException" ) ; } @@ -1025,11 +1044,36 @@ break ; \ } - HANDLE_SINGLE_FIELD( CPPTYPE_INT32, Int32, GPB::int32) ; - HANDLE_SINGLE_FIELD( CPPTYPE_UINT32, UInt32, GPB::uint32) ; HANDLE_SINGLE_FIELD( CPPTYPE_DOUBLE, Double, double) ; HANDLE_SINGLE_FIELD( CPPTYPE_FLOAT, Float, float) ; HANDLE_SINGLE_FIELD( CPPTYPE_BOOL, Bool, bool) ; + case CPPTYPE_INT32 : + { + if (TYPEOF(value) == STRSXP) { + const string int32str = COPYSTRING(CHAR( + STRING_ELT(value, 0))); + ref->SetInt32(message, field_desc, + Int32FromString(int32str)); + break ; + } else { + ref->SetInt32( message, field_desc, Rcpp::as(value)); + break; + } + } + case CPPTYPE_UINT32 : + { + if (TYPEOF(value) == STRSXP) { + const string uint32str = COPYSTRING(CHAR( + STRING_ELT(value, 0))); + ref->SetUInt32(message, field_desc, + Int32FromString(uint32str)); + break ; + } else { + ref->SetUInt32( message, field_desc, Rcpp::as(value)); + break; + } + } + #ifdef RCPP_HAS_LONG_LONG_TYPES case CPPTYPE_INT64 : { From noreply at r-forge.r-project.org Fri Dec 27 02:13:18 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 02:13:18 +0100 (CET) Subject: [Rprotobuf-commits] r596 - pkg Message-ID: <20131227011318.2BAA2183CD1@r-forge.r-project.org> Author: murray Date: 2013-12-27 02:13:17 +0100 (Fri, 27 Dec 2013) New Revision: 596 Modified: pkg/ChangeLog Log: Update email address to my google.com one. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-27 01:11:16 UTC (rev 595) +++ pkg/ChangeLog 2013-12-27 01:13:17 UTC (rev 596) @@ -1,4 +1,4 @@ -2013-12-26 Murray Stokely +2013-12-26 Murray Stokely * src/mutators.cpp: Support setting int32 values with character vectors of a decimal number, as we do by necessity for int64s. @@ -9,7 +9,7 @@ instead of just returning NULL even for types returned by $ completion. -2013-12-23 Murray Stokely +2013-12-23 Murray Stokely * DESCRIPTION (Version): increment. * inst/proto/addressbook.proto: Reserved extension fields in @@ -17,12 +17,12 @@ * vignettes/RProtoBuf-intro.Rnw (subsection{Extensions}): Added a new section documenting protocol buffer extensions. -2013-12-20 Murray Stokely +2013-12-20 Murray Stokely * R/00classes.R: Correct a bug that incorrectly dispatched as.character() when as.list() was called on Descriptor objects. -2013-12-18 Murray Stokely +2013-12-18 Murray Stokely * R/completion.R (.DollarNames.EnumValueDescriptor): Add $-completion for EnumValueDescriptor and FileDescriptor classes @@ -44,7 +44,7 @@ * configure.in: No longer create vignettes/Makefile -2013-12-17 Murray Stokely +2013-12-17 Murray Stokely * R/completion.R (.DollarNames.Message): Add missing methods to dollar completion list for Message and Descriptor objects @@ -70,7 +70,7 @@ * R/lookup.R (attachDescriptorPool): No longer attach them here * src/rprotobuf.h: Updated function declaration -2013-12-14 Murray Stokely +2013-12-14 Murray Stokely * src/mutators.cpp (rprotobuf): Fix a bug which incorrectly prevented users from setting raw non-repeated fields under some @@ -79,14 +79,14 @@ set to required bytes fields to verify correct behavior for use case mentioned on rprotobuf-yada list. -2013-11-13 Murray Stokely +2013-11-13 Murray Stokely * R/extensions.R: Give a user friendly error message if someone tries to set an extension to a message of the wrong type instead of causing a C++ check failure that terminates your R session. * inst/unitTests/runit.extensions.R (test.extension): Add test. -2013-10-23 Murray Stokely +2013-10-23 Murray Stokely * src/lookup.cpp (rprotobuf): Remove stop() error in object table assignment as this was causing errors with the '<<-' operator in @@ -94,7 +94,7 @@ * inst/unitTests/runit.import.R (test.assign.in.global): Add a test for the above. -2013-09-16 Murray Stokely +2013-09-16 Murray Stokely * DESCRIPTION (Version): Increment to 0.3.1.1. * R/00classes.R: Improve show method for EnumValueDescriptor and @@ -109,31 +109,31 @@ * DESCRIPTION (Version): Release 0.3.1 -2013-09-13 Murray Stokely +2013-09-13 Murray Stokely * vignettes/Makefile.in: Update configure to output R_HOME to the vignette makefile so we can avoid the use of a non-portable GNU makefile extension here. -2013-09-12 Murray Stokely +2013-09-12 Murray Stokely * src/RcppMacros.h: Add Rcpp compatibility macros which are simplified versions of the now deprecated ones from Rcpp. -2013-09-11 Murray Stokely +2013-09-11 Murray Stokely * configure.in: If pkg-config is not available add -lprotobuf to PKG_LIBS. This makes it easier to install on MacOS X 10.8, for example. -2013-09-06 Murray Stokely +2013-09-06 Murray Stokely * src/rprotobuf.cpp (rprotobuf): Include the name of the field that could not be found in exceptions in getFieldDescriptor (errors from update / new, etc.). -2013-09-03 Murray Stokely +2013-09-03 Murray Stokely * inst/NEWS.Rd: Summarize changes since the last release. * vignettes/RProtoBuf/RProtoBuf.Rnw: Add a new section on 64-bit @@ -148,7 +148,7 @@ * R/*R: Updated several files which no longer need 'tools:::' prefix * DESCRIPTION: Updated Depends: and Imports accordingly -2013-08-29 Murray Stokely +2013-08-29 Murray Stokely * R/zzz.R (.onLoad): Rename option controlling int64 handling with package name prefix. @@ -157,7 +157,7 @@ code duplication in last changelist. * src/mutators.cpp (rprotobuf): Idem -2013-08-27 Murray Stokely +2013-08-27 Murray Stokely * src/extractors.cpp (rprotobuf): Add support for a new option("int64AsString") that controls whether extractors for @@ -175,7 +175,7 @@ identifier needs to be stored. * inst/unitTests/runit.int64.R: Add tests for the above. -2013-08-21 Murray Stokely +2013-08-21 Murray Stokely * inst/unitTests/runit.addressbook.R (test.ascii): Add more tests. * src/wrapper_Descriptor.cpp (rprotobuf): Add better error @@ -204,7 +204,7 @@ * vignettes/RProtoBuf-unitTests.Rnw: Idem * vignettes/RProtoBuf-quickref/RProtoBuf-quickref.Rnw: Idem -2013-07-13 Murray Stokely +2013-07-13 Murray Stokely * inst/NEWS.Rd: Summarize new features since the last CRAN release last year. @@ -221,7 +221,7 @@ rather long time ago * R/zzz.R: Check for minimal version is now commented-out -2013-07-12 Murray Stokely +2013-07-12 Murray Stokely * src/extensions.cpp: Replace custom extractor and mutator with call to existing functions in mutators.cpp and extractors.cpp that @@ -236,7 +236,7 @@ * inst/unitTests/runit.extensions.R: Add additional tests for nested enum and message type extensions. -2013-07-11 Murray Stokely +2013-07-11 Murray Stokely * R/extensions.R: Implement getExtension, setExtension methods. * src/extensions.cpp: Implement getExtension, setExtension. @@ -254,7 +254,7 @@ * src/lookup.cpp: Add support for looking up extensions. * inst/unitTests/runit.extensions.R: Add basic test for the above. -2013-07-10 Murray Stokely +2013-07-10 Murray Stokely * man/aslist.Rd: Document behavior for enum and file descriptors and be more sparing with \dontrun in examples. @@ -275,7 +275,7 @@ * man/with.Rd: Idem * man/RProtoBuf-package.Rd: Idem -2013-07-08 Murray Stokely +2013-07-08 Murray Stokely * R/has.R: add a has method for EnumDescriptor objects to return a logical indicating if the named constant exists or not. @@ -290,7 +290,7 @@ * man/EnumDescriptor-class.Rd: Add example of the above. * man/EnumValueDescriptor-class.Rd: Add example of the above. -2013-02-21 Murray Stokely +2013-02-21 Murray Stokely * R/00classes.R: add filename and package slots to FileDescriptor S4 class and provide more user-friendly show() methods for @@ -304,7 +304,7 @@ * man/FileDescriptor-class.Rd: document the new slots in FileDescriptor and add examples. -2012-10-03 Murray Stokely +2012-10-03 Murray Stokely * src/mutators.cpp (rprotobuf): Fix bug where LENGTH() is used on non-vectors when setting a repeated message field to a single @@ -321,7 +321,7 @@ * man/number.Rd: Idem * man/type.Rd: Idem -2012-09-24 Murray Stokely +2012-09-24 Murray Stokely * R/has.R: Distinguish between non-existant and not-set fields in a message by returning NULL in the former case. @@ -330,7 +330,7 @@ * inst/unitTests/runit.golden.message.R (test.has): Add test. * man/has.Rd: Add example of the above. -2012-09-21 Murray Stokely +2012-09-21 Murray Stokely * Fix a bug causing segfaults in containing_type(). * R/containing_type.R: Return NULL instead of invalid descriptors @@ -344,7 +344,7 @@ * inst/unitTests/runit.FieldDescriptor.R (test.FieldDescriptor.class): Add tests for the above. -2012-08-21 Murray Stokely +2012-08-21 Murray Stokely * src/mutators.cpp: Add better input checking when setting an optional field to avoid an uncaught exception that would kill the From noreply at r-forge.r-project.org Fri Dec 27 02:30:04 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 02:30:04 +0100 (CET) Subject: [Rprotobuf-commits] r597 - pkg/inst/unitTests Message-ID: <20131227013004.77A0D1865B4@r-forge.r-project.org> Author: murray Date: 2013-12-27 02:30:03 +0100 (Fri, 27 Dec 2013) New Revision: 597 Added: pkg/inst/unitTests/runit.int32.R Log: Add a unit test of setting int32 fields with character vectors and make sure we correctly raise exceptions in the appropriate cases rather than crashing R since Rcpp::as can't handle string types. Added: pkg/inst/unitTests/runit.int32.R =================================================================== --- pkg/inst/unitTests/runit.int32.R (rev 0) +++ pkg/inst/unitTests/runit.int32.R 2013-12-27 01:30:03 UTC (rev 597) @@ -0,0 +1,49 @@ +# Copyright 2013 Google Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +test.int32 <- function() { + if (!exists("protobuf_unittest.TestAllTypes", + "RProtoBuf:DescriptorPool")) { + unittest.proto.file <- system.file("unitTests", "data", + "unittest.proto", + package="RProtoBuf") + readProtoFiles(file=unittest.proto.file) + } + + a <- new(protobuf_unittest.TestAllTypes) + a$repeated_int32 <- 1 + # Verify we can set character strings + a$repeated_int32 <- c("9007", "9008") + checkEquals(length(a$repeated_int32), 2) + # Verify we can't set any garbage string to a repeated int32. + checkException(a$repeated_int32 <-c("invalid", "invalid")) + checkException(a$repeated_int32 <-c("33-")) + + a$optional_int32 <- 1 + a$optional_int32 <- "2" + checkEquals(a$optional_int32, 2) + # Verify we can't set any garbage string to an optional int32. + checkException(a$optional_int32 <- "invalid") + + a$optional_uint32 <- 10000 + a$optional_uint32 <- "200000" + checkEquals(a$optional_uint32, 200000) + # Verify we can't set any garbage string to an optional uint32. + checkException(a$optional_uint32 <- "invalid") + + a$repeated_uint32 <- c("9007", "9008") + checkEquals(length(a$repeated_uint32), 2) +} From noreply at r-forge.r-project.org Fri Dec 27 02:53:01 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 02:53:01 +0100 (CET) Subject: [Rprotobuf-commits] r598 - pkg/vignettes Message-ID: <20131227015301.A04B71867ED@r-forge.r-project.org> Author: murray Date: 2013-12-27 02:53:01 +0100 (Fri, 27 Dec 2013) New Revision: 598 Modified: pkg/vignettes/RProtoBuf-intro.Rnw Log: Update the tables describing the correspondance between R types and protobuf types to note that character vectors can be extracted from 64-bit integers when the RProtoBuf.int64AsStrings option is set (and add a reference to the later section where this is explained in more detail). Also, update the table for mutations to note that int32s and int64s can now be set from character vectors (though setting optional_double <- "3.14" will still crash R). Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-27 01:30:03 UTC (rev 597) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-27 01:53:01 UTC (rev 598) @@ -438,16 +438,18 @@ float & \texttt{double} vector & \texttt{double} vector \\ \hline int32 & \texttt{integer} vector & \texttt{integer} vector \\ -int64 & \texttt{integer} vector & \texttt{integer} vector \\ uint32 & \texttt{integer} vector & \texttt{integer} vector \\ -uint64 & \texttt{integer} vector & \texttt{integer} vector \\ sint32 & \texttt{integer} vector & \texttt{integer} vector \\ -sint64 & \texttt{integer} vector & \texttt{integer} vector \\ fixed32 & \texttt{integer} vector & \texttt{integer} vector \\ -fixed64 & \texttt{integer} vector & \texttt{integer} vector \\ sfixed32 & \texttt{integer} vector & \texttt{integer} vector \\ -sfixed64 & \texttt{integer} vector & \texttt{integer} vector \\ \hline +int64 & \texttt{integer} or \texttt{character} +vector \footnotemark & \texttt{integer} or \texttt{character} vector \\ +uint64 & \texttt{integer} or \texttt{character} vector & \texttt{integer} or \texttt{character} vector \\ +sint64 & \texttt{integer} or \texttt{character} vector & \texttt{integer} or \texttt{character} vector \\ +fixed64 & \texttt{integer} or \texttt{character} vector & \texttt{integer} or \texttt{character} vector \\ +sfixed64 & \texttt{integer} or \texttt{character} vector & \texttt{integer} or \texttt{character} vector \\ +\hline bool & \texttt{logical} vector & \texttt{logical} vector \\ \hline string & \texttt{character} vector & \texttt{character} vector \\ @@ -459,7 +461,11 @@ \hline \end{tabular} \end{small} -\caption{\label{table-get-types}Correspondance between field type and R type retrieved by the extractors.} +\caption{\label{table-get-types}Correspondance between field type and + R type retrieved by the extractors. \footnotesize{1. R lacks native + 64-bit integers, so the \texttt{RProtoBuf.int64AsString} option is + available to return large integers as characters to avoid losing + precision. This option is described in Section~\ref{sec:int64}}.} \end{table} \subsubsection{Modify fields} @@ -495,7 +501,8 @@ \texttt{int32}, \texttt{int64}, \texttt{uint32}, \texttt{uint64}, \texttt{sint32}, \texttt{sint64}, \texttt{fixed32}, \texttt{fixed64}, \texttt{sfixed32}, \texttt{sfixed64} & - \texttt{integer}, \texttt{raw}, \texttt{double}, \texttt{logical} \\ + \texttt{integer}, \texttt{raw}, \texttt{double}, + \texttt{logical}, \texttt{character} \\ \hline \texttt{bool} & \texttt{integer}, \texttt{raw}, \texttt{double}, \texttt{logical} \\ \hline @@ -1855,6 +1862,7 @@ \item field names, enum types, nested types for message type descriptors \item names for enum descriptors \item names for top-level extensions +\item message names for file descriptors \end{itemize} In the unlikely event that there is a user-defined field of exactly From noreply at r-forge.r-project.org Fri Dec 27 03:10:41 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 03:10:41 +0100 (CET) Subject: [Rprotobuf-commits] r599 - pkg Message-ID: <20131227021041.B8D79183CD1@r-forge.r-project.org> Author: murray Date: 2013-12-27 03:10:40 +0100 (Fri, 27 Dec 2013) New Revision: 599 Modified: pkg/ChangeLog pkg/TODO Log: Update TODO list. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-27 01:53:01 UTC (rev 598) +++ pkg/ChangeLog 2013-12-27 02:10:40 UTC (rev 599) @@ -2,12 +2,19 @@ * src/mutators.cpp: Support setting int32 values with character vectors of a decimal number, as we do by necessity for int64s. + * inst/unitTests/runit.int32.R (test.int32): Add tests for above. * NAMESPACE: Add missing export for .DollarNames EnumValueDescriptor to allow completion on that class. * R/00classes.R: Update FileDescriptor '$' dispatch to work properly for the names of fields defined in the FileDescriptor, instead of just returning NULL even for types returned by $ completion. + * vignettes/RProtoBuf-intro.Rnw (subsubsection{Retrieve fields}): + Update the type mapping tables to note that characters can be + extracted from 64-bit integer types with the + RProtoBuf.int64AsString type and note that int32 and int64 types + can be set to character values representing decimal numbers. + * TODO: Update todo list. 2013-12-23 Murray Stokely Modified: pkg/TODO =================================================================== --- pkg/TODO 2013-12-27 01:53:01 UTC (rev 598) +++ pkg/TODO 2013-12-27 02:10:40 UTC (rev 599) @@ -1,16 +1,96 @@ Current TODO list: -1. Finish extensions support [enums, messages, nested, more tests] -2. Unit testing [ongoing] -3. More as.Message methods [have patch, needs cleanup] -4. Replace usage of RCPP_FUNCTION_* macros with Rcpp Modules or Attributes. -5. Clean up formatting / whitespace. -6. Add more documentation / examples. +1. Finish improved vignette / R Journal writeup. -Older stuff +2. Refactor massive 800+ line setMessageField function in + src/mutators.cpp into more modular, testable, easier to read + subroutines. - o finalizers [murray: what is needed here?] - o http-powered rpc implementation [maybe] - o what to do when unload the package - o useR abstract [done] - o useR presentation [done] +3. Push some type coercion hacks done in RProtoBuf upstream to Rcpp + (Rcpp:as types should work on character strings representing + numbers, especially for int64s since we don't otherwise have a way + to represent 64-bit integers in base R). + +4. Add more packages that depend on or enhance RProtoBuf. + +5. Investigate Rcpp Modules support for some classes. Murray is not + personally super enthusiastic about this one, as I think it may + require non trivial changes to Rcpp and/or result in losing some of + the user-friendliness we've crafted in the explicit RcppExported + function entry points. Still, it could be explored and may result + in significantly fewer lines of code if successful. + +6. Add a FAQ and other documentation / examples. + +7. Add more unit tests. + +8. Explore removing the CLONE() in extractors.cpp. This makes for + unusual semantics for any mutable methods of sub-messages. For + example, clear(), setExtension(), and probably also update() ( but + "$<-" on sub-messages is not a problem, it seems). More details below. + +9. What should we do when we unload the package? Any additional + resources to free that is not currently done? + +10. finalizers [murray: what is needed here?] + +11. Clean up formatting / whitespace (its awful, run it all through + clang-format?) + +12. Thoroughly audit extensions support and other deeply nested types + support to ensure everything is implemented as expected. + +Stuff I think belongs in additional packages that depend on RProtoBuf, +rather than inside RProtoBuf directly: + + o http-powered rpc implementation + o More as.Message methods + +--- Detailed Notes ---- + +8. CLONE() + +--[ examples from Murray illustrating the problem ]-- + +library(RProtoBuf) +InitGoogle() + +if (!exists("protobuf_unittest.TestAllTypes", "RProtoBuf:DescriptorPool")) { + unittest.proto.file <- system.file("unitTests", "data", "unittest.proto",package="RProtoBuf") + readProtoFiles(file=unittest.proto.file) +} +test <- new(protobuf_unittest.TestAllTypes) +test$optional_foreign_message <- new(protobuf_unittest.ForeignMessage, c=3) + +# Example 1: +test$optional_foreign_message$c +test$optional_foreign_message$clear() +test$optional_foreign_message$c +# didn't clear test$optional_foreign_message$c + +# Example 2: +foo <- new(protobuf_unittest.ForeignMessage, c=3) +foo$c +foo$clear() +foo$c +# did clear foo$c + +# Example 3: +baz <- test$optional_foreign_message +baz$c +baz$c <- 4 +test$optional_foreign_message$c +# still 3, but would be 4 if we removed the CLONE(). + + +Example 1 is currently I think very confusing semantically for users of RProtoBuf with nested messages and I would like to fix that case. Example 2 works correctly now and would not be affected by this change. Example 3 would change behavior and could cause problems for users. Would need to be clearly announced in the NEWS file and to our user list. + +--[ Romain's thoughts ]-- + + +`$<-` is the task of setMessageField: + +https://github.com/RProtoBuf/RProtoBuf/blob/master/R/00classes.R#L197 +https://github.com/RProtoBuf/RProtoBuf/blob/master/src/mutators.cpp#L377 + +For "$" we could perhaps move to some sort of copy on change semantics (similar to what R does), instead of what we use currently which is more like copy on access. From noreply at r-forge.r-project.org Fri Dec 27 03:19:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 03:19:35 +0100 (CET) Subject: [Rprotobuf-commits] r600 - pkg/inst Message-ID: <20131227021935.9916018657E@r-forge.r-project.org> Author: murray Date: 2013-12-27 03:19:33 +0100 (Fri, 27 Dec 2013) New Revision: 600 Modified: pkg/inst/NEWS.Rd Log: Document todays changes. Modified: pkg/inst/NEWS.Rd =================================================================== --- pkg/inst/NEWS.Rd 2013-12-27 02:10:40 UTC (rev 599) +++ pkg/inst/NEWS.Rd 2013-12-27 02:19:33 UTC (rev 600) @@ -2,23 +2,36 @@ \title{News for Package \pkg{RProtoBuf}} \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}} -\section{Changes in UNRELEASED RProtoBuf version 0.3.3 (2013-12-23)}{ +\section{Changes in UNRELEASED RProtoBuf version 0.3.3 (2013-12-26)}{ \itemize{ \item Vignettes have been converted to the R 3.0.0 or later use of external vignette builders, no longer need a \code{Makefile} \item Added missing methods to dollar completion list for Message, Descriptor, EnumValueDescriptor, and FileDescriptor classes. + \item Add missing export for \code{.DollarNames} EnumValueDescriptor + to allow completion on that class. \item Add more than 10 additional pages to the main Intro vignette - documenting better all of the S4 classes implemented by RProtoBuf and - advanced features such as Extensions. + documenting better all of the S4 classes implemented by RProtoBuf, + updating the type mapping tables to take into account 64-bit + support, and documenting advanced features such as Extensions. \item Added better error checking in EnumDescriptors to catch the case when wrong types are provided. \item Updated the FileDescriptor \code{name()} method to accept a boolean for full paths just like the generic \code{name()} method. \item Correct a bug that incorrectly dispatched \code{as.character()} when \code{as.list()} was called on Descriptor objects. + \item Update FileDescriptor \code{$} dispatch to work properly for + the names of fields defined in the FileDescriptor, instead of + just returning \code{NULL} even for types returned by \code{$} + completion. \item Added a reservation for extension fields in the example tutorial.Person schema. + \item Support setting int32 fields with character representations + and raise an R-level \code{stop()} error if the provided string can + not be parsed as a 32-bit integer, rather than crashing the R + instance. + \item Update the project TODO file. + \item Add better documentation and tests for all of the above. } } From noreply at r-forge.r-project.org Fri Dec 27 03:48:25 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 03:48:25 +0100 (CET) Subject: [Rprotobuf-commits] r601 - in pkg: . src Message-ID: <20131227024828.295E9185D28@r-forge.r-project.org> Author: murray Date: 2013-12-27 03:48:24 +0100 (Fri, 27 Dec 2013) New Revision: 601 Modified: pkg/ChangeLog pkg/src/mutators.cpp Log: Refuse to set non-repeated bools to NA, just as we do for repeated bool fields by raising a stop() error since protocol buffer bools are 2-valued and NA is the third-value of R bools. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-27 02:19:33 UTC (rev 600) +++ pkg/ChangeLog 2013-12-27 02:48:24 UTC (rev 601) @@ -2,6 +2,9 @@ * src/mutators.cpp: Support setting int32 values with character vectors of a decimal number, as we do by necessity for int64s. + Also, refuse to set non-repeated bools to NA, just as we do for + repeated bool fields by raising a stop() error since protocol + buffer bools are 2-valued and NA is the third-value of R bools. * inst/unitTests/runit.int32.R (test.int32): Add tests for above. * NAMESPACE: Add missing export for .DollarNames EnumValueDescriptor to allow completion on that class. Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-27 02:19:33 UTC (rev 600) +++ pkg/src/mutators.cpp 2013-12-27 02:48:24 UTC (rev 601) @@ -183,19 +183,22 @@ switch( TYPEOF(x) ){ case INTSXP: if (INTEGER(x)[index] == R_NaInt) { - throwException( "NA boolean values not supported by RProtoBuf", + throwException( "NA boolean values can not be stored in " + "bool protocol buffer fields", "CastException" ) ; } return( (bool)INTEGER(x)[index] ); case REALSXP: if (REAL(x)[index] == R_NaReal) { - throwException( "NA boolean values not supported by RProtoBuf", + throwException( "NA boolean values can not be stored in " + "bool protocol buffer fields", "CastException" ) ; } return( (bool)REAL(x)[index] ); case LGLSXP: if (LOGICAL(x)[index] == NA_LOGICAL) { - throwException( "NA boolean values not supported by RProtoBuf", + throwException( "NA boolean values can not be stored in " + "bool protocol buffer fields", "CastException" ) ; } return( (bool)LOGICAL(x)[index] ); @@ -1046,7 +1049,28 @@ HANDLE_SINGLE_FIELD( CPPTYPE_DOUBLE, Double, double) ; HANDLE_SINGLE_FIELD( CPPTYPE_FLOAT, Float, float) ; - HANDLE_SINGLE_FIELD( CPPTYPE_BOOL, Bool, bool) ; + case CPPTYPE_BOOL : + { + // TODO(mstokely): Rcpp should handle this! + if ((TYPEOF(value) == LGLSXP) && + (LOGICAL(value)[0] == NA_LOGICAL)) { + throwException("NA boolean values can not be stored in " + "bool protocol buffer fields", + "CastException"); + } else if ((TYPEOF(value) == INTSXP) && + (INTEGER(value)[0] == R_NaInt)) { + throwException( "NA boolean values can not be stored in " + "bool protocol buffer fields", + "CastException"); + } else if ((TYPEOF(value) == REALSXP) && + (REAL(value)[0] == R_NaReal)) { + throwException( "NA boolean values can not be stored in " + "bool protocol buffer fields", + "CastException"); + } + ref->SetBool(message, field_desc, Rcpp::as(value)); + break ; + } case CPPTYPE_INT32 : { if (TYPEOF(value) == STRSXP) { From noreply at r-forge.r-project.org Fri Dec 27 04:03:44 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 04:03:44 +0100 (CET) Subject: [Rprotobuf-commits] r602 - pkg/inst/unitTests Message-ID: <20131227030344.98EA6186222@r-forge.r-project.org> Author: murray Date: 2013-12-27 04:03:43 +0100 (Fri, 27 Dec 2013) New Revision: 602 Added: pkg/inst/unitTests/runit.bool.R Log: Add unit test for boolean types, comment out some ways to crash the R session that we need to fix. Added: pkg/inst/unitTests/runit.bool.R =================================================================== --- pkg/inst/unitTests/runit.bool.R (rev 0) +++ pkg/inst/unitTests/runit.bool.R 2013-12-27 03:03:43 UTC (rev 602) @@ -0,0 +1,47 @@ +# Copyright 2013 Google Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +test.bool <- function() { + if (!exists("protobuf_unittest.TestAllTypes", + "RProtoBuf:DescriptorPool")) { + unittest.proto.file <- system.file("unitTests", "data", + "unittest.proto", + package="RProtoBuf") + readProtoFiles(file=unittest.proto.file) + } + + a <- new(protobuf_unittest.TestAllTypes) + a$optional_bool <- TRUE + a$optional_bool <- FALSE + # Verify we can not set a protocol buffer bool to NA. + checkException(a$optional_bool <- NA) + + # Verify we can set character strings + a$repeated_bool <- c(TRUE, FALSE, TRUE) + checkEquals(length(unique(a$repeated_bool)), 2) + + # Verify we can't set any garbage string to a bool. + # TODO(mstokely): Fix and uncomment these. +# checkException(a$optional_bool <- "100") +# checkException(a$optional_bool <- "invalid") + + # Verify we can't set any garbage string to a repeated bool. +# checkException(a$repeated_bool <-c("invalid", "invalid")) +# checkException(a$repeated_bool <-c("33-")) + + # Verify we can set NA + checkException(a$repeated_bool <- c(TRUE, FALSE, TRUE, NA)) +} From noreply at r-forge.r-project.org Fri Dec 27 04:08:45 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 04:08:45 +0100 (CET) Subject: [Rprotobuf-commits] r603 - pkg Message-ID: <20131227030845.D53331862CD@r-forge.r-project.org> Author: murray Date: 2013-12-27 04:08:36 +0100 (Fri, 27 Dec 2013) New Revision: 603 Modified: pkg/ChangeLog pkg/TODO Log: Add another todo entry and note the addition of the bool unit test in the changelog. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-27 03:03:43 UTC (rev 602) +++ pkg/ChangeLog 2013-12-27 03:08:36 UTC (rev 603) @@ -18,6 +18,8 @@ RProtoBuf.int64AsString type and note that int32 and int64 types can be set to character values representing decimal numbers. * TODO: Update todo list. + * inst/unitTests/runit.bool.R (test.bool): Add more tests about + boolean values, NA handling, etc. 2013-12-23 Murray Stokely Modified: pkg/TODO =================================================================== --- pkg/TODO 2013-12-27 03:03:43 UTC (rev 602) +++ pkg/TODO 2013-12-27 03:08:36 UTC (rev 603) @@ -13,31 +13,34 @@ 4. Add more packages that depend on or enhance RProtoBuf. -5. Investigate Rcpp Modules support for some classes. Murray is not +5. Improve exception handling to prevent cases where an Rcpp exception + crashes the interactive R instance. + +6. Investigate Rcpp Modules support for some classes. Murray is not personally super enthusiastic about this one, as I think it may require non trivial changes to Rcpp and/or result in losing some of the user-friendliness we've crafted in the explicit RcppExported function entry points. Still, it could be explored and may result in significantly fewer lines of code if successful. -6. Add a FAQ and other documentation / examples. +7. Add a FAQ and other documentation / examples. -7. Add more unit tests. +8. Add more unit tests. -8. Explore removing the CLONE() in extractors.cpp. This makes for +9. Explore removing the CLONE() in extractors.cpp. This makes for unusual semantics for any mutable methods of sub-messages. For example, clear(), setExtension(), and probably also update() ( but "$<-" on sub-messages is not a problem, it seems). More details below. -9. What should we do when we unload the package? Any additional +10. What should we do when we unload the package? Any additional resources to free that is not currently done? -10. finalizers [murray: what is needed here?] +11. finalizers [murray: what is needed here?] -11. Clean up formatting / whitespace (its awful, run it all through +12. Clean up formatting / whitespace (its awful, run it all through clang-format?) -12. Thoroughly audit extensions support and other deeply nested types +13. Thoroughly audit extensions support and other deeply nested types support to ensure everything is implemented as expected. Stuff I think belongs in additional packages that depend on RProtoBuf, From noreply at r-forge.r-project.org Fri Dec 27 09:27:34 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 09:27:34 +0100 (CET) Subject: [Rprotobuf-commits] r604 - in pkg: . inst/unitTests src Message-ID: <20131227082734.93CDD186809@r-forge.r-project.org> Author: murray Date: 2013-12-27 09:27:34 +0100 (Fri, 27 Dec 2013) New Revision: 604 Modified: pkg/.Rbuildignore pkg/ChangeLog pkg/TODO pkg/inst/unitTests/runit.bool.R pkg/src/mutators.cpp Log: Refactor setMessageField into four separate functions, correct a few minor typos, and wrap everything in a try/catch block so we catch any exceptions generated by Rcpp::as or other functions and forward it along to an R-language stop() error instead of terminating our R instance. Modified: pkg/.Rbuildignore =================================================================== --- pkg/.Rbuildignore 2013-12-27 03:08:36 UTC (rev 603) +++ pkg/.Rbuildignore 2013-12-27 08:27:34 UTC (rev 604) @@ -1,2 +1,3 @@ m4 configure.in +vignettes/Sweave.sty Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-27 03:08:36 UTC (rev 603) +++ pkg/ChangeLog 2013-12-27 08:27:34 UTC (rev 604) @@ -1,3 +1,11 @@ +2013-12-27 Murray Stokely + + * src/mutators.cpp: Refactor setMessageField into four separate + functions, correct a few minor typos, and wrap everything in a + try/catch block so we catch any exceptions generated by Rcpp::as + or other functions and forward it along to an R-language stop() + error instead of terminating our R instance. + 2013-12-26 Murray Stokely * src/mutators.cpp: Support setting int32 values with character Modified: pkg/TODO =================================================================== --- pkg/TODO 2013-12-27 03:08:36 UTC (rev 603) +++ pkg/TODO 2013-12-27 08:27:34 UTC (rev 604) @@ -1,47 +1,43 @@ Current TODO list: -1. Finish improved vignette / R Journal writeup. +o Finish improved vignette / R Journal writeup. -2. Refactor massive 800+ line setMessageField function in - src/mutators.cpp into more modular, testable, easier to read - subroutines. +o Push some type coercion hacks done in RProtoBuf upstream to Rcpp + (Rcpp:as types should work on character strings representing + numbers, especially for int64s since we don't otherwise have a way + to represent 64-bit integers in base R). -3. Push some type coercion hacks done in RProtoBuf upstream to Rcpp - (Rcpp:as types should work on character strings representing - numbers, especially for int64s since we don't otherwise have a way - to represent 64-bit integers in base R). +o Add more packages that depend on or enhance RProtoBuf. -4. Add more packages that depend on or enhance RProtoBuf. - -5. Improve exception handling to prevent cases where an Rcpp exception +o Improve exception handling to prevent cases where an Rcpp exception crashes the interactive R instance. -6. Investigate Rcpp Modules support for some classes. Murray is not - personally super enthusiastic about this one, as I think it may - require non trivial changes to Rcpp and/or result in losing some of - the user-friendliness we've crafted in the explicit RcppExported - function entry points. Still, it could be explored and may result - in significantly fewer lines of code if successful. +o Investigate Rcpp Modules support for some classes. Murray is not + personally super enthusiastic about this one, as I think it may + require non trivial changes to Rcpp and/or result in losing some of + the user-friendliness we've crafted in the explicit RcppExported + function entry points. Still, it could be explored and may result + in significantly fewer lines of code if successful. -7. Add a FAQ and other documentation / examples. +o Add a FAQ and other documentation / examples. -8. Add more unit tests. +o Add more unit tests. -9. Explore removing the CLONE() in extractors.cpp. This makes for - unusual semantics for any mutable methods of sub-messages. For - example, clear(), setExtension(), and probably also update() ( but - "$<-" on sub-messages is not a problem, it seems). More details below. +o Explore removing the CLONE() in extractors.cpp. This makes for + unusual semantics for any mutable methods of sub-messages. For + example, clear(), setExtension(), and probably also update() ( but + "$<-" on sub-messages is not a problem, it seems). More details below. -10. What should we do when we unload the package? Any additional - resources to free that is not currently done? +o What should we do when we unload the package? Any additional + resources to free that is not currently done? -11. finalizers [murray: what is needed here?] +o finalizers [murray: what is needed here?] -12. Clean up formatting / whitespace (its awful, run it all through - clang-format?) +o Clean up formatting / whitespace (its awful, run it all through + clang-format?) -13. Thoroughly audit extensions support and other deeply nested types - support to ensure everything is implemented as expected. +o Thoroughly audit extensions support and other deeply nested types + support to ensure everything is implemented as expected. Stuff I think belongs in additional packages that depend on RProtoBuf, rather than inside RProtoBuf directly: Modified: pkg/inst/unitTests/runit.bool.R =================================================================== --- pkg/inst/unitTests/runit.bool.R 2013-12-27 03:08:36 UTC (rev 603) +++ pkg/inst/unitTests/runit.bool.R 2013-12-27 08:27:34 UTC (rev 604) @@ -34,13 +34,12 @@ checkEquals(length(unique(a$repeated_bool)), 2) # Verify we can't set any garbage string to a bool. - # TODO(mstokely): Fix and uncomment these. -# checkException(a$optional_bool <- "100") -# checkException(a$optional_bool <- "invalid") + checkException(a$optional_bool <- "100") + checkException(a$optional_bool <- "invalid") # Verify we can't set any garbage string to a repeated bool. -# checkException(a$repeated_bool <-c("invalid", "invalid")) -# checkException(a$repeated_bool <-c("33-")) + checkException(a$repeated_bool <-c("invalid", "invalid")) + checkException(a$repeated_bool <-c("33-")) # Verify we can set NA checkException(a$repeated_bool <- c(TRUE, FALSE, TRUE, NA)) Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-27 03:08:36 UTC (rev 603) +++ pkg/src/mutators.cpp 2013-12-27 08:27:34 UTC (rev 604) @@ -382,8 +382,856 @@ } +/** + * check that all repeated values are ok before doing anything, + * otherwise this could lead to modifying a few values then failing in + * an inconsistent state. + */ +void CHECK_repeated_vals(GPB::FieldDescriptor* field_desc, + SEXP value, int value_size) { + switch( field_desc->type() ){ + case TYPE_MESSAGE: + case TYPE_GROUP: + { + switch( TYPEOF( value ) ){ + case VECSXP : + { + /* check that it is a list of Messages of the appropriate type */ + for( int i=0; imessage_type()->full_name().c_str() ) ){ + /* TODO: include i, target type and actual type in the message */ + throwException( "incorrect type", "IncorrectMessageTypeException" ) ; + } + } + break ; + } + case S4SXP: + { + /* check that this is a message of the appropriate type */ + if( !isMessage( value, field_desc->message_type()->full_name().c_str() ) ){ + throwException( "incorrect type", "IncorrectMessageTypeException" ) ; + } + break ; + } + default: + { + throwException( "impossible to convert to a message" , "ConversionException" ) ; + } + } + break ; + } + case TYPE_ENUM : + { + const GPB::EnumDescriptor* enum_desc = field_desc->enum_type() ; + /* check first, it means we have to loop twice, but + otherwise this could have some side effects before the + exception is thrown */ + + /* FIXME: the checking should go before the resizing */ + + switch( TYPEOF( value ) ){ + // {{{ numbers + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + { + int nenums = enum_desc->value_count() ; + std::vector possibles(nenums) ; + for( int i=0; i< nenums; i++){ + possibles[i] = enum_desc->value(i)->number(); + } + + /* loop around the numbers to see if they are in the possibles */ + for( int i=0; ivalue_count() ; + std::vector possibles(nenums) ; + for( int i=0; i< nenums; i++){ + possibles[i] = enum_desc->value(i)->name() ; + } + + /* loop around the numbers to see if they are in the possibles */ + for( int i=0; i 1) { + throwException( "cannot set non-repeated field to vector of length > 1", + "CastException" ) ; + } + switch( GPB::FieldDescriptor::TypeToCppType( field_desc->type() ) ){ + // {{{ simple cases using macro expansion +#undef HANDLE_SINGLE_FIELD +#define HANDLE_SINGLE_FIELD( CPPTYPE, CAMEL, TYPE ) \ + case CPPTYPE : \ + { \ + ref->Set##CAMEL( message, field_desc, Rcpp::as(value) ) ; \ + break ; \ + } + + HANDLE_SINGLE_FIELD( CPPTYPE_DOUBLE, Double, double) ; + HANDLE_SINGLE_FIELD( CPPTYPE_FLOAT, Float, float) ; + case CPPTYPE_BOOL : + { + // TODO(mstokely): Rcpp should handle this! + if ((TYPEOF(value) == LGLSXP) && + (LOGICAL(value)[0] == NA_LOGICAL)) { + throwException("NA boolean values can not be stored in " + "bool protocol buffer fields", + "CastException"); + } else if ((TYPEOF(value) == INTSXP) && + (INTEGER(value)[0] == R_NaInt)) { + throwException( "NA boolean values can not be stored in " + "bool protocol buffer fields", + "CastException"); + } else if ((TYPEOF(value) == REALSXP) && + (REAL(value)[0] == R_NaReal)) { + throwException( "NA boolean values can not be stored in " + "bool protocol buffer fields", + "CastException"); + } + ref->SetBool(message, field_desc, Rcpp::as(value)); + break ; + } + case CPPTYPE_INT32 : + { + if (TYPEOF(value) == STRSXP) { + const string int32str = COPYSTRING(CHAR( + STRING_ELT(value, 0))); + ref->SetInt32(message, field_desc, + Int32FromString(int32str)); + break ; + } else { + ref->SetInt32( message, field_desc, Rcpp::as(value)); + break; + } + } + case CPPTYPE_UINT32 : + { + if (TYPEOF(value) == STRSXP) { + const string uint32str = COPYSTRING(CHAR( + STRING_ELT(value, 0))); + ref->SetUInt32(message, field_desc, + Int32FromString(uint32str)); + break ; + } else { + ref->SetUInt32( message, field_desc, Rcpp::as(value)); + break; + } + } + +#ifdef RCPP_HAS_LONG_LONG_TYPES + case CPPTYPE_INT64 : + { + // TODO(mstokely) Rcpp::as of a STRSEXP should just + // work for strings representing int64s. + if (TYPEOF(value) == STRSXP) { + const string int64str = COPYSTRING(CHAR( + STRING_ELT(value, 0))); + ref->SetInt64(message, field_desc, + Int64FromString(int64str)); + break ; + } else { + ref->SetInt64( message, field_desc, Rcpp::as(value)); + break; + } + } + case CPPTYPE_UINT64 : + { + // TODO(mstokely) Rcpp::as of a STRSEXP should just + // work for strings representing int64s. + if (TYPEOF(value) == STRSXP) { + const string int64str = COPYSTRING(CHAR( + STRING_ELT(value, 0))); + ref->SetUInt64(message, field_desc, + Int64FromString(int64str)); + break ; + } else { + ref->SetUInt64(message, field_desc, + Rcpp::as(value)); + break; + } + } +#endif +#undef HANDLE_SINGLE_FIELD + default: + throwException("Unsupported type", "ConversionException"); +// }}} + + // {{{ string + case CPPTYPE_STRING: + { + switch( TYPEOF( value ) ){ + case STRSXP: + { + ref->SetString(message, field_desc, + COPYSTRING( CHAR(STRING_ELT(value,0 )) ) ) ; + break ; + } + case RAWSXP: + { + ref->SetString(message, field_desc, GET_bytes(value, 0)) ; + break ; + } + case S4SXP: + { + /* check if value is a message */ + if( !Rf_inherits( value, "Message" ) ){ + throwException( "Can only convert S4 objects of class 'Message'", + "ConversionException" ) ; + } + GPB::Message* __mess = GET_MESSAGE_POINTER_FROM_S4(value); + ref->SetString(message, field_desc, + __mess->SerializeAsString()); + break ; + } + default: + { + throwException( "Cannot convert to string", + "ConversionException" ) ; + } + } + break ; + } + // }}} + + // {{{ message + case CPPTYPE_MESSAGE: + { + if( TYPEOF( value ) == S4SXP && Rf_inherits( value, "Message" ) ){ + GPB::Message* mess = (GPB::Message*) EXTPTR_PTR( GET_SLOT( value, Rf_install("pointer") ) ) ; + const char* type = mess->GetDescriptor()->full_name().c_str() ; + const char* target = field_desc->message_type()->full_name().c_str() ; + if( strcmp( type, target ) ){ + throwException( "wrong message type", "WrongMessageException" ) ; + } + GPB::Message* m = ref->MutableMessage( message, field_desc ) ; + m->CopyFrom( *mess ) ; + } else { + throwException( "type mismatch, expecting a 'Message' object", + "TypeMismatchException" ) ; + } + break ; + } + // }}} + + // {{{ enum + case CPPTYPE_ENUM : + { + const GPB::EnumDescriptor* enum_desc = field_desc->enum_type() ; + switch( TYPEOF( value ) ){ + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + { + int val = Rcpp::as(value) ; + const GPB::EnumValueDescriptor* evd = enum_desc->FindValueByNumber(val) ; + if( !evd ){ + throwException( "wrong value for enum", + "WrongEnumValueException" ) ; + } else { + ref->SetEnum( message, field_desc, evd ); + } + break ; + } + case STRSXP: + { + std::string val = Rcpp::as( value ) ; + const GPB::EnumValueDescriptor* evd = enum_desc->FindValueByName(val) ; + if( !evd ){ + throwException( "wrong value for enum", "WrongEnumValueException" ) ; + } else { + ref->SetEnum( message, field_desc, evd ); + } + break ; + } + default: + { + throwException( "cannot set enum value", "WrongTypeEnumValueException" ) ; + } + } + } + // }}} + } + // }}} +} + +/** + * set a repeated message field to a new value + * + * @param message pointer to a message + * @param ref pointer to reflection object for message + * @param field_desc pointer to field descriptor to update + * @param value new value for the field + * @param value_size size of the new value for the field + * + * @return void, the message is modified by reference + */ + +void setRepeatedMessageField(GPB::Message* message, + const Reflection* ref, + GPB::FieldDescriptor* field_desc, + SEXP value, int value_size) { + // The number of elements already in the repeated field. + int field_size = ref->FieldSize( *message, field_desc ) ; + + /* {{{ in case of messages or enum, we have to check that all + values are ok before doing anything, othewise this could leed + to modify a few values and then fail which is not good */ + CHECK_repeated_vals(field_desc, value, value_size); + + /* Remove some items if there are too many. */ + if( field_size > value_size ) { + /* we need to remove some */ + while( field_size > value_size ){ + ref->RemoveLast( message, field_desc ) ; + field_size-- ; + } + } + + switch( field_desc->type() ){ + // {{{ int32 + case TYPE_INT32: + case TYPE_SINT32: + case TYPE_SFIXED32: + { + switch( TYPEOF( value ) ){ + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + case STRSXP: // For int32, we support chars. + { + int i = 0; + /* in any case, fill the values up to field_size */ + for( ; iSetRepeatedInt32( message, field_desc, i, + GET_int32(value,i) ) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddInt32( message, field_desc, + GET_int32(value,i) ) ; + } + } + + break ; + } + + default: + { + throwException( "Cannot convert to int32", + "ConversionException" ) ; + } + } + break ; + } + // }}} + + // {{{ int64 + case TYPE_INT64: + case TYPE_SINT64: + case TYPE_SFIXED64: + { + switch( TYPEOF( value ) ){ + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + case STRSXP: // For int64, we support chars. + { + int i = 0; + + /* in any case, fill the values up to field_size */ + for( ; iSetRepeatedInt64( message, field_desc, i, + GET_int64(value,i) ) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddInt64( message, field_desc, + GET_int64(value,i) ) ; + } + } + break ; + } + + default: + throwException( "Cannot convert to int64", + "ConversionException" ) ; + } + break ; + } + // }}} + + // {{{ uint32 + case TYPE_UINT32: + case TYPE_FIXED32: + { + switch( TYPEOF( value ) ){ + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + case STRSXP: // For int32, we support chars. + { + int i = 0; + /* in any case, fill the values up to field_size */ + for( ; iSetRepeatedUInt32( message, field_desc, i, + GET_int32(value,i) ) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddUInt32( message, field_desc, + GET_int32(value,i) ) ; + } + } + break ; + } + default: + throwException( "Cannot convert to uint32", + "ConversionException" ) ; + } + break ; + } + // }}} + + // {{{ uint64 + case TYPE_UINT64: + case TYPE_FIXED64: + { + switch( TYPEOF( value ) ){ + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + case STRSXP: // For int64, we support chars. + { + int i = 0; + /* in any case, fill the values up to field_size */ + for( ; iSetRepeatedUInt64( message, field_desc, i, + GET_uint64(value,i) ) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddUInt64( message, field_desc, + GET_uint64(value,i) ) ; + } + } + break ; + } + default: + throwException( "Cannot convert to int64", + "ConversionException" ) ; + } + break ; + } + // }}} + + // {{{ double + case TYPE_DOUBLE: + { + switch( TYPEOF( value ) ){ + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + { + int i = 0; + /* in any case, fill the values up to field_size */ + for( ; iSetRepeatedDouble( message, field_desc, i, + GET_double(value,i) ) ; + } + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddDouble( message, field_desc, + GET_double(value,i) ) ; + } + } + break ; + } + default: + throwException( "Cannot convert to double", + "ConversionException" ) ; + } + break ; + } + // }}} + + // {{{ float + case TYPE_FLOAT: + { + switch( TYPEOF( value ) ){ + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + { + int i = 0; + /* in any case, fill the values up to field_size */ + for( ; iSetRepeatedFloat( message, field_desc, i, + GET_float(value,i) ) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddFloat( message, field_desc, + GET_float(value,i) ) ; + } + } + break ; + } + default: + throwException( "Cannot convert to float", + "ConversionException" ) ; + } + break ; + } + // }}} + + // {{{ bool + case TYPE_BOOL: + { + switch( TYPEOF( value ) ){ + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + { + int i = 0; + /* in any case, fill the values up to field_size */ + for( ; iSetRepeatedBool( message, field_desc, i, + GET_bool(value,i) ) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddBool( message, field_desc, + GET_bool(value,i) ) ; + } + } + break ; + } + default: + throwException( "Cannot convert to bool", + "ConversionException" ) ; + } + break ; + } + // }}} + + // {{{ string + case TYPE_STRING: + case TYPE_BYTES: + { + switch( TYPEOF(value) ){ + case STRSXP : + { + /* in any case, fill the values up to field_size */ + int i = 0; + for( ; iSetRepeatedString( message, field_desc, i, + COPYSTRING( CHAR(STRING_ELT(value,i )) ) ) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddString( message, field_desc, + COPYSTRING( CHAR(STRING_ELT(value,i )) ) ) ; + } + } + break ; + } + case RAWSXP: + { + /* in any case, fill the values up to field_size */ + int i = 0; + for ( ; iSetRepeatedString( message, field_desc, i, + GET_bytes(value, 0)) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddString( message, field_desc, + GET_bytes(value, 0)) ; + } + } + break; + } + case S4SXP: + { + /* check if value is a message */ + if( !Rf_inherits( value, "Message" ) ){ + throwException( "Can only convert S4 objects of class 'Message' ", + "ConversionException" ) ; + } + GPB::Message* __mess = GET_MESSAGE_POINTER_FROM_S4( value ) ; + ref->SetRepeatedString(message, field_desc, 0, + __mess->SerializeAsString() ) ; + break ; + } + case VECSXP: + { + // we know it is a list of messages or raws because it + // has been tested above + if (LENGTH(value) > 0 && TYPEOF(VECTOR_ELT(value, 0)) == RAWSXP ) { + /* in any case, fill the values up to field_size */ + int i = 0; + for( ; iSetRepeatedString( message, field_desc, i, + GET_bytes(value,i )) ; + } + + /* then add some if needed */ + if( value_size > field_size ) { + for( ; iAddString( message, field_desc, + GET_bytes(value,i )) ; + } + } + } else { + // FIXME: we should probably use SerializeToString + // as indicated in the protobuf api documentation + // http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.message_lite.html#MessageLite.SerializeAsString.details + GPB::Message* __mess ; + + /* in any case, fill the values up to field_size */ + int i = 0; + for( ; iSetRepeatedString( message, field_desc, i, + __mess->SerializeAsString() ) ; + } + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddString( message, field_desc, + __mess->SerializeAsString() ) ; + } + } + } + break ; + } + default: + throwException( "Cannot convert to string", + "ConversionException" ) ; + } + break ; + } + // }}} + + // {{{ message + case TYPE_MESSAGE: + case TYPE_GROUP: + { + if( TYPEOF( value ) == S4SXP ) { + /* we know it is a message of the correct type (tested above) */ + GPB::Message* mess = GET_MESSAGE_POINTER_FROM_S4( value ) ; + + if( field_size == 1 ) { + /* FIXME: we should not __copy__ the message */ + ref->MutableRepeatedMessage(message, field_desc, 0 )->CopyFrom( *mess ) ; + } else { + /* FIXME */ + ref->ClearField( message, field_desc ); + + /* FIXME: we should not __copy__ the message */ + ref->AddMessage( message, field_desc )->CopyFrom( *mess ) ; + } + } else if( TYPEOF(value) == VECSXP ) { + /* in any case, fill the values up to field_size */ + int i = 0; + for( ; iMutableRepeatedMessage(message, field_desc, i )->CopyFrom( *mess ) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddMessage(message, field_desc)->CopyFrom( *mess ) ; + } + } + } else{ + throwException( "type mismatch, expecting a 'Message' object or a list of them", "TypeMismatchException" ) ; + } + break ; + } + // }}} + + // {{{ enum + case TYPE_ENUM : + { + const GPB::EnumDescriptor* enum_desc = field_desc->enum_type() ; + + switch( TYPEOF( value ) ){ + // {{{ numbers + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: + { + int i = 0; + /* in any case, fill the values up to field_size */ + for( ; iSetRepeatedEnum( message, field_desc, i, + enum_desc->FindValueByNumber(val) ) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iAddEnum( message, field_desc, + enum_desc->FindValueByNumber(val) ) ; + } + } + break ; + } + // }}} + + // {{{ STRSXP + case STRSXP: + { + /* in any case, fill the values up to field_size */ + int i = 0; + for( ; iFindValueByName(val) ; + ref->SetRepeatedEnum( message, field_desc, i, evd ) ; + } + + /* then add some if needed */ + if( value_size > field_size ){ + for( ; iFindValueByName(val) ; + ref->AddEnum( message, field_desc, evd ) ; + } + } + break ; + } + // }}} + + // {{{ default + default: + { + throwException( "cannot set enum value", "WrongTypeEnumValueException" ) ; + } + // }}} + } + } + // }}} + } + // }}} +} + +/** * set a message field to a new value * * @param pointer external pointer to a message @@ -402,12 +1250,10 @@ PRINT_DEBUG_INFO( "value", value ) ; #endif + try { /* grab the Message pointer */ GPB::Message* message = GET_MESSAGE_POINTER_FROM_XP(pointer) ; - /* the message descriptor */ - // const GPB::Descriptor* desc = message->GetDescriptor() ; - /* check that we can get a file descriptor from name */ GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, name ); @@ -443,802 +1289,17 @@ // }}} if( field_desc->is_repeated() ){ - // {{{ repeated fields - - // The number of elements already in the repeated field. - int field_size = ref->FieldSize( *message, field_desc ) ; - - /* {{{ in case of messages or enum, we have to check that all values - are ok before doing anything, othewise this could leed to modify a few values - and then fail which is not good */ - - switch( field_desc->type() ){ - case TYPE_MESSAGE: - case TYPE_GROUP: - { - switch( TYPEOF( value ) ){ - case VECSXP : - { - /* check that it is a list of Messages of the appropriate type */ - for( int i=0; imessage_type()->full_name().c_str() ) ){ - /* TODO: include i, target type and actual type in the message */ - throwException( "incorrect type", "IncorrectMessageTypeException" ) ; - } - } - break ; - } - case S4SXP: - { - /* check that this is a message of the appropriate type */ - if( !isMessage( value, field_desc->message_type()->full_name().c_str() ) ){ - throwException( "incorrect type", "IncorrectMessageTypeException" ) ; - } - break ; - } - default: - { - throwException( "impossible to convert to a message" , "ConversionException" ) ; - } - } - break ; - } - case TYPE_ENUM : - { - const GPB::EnumDescriptor* enum_desc = field_desc->enum_type() ; - - /* check first, it means we have to loop twice, but - otherwise this could have some side effects before - the exception is thrown */ - - /* FIXME: the checking should go before the resizing */ - - switch( TYPEOF( value ) ){ - // {{{ numbers - case INTSXP: - case REALSXP: - case LGLSXP: - case RAWSXP: - { - int nenums = enum_desc->value_count() ; - std::vector possibles(nenums) ; - for( int i=0; i< nenums; i++){ - possibles[i] = enum_desc->value(i)->number(); - } - - /* loop around the numbers to see if they are in the possibles */ - for( int i=0; ivalue_count() ; - std::vector possibles(nenums) ; - for( int i=0; i< nenums; i++){ - possibles[i] = enum_desc->value(i)->name() ; - } - - /* loop around the numbers to see if they are in the possibles */ - for( int i=0; i Author: murray Date: 2013-12-27 09:36:02 +0100 (Fri, 27 Dec 2013) New Revision: 605 Modified: pkg/ChangeLog pkg/src/mutators.cpp Log: Make field_desc const and update email address. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-27 08:27:34 UTC (rev 604) +++ pkg/ChangeLog 2013-12-27 08:36:02 UTC (rev 605) @@ -1,4 +1,4 @@ -2013-12-27 Murray Stokely +2013-12-27 Murray Stokely * src/mutators.cpp: Refactor setMessageField into four separate functions, correct a few minor typos, and wrap everything in a Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-27 08:27:34 UTC (rev 604) +++ pkg/src/mutators.cpp 2013-12-27 08:36:02 UTC (rev 605) @@ -387,7 +387,7 @@ * otherwise this could lead to modifying a few values then failing in * an inconsistent state. */ -void CHECK_repeated_vals(GPB::FieldDescriptor* field_desc, +void CHECK_repeated_vals(const GPB::FieldDescriptor* field_desc, SEXP value, int value_size) { switch( field_desc->type() ){ case TYPE_MESSAGE: @@ -530,7 +530,7 @@ */ void setNonRepeatedMessageField(GPB::Message* message, const Reflection* ref, - GPB::FieldDescriptor* field_desc, + const GPB::FieldDescriptor* field_desc, SEXP value, int value_size) { if (value_size > 1) { throwException( "cannot set non-repeated field to vector of length > 1", @@ -748,7 +748,7 @@ void setRepeatedMessageField(GPB::Message* message, const Reflection* ref, - GPB::FieldDescriptor* field_desc, + const GPB::FieldDescriptor* field_desc, SEXP value, int value_size) { // The number of elements already in the repeated field. int field_size = ref->FieldSize( *message, field_desc ) ; @@ -1255,7 +1255,7 @@ GPB::Message* message = GET_MESSAGE_POINTER_FROM_XP(pointer) ; /* check that we can get a file descriptor from name */ - GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, name ); + const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, name ); const Reflection * ref = message->GetReflection() ; From noreply at r-forge.r-project.org Fri Dec 27 09:52:32 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 09:52:32 +0100 (CET) Subject: [Rprotobuf-commits] r606 - in pkg: . inst/unitTests Message-ID: <20131227085232.7A359186710@r-forge.r-project.org> Author: murray Date: 2013-12-27 09:52:31 +0100 (Fri, 27 Dec 2013) New Revision: 606 Added: pkg/inst/unitTests/runit.messages.R Modified: pkg/ChangeLog Log: Add unit tests for our handling of setting repeated message fields. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-27 08:36:02 UTC (rev 605) +++ pkg/ChangeLog 2013-12-27 08:52:31 UTC (rev 606) @@ -5,6 +5,8 @@ try/catch block so we catch any exceptions generated by Rcpp::as or other functions and forward it along to an R-language stop() error instead of terminating our R instance. + * inst/unitTests/runit.messages.R (test.message): Add unit tests + for our handling of setting repeated message fields. 2013-12-26 Murray Stokely Added: pkg/inst/unitTests/runit.messages.R =================================================================== --- pkg/inst/unitTests/runit.messages.R (rev 0) +++ pkg/inst/unitTests/runit.messages.R 2013-12-27 08:52:31 UTC (rev 606) @@ -0,0 +1,47 @@ +# Copyright 2013 Google Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +test.message <- function() { + if (!exists("protobuf_unittest.TestAllTypes", + "RProtoBuf:DescriptorPool")) { + unittest.proto.file <- system.file("unitTests", "data", + "unittest.proto", + package="RProtoBuf") + readProtoFiles(file=unittest.proto.file) + } + a <- new(protobuf_unittest.TestAllTypes) + a$repeated_nested_message <- list( + new(protobuf_unittest.TestAllTypes.NestedMessage, bb=3), + new(protobuf_unittest.TestAllTypes.NestedMessage, bb=4)) + checkEquals(a$repeated_nested_message[[1]]$bb, 3) + checkEquals(a$repeated_nested_message[[2]]$bb, 4) + + checkException(a$repeated_nested_message <- list( + new(protobuf_unittest.ForeignMessage, c=1), + new(protobuf_unittest.TestAllTypes.NestedMessage, bb=4))) + + checkException(a$repeated_nested_message <- list( + new(protobuf_unittest.TestAllTypes.NestedMessage, bb=4), + new(protobuf_unittest.ForeignMessage, c=1))) + + checkException(a$repeated_nested_message <- list( + new(protobuf_unittest.TestAllTypes.NestedMessage, bb=4), + 3)) + + checkException(a$repeated_nested_message <- list( + new(protobuf_unittest.TestAllTypes.NestedMessage, bb=4), + "foo")) +} From noreply at r-forge.r-project.org Fri Dec 27 10:11:22 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 10:11:22 +0100 (CET) Subject: [Rprotobuf-commits] r607 - in pkg: . src Message-ID: <20131227091122.155311813C8@r-forge.r-project.org> Author: murray Date: 2013-12-27 10:11:21 +0100 (Fri, 27 Dec 2013) New Revision: 607 Modified: pkg/ChangeLog pkg/src/mutators.cpp pkg/src/rprotobuf.h pkg/src/wrapper_Message.cpp Log: More const correctness for field_desc type throughout, which then lets us remove a small amount of duplicate code and reuse a function. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-27 08:52:31 UTC (rev 606) +++ pkg/ChangeLog 2013-12-27 09:11:21 UTC (rev 607) @@ -7,6 +7,8 @@ error instead of terminating our R instance. * inst/unitTests/runit.messages.R (test.message): Add unit tests for our handling of setting repeated message fields. + * src/wrapper_Message.cpp: Add const qualifier to + field_desc throughout file. 2013-12-26 Murray Stokely Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-27 08:52:31 UTC (rev 606) +++ pkg/src/mutators.cpp 2013-12-27 09:11:21 UTC (rev 607) @@ -288,7 +288,7 @@ * @param value value to potentially fill the enum * */ -void CHECK_values_for_enum( GPB::FieldDescriptor* field_desc, SEXP value ){ +void CHECK_values_for_enum( const GPB::FieldDescriptor* field_desc, SEXP value ){ const GPB::EnumDescriptor* enum_desc = field_desc->enum_type() ; // N.B. n undefined if TYPEOF(value) not a vector, but we catch that below. @@ -365,7 +365,7 @@ /** * check that the values are suitable for the field descriptor */ -void CHECK_messages( GPB::FieldDescriptor* field_desc, SEXP values ){ +void CHECK_messages( const GPB::FieldDescriptor* field_desc, SEXP values ){ if( TYPEOF( values ) != VECSXP ){ throwException( "expecting a list of messages", "ConversionException" ) ; @@ -396,26 +396,25 @@ switch( TYPEOF( value ) ){ case VECSXP : { - /* check that it is a list of Messages of the appropriate type */ - for( int i=0; imessage_type()->full_name().c_str() ) ){ - /* TODO: include i, target type and actual type in the message */ - throwException( "incorrect type", "IncorrectMessageTypeException" ) ; - } - } + + /* check that it is a list of Messages of the + appropriate type */ + CHECK_messages(field_desc, value); break ; } case S4SXP: { /* check that this is a message of the appropriate type */ - if( !isMessage( value, field_desc->message_type()->full_name().c_str() ) ){ + if( !isMessage( value, + field_desc->message_type()->full_name().c_str() ) ){ throwException( "incorrect type", "IncorrectMessageTypeException" ) ; } break ; } default: { - throwException( "impossible to convert to a message" , "ConversionException" ) ; + throwException( "impossible to convert to a message" , + "ConversionException" ) ; } } break ; Modified: pkg/src/rprotobuf.h =================================================================== --- pkg/src/rprotobuf.h 2013-12-27 08:52:31 UTC (rev 606) +++ pkg/src/rprotobuf.h 2013-12-27 09:11:21 UTC (rev 607) @@ -148,8 +148,8 @@ bool GET_bool( SEXP, int) ; std::string GET_stdstring( SEXP, int ) ; std::string GET_bytes( SEXP, int ) ; -void CHECK_values_for_enum( GPB::FieldDescriptor*, SEXP) ; -void CHECK_messages( GPB::FieldDescriptor*, SEXP) ; +void CHECK_values_for_enum( const GPB::FieldDescriptor*, SEXP) ; +void CHECK_messages( const GPB::FieldDescriptor*, SEXP) ; /* in wrapper_ServiceDescriptor.cpp */ RcppExport SEXP ServiceDescriptor_length(SEXP); Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-12-27 08:52:31 UTC (rev 606) +++ pkg/src/wrapper_Message.cpp 2013-12-27 09:11:21 UTC (rev 607) @@ -167,7 +167,7 @@ * @param field name or tag of the field */ RPB_FUNCTION_VOID_2(METHOD(clear_field), Rcpp::XPtr m, SEXP field ){ - GPB::FieldDescriptor* field_desc = getFieldDescriptor( m, field ) ; + const GPB::FieldDescriptor* field_desc = getFieldDescriptor( m, field ) ; const GPB::Reflection* ref = m->GetReflection(); ref->ClearField( m, field_desc ) ; } @@ -258,7 +258,7 @@ RPB_FUNCTION_2( int, METHOD(field_size), Rcpp::XPtr message, SEXP field ){ - GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ; + const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ; int res = 0 ; if( field_desc->is_repeated() ){ @@ -276,7 +276,7 @@ RPB_FUNCTION_VOID_3( METHOD(set_field_size), Rcpp::XPtr message, SEXP field, int target){ - GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ; + const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ; const GPB::Reflection* ref = message->GetReflection() ; if( field_desc->is_repeated() ){ @@ -688,7 +688,7 @@ */ RPB_FUNCTION_VOID_3( METHOD(add_values), Rcpp::XPtr message, SEXP field, SEXP values){ const Reflection * ref = message->GetReflection() ; - GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ); + const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ); if( values == R_NilValue || LENGTH(values) == 0 ){ return ; @@ -1076,7 +1076,7 @@ */ RPB_FUNCTION_VOID_4( METHOD(set_field_values), Rcpp::XPtr message, SEXP field, Rcpp::IntegerVector index, SEXP values ){ - GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ; + const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ; if( !field_desc->is_repeated() ){ throw std::range_error( "set can only be used on repeated fields" ) ; } From noreply at r-forge.r-project.org Fri Dec 27 21:04:30 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 21:04:30 +0100 (CET) Subject: [Rprotobuf-commits] r608 - in pkg: . R src Message-ID: <20131227200430.8AE621868F3@r-forge.r-project.org> Author: murray Date: 2013-12-27 21:04:29 +0100 (Fri, 27 Dec 2013) New Revision: 608 Removed: pkg/R/exceptions.R pkg/src/exceptions.cpp Modified: pkg/ChangeLog pkg/src/extractors.cpp pkg/src/mutators.cpp pkg/src/rprotobuf.cpp pkg/src/wrapper_EnumDescriptor.cpp pkg/src/wrapper_FieldDescriptor.cpp pkg/src/wrapper_Message.cpp pkg/src/wrapper_ServiceDescriptor.cpp Log: Remove ancient exception handling code and migrate the codebase to use the standard exception classes and helper functions from Rcpp. Some whitespace changes were necessary to clean up the indentation, which identified additional minor cut-and-paste bugs which have been corrected. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-27 09:11:21 UTC (rev 607) +++ pkg/ChangeLog 2013-12-27 20:04:29 UTC (rev 608) @@ -9,6 +9,10 @@ for our handling of setting repeated message fields. * src/wrapper_Message.cpp: Add const qualifier to field_desc throughout file. + * src/exceptions.cpp: Remove ancient exceptions handling code, + migrate codebase to use standard exception classes and helper + functions from Rcpp. + * R/exceptions.R (throw): idem. 2013-12-26 Murray Stokely Deleted: pkg/R/exceptions.R =================================================================== --- pkg/R/exceptions.R 2013-12-27 09:11:21 UTC (rev 607) +++ pkg/R/exceptions.R 2013-12-27 20:04:29 UTC (rev 608) @@ -1,23 +0,0 @@ - -#' throw a particular protobuf error condition -#' all conditions have the class "ProtobufError", "error" and "condition" -#' plus any number of classes as defined by the class argument -#' -#' @param message the message of the error -#' @param class the sub class of the condition - -# this is exported at the moment, but I would prefer it not to be -# so need to find a way to call a namespace private function from the -# C call -throw <- function( message = " error", class = NULL ){ - - callstack <- sys.calls() - ncalls <- length(callstack) - call <- if( ncalls > 1L) callstack[[ ncalls - 1L ]] else match.call() - classes <- c( class, "ProtobufError", "error", "condition" ) - condition <- structure( - list( message = message, call = call ), - class = classes ) - stop( condition ) -} - Deleted: pkg/src/exceptions.cpp =================================================================== --- pkg/src/exceptions.cpp 2013-12-27 09:11:21 UTC (rev 607) +++ pkg/src/exceptions.cpp 2013-12-27 20:04:29 UTC (rev 608) @@ -1,29 +0,0 @@ -#include "rprotobuf.h" - -namespace rprotobuf{ - -/* FIXME: this has got to disappear */ - -/** - * create a call to throw an evaluate it - * - * @param message the message - * @param subclass the subclass to use (to allow direct handlers in tryCatch) - */ -SEXP throwException( const char* message, const char* subclass ){ - - SEXP m = PROTECT( Rf_mkString( message ) ) ; - SEXP s = PROTECT( Rf_mkString( subclass ) ) ; - - SEXP call = PROTECT( Rf_lang3( Rf_install("throw"), m, s) ) ; - UNPROTECT( 2) ; /* m, s */ - - Rf_eval( call, R_FindNamespace(Rf_mkString("RProtoBuf")) ) ; - - /* but this is never actually called since the call eventually calls stop */ - UNPROTECT(1); - return( R_NilValue ); /* Wall */ -} - -} // namespace rprotobuf - Modified: pkg/src/extractors.cpp =================================================================== --- pkg/src/extractors.cpp 2013-12-27 09:11:21 UTC (rev 607) +++ pkg/src/extractors.cpp 2013-12-27 20:04:29 UTC (rev 608) @@ -35,18 +35,20 @@ // So, if an option is set, we return as a character string. template SEXP Int64AsSEXP(ValueType value) { - if (UseStringsForInt64()) { - std::stringstream ss; - if ((ss << value).fail()) { - // This should not happen, its a bug in the code. - string message = string("Error converting int64 to string, unset ") + + BEGIN_RCPP + if (UseStringsForInt64()) { + std::stringstream ss; + if ((ss << value).fail()) { + // This should not happen, its a bug in the code. + string message = string("Error converting int64 to string, unset ") + kIntStringOptionName + " option."; - throwException(message.c_str(), "ConversionException"); + Rcpp::throw(message.c_str()); + } + return Rcpp::CharacterVector(ss.str()); + } else { + return Rcpp::wrap(value); } - return Rcpp::CharacterVector(ss.str()); - } else { - return Rcpp::wrap(value); - } + END_RCPP } /** @@ -82,7 +84,7 @@ SEXP extractFieldAsSEXP( const Rcpp::XPtr& message, const GPB::FieldDescriptor* fieldDesc ){ - + BEGIN_RCPP const Reflection * ref = message->GetReflection() ; if( fieldDesc->is_repeated() ){ @@ -137,15 +139,14 @@ } return res; } else { - throwException( "unknown field type with CPP_TYPE STRING", "ConversionException" ) ; + Rcpp::throw("unknown field type with CPP_TYPE STRING"); } default: - throwException("Unsupported type", "ConversionException"); + Rcpp::throw("Unsupported type"); } } else { - switch( GPB::FieldDescriptor::TypeToCppType(fieldDesc->type()) ){ #undef HANDLE_SINGLE_FIELD @@ -175,7 +176,7 @@ std::string s = ref->GetString(*message, fieldDesc); return Rcpp::wrap(std::vector(s.begin(), s.end())); } else { - throwException( "unknown field type with CPP_TYPE STRING", "ConversionException" ) ; + Rcpp::throw("unknown field type with CPP_TYPE STRING"); } case CPPTYPE_ENUM : return Rcpp::wrap( ref->GetEnum( *message, fieldDesc )->number() ) ; @@ -185,11 +186,11 @@ break ; default: - throwException("Unsupported type", "ConversionException"); + Rcpp::throw("Unsupported type"); } } - return R_NilValue ; /* -Wall */ + END_RCPP } } // namespace rprotobuf Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-27 09:11:21 UTC (rev 607) +++ pkg/src/mutators.cpp 2013-12-27 20:04:29 UTC (rev 608) @@ -31,11 +31,12 @@ * @param x some R data * @param index the index * @return x[index], as an double - * @throws CastException if x[index] cannot be converted to double + * @throws Rcpp::exception if x[index] cannot be converted to double */ /* FIXME: should we convert the NA's */ double GET_double( SEXP x, int index ){ - switch( TYPEOF(x) ){ + try { + switch( TYPEOF(x) ){ case INTSXP: return( (double)INTEGER(x)[index] ) ; case REALSXP: @@ -45,14 +46,18 @@ case RAWSXP: return( (double)RAW(x)[index] ) ; default: - throwException( "cannot cast SEXP to double", "CastException" ) ; + Rcpp::throw("cannot cast SEXP to double"); + } + } catch(std::exception &ex) { + forward_exception_to_r(ex); } return 0.0 ; // -Wall } // }}} float GET_float( SEXP x, int index ){ - switch( TYPEOF(x) ){ + try { + switch( TYPEOF(x) ){ case INTSXP: return( (float)INTEGER(x)[index] ) ; case REALSXP: @@ -62,13 +67,17 @@ case RAWSXP: return( (float)RAW(x)[index] ) ; default: - throwException( "cannot cast SEXP to double", "CastException" ) ; + Rcpp::throw("cannot cast SEXP to double"); + } + } catch(std::exception &ex) { + forward_exception_to_r(ex); } return (float)0.0 ; // -Wall } int GET_int( SEXP x, int index ){ - switch( TYPEOF(x) ){ + try { + switch( TYPEOF(x) ){ case INTSXP: return( INTEGER(x)[index] ); case REALSXP: @@ -78,37 +87,49 @@ case RAWSXP: return( (int)RAW(x)[index] ) ; default: - throwException( "cannot cast SEXP to int", "CastException" ) ; + Rcpp::throw( "cannot cast SEXP to int" ); + } + } catch(std::exception &ex) { + forward_exception_to_r(ex); } return 0 ; // -Wall, should not happen since we only call this when we know it works } template ValueType Int64FromString(const string &value) { - std::stringstream ss(value); - ValueType ret; - if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { - string message = "Provided character value '" + value + + try { + std::stringstream ss(value); + ValueType ret; + if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { + string message = "Provided character value '" + value + "' cannot be cast to 64-bit integer."; - throwException(message.c_str(), "CastException"); - } - return ret; + Rcpp::throw(message.c_str()); + } + return ret; + } catch(std::exception &ex) { + forward_exception_to_r(ex); + } } template ValueType Int32FromString(const string &value) { - std::stringstream ss(value); - ValueType ret; - if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { - string message = "Provided character value '" + value + + try { + std::stringstream ss(value); + ValueType ret; + if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { + string message = "Provided character value '" + value + "' cannot be cast to 32-bit integer."; - throwException(message.c_str(), "CastException"); - } - return ret; + Rcpp::throw(message.c_str()); + } + return ret; + } catch(std::exception &ex) { + forward_exception_to_r(ex); + } } int32 GET_int32( SEXP x, int index ){ - switch( TYPEOF(x) ){ + try { + switch( TYPEOF(x) ){ case INTSXP: return( (int32)INTEGER(x)[index] ); case REALSXP: @@ -120,13 +141,17 @@ case STRSXP: return Int32FromString(CHAR(STRING_ELT(x, index))); default: - throwException( "cannot cast SEXP to int32", "CastException" ) ; + Rcpp::throw( "cannot cast SEXP to int32"); + } + } catch(std::exception &ex) { + forward_exception_to_r(ex); } return (int32)0 ; // -Wall, should not happen since we only call this when we know it works } int64 GET_int64( SEXP x, int index ){ - switch( TYPEOF(x) ){ + try { + switch( TYPEOF(x) ){ case INTSXP: return( (int64)INTEGER(x)[index] ); case REALSXP: @@ -138,13 +163,17 @@ case STRSXP: return Int64FromString(CHAR(STRING_ELT(x, index))); default: - throwException( "cannot cast SEXP to int64", "CastException" ) ; + Rcpp::throw("cannot cast SEXP to int64"); + } + } catch(std::exception &ex) { + forward_exception_to_r(ex); } return (int64)0 ; // -Wall, should not happen since we only call this when we know it works } uint32 GET_uint32( SEXP x, int index ){ - switch( TYPEOF(x) ){ + try { + switch( TYPEOF(x) ){ case INTSXP: return( (uint32)INTEGER(x)[index] ); case REALSXP: @@ -156,13 +185,17 @@ case STRSXP: return Int32FromString(CHAR(STRING_ELT(x, index))); default: - throwException( "cannot cast SEXP to uint32", "CastException" ) ; + Rcpp::throw("cannot cast SEXP to uint32"); + } + } catch(std::exception &ex) { + forward_exception_to_r(ex); } return (uint32)0 ; // -Wall, should not happen since we only call this when we know it works } uint64 GET_uint64( SEXP x, int index ){ - switch( TYPEOF(x) ){ + try { + switch( TYPEOF(x) ){ case INTSXP: return( (uint64)INTEGER(x)[index] ); case REALSXP: @@ -174,38 +207,42 @@ case STRSXP: return Int64FromString(CHAR(STRING_ELT(x, index))); default: - throwException( "cannot cast SEXP to uint64", "CastException" ) ; + Rcpp::throw("cannot cast SEXP to uint64"); + } + } catch(std::exception &ex) { + forward_exception_to_r(ex); } return (uint64)0 ; // -Wall, should not happen since we only call this when we know it works } bool GET_bool( SEXP x, int index ){ - switch( TYPEOF(x) ){ + try { + switch( TYPEOF(x) ){ case INTSXP: if (INTEGER(x)[index] == R_NaInt) { - throwException( "NA boolean values can not be stored in " - "bool protocol buffer fields", - "CastException" ) ; + Rcpp::throw("NA boolean values can not be stored in " + "bool protocol buffer fields"); } return( (bool)INTEGER(x)[index] ); case REALSXP: if (REAL(x)[index] == R_NaReal) { - throwException( "NA boolean values can not be stored in " - "bool protocol buffer fields", - "CastException" ) ; + Rcpp::throw("NA boolean values can not be stored in " + "bool protocol buffer fields"); } return( (bool)REAL(x)[index] ); case LGLSXP: if (LOGICAL(x)[index] == NA_LOGICAL) { - throwException( "NA boolean values can not be stored in " - "bool protocol buffer fields", - "CastException" ) ; + Rcpp::throw("NA boolean values can not be stored in " + "bool protocol buffer fields"); } return( (bool)LOGICAL(x)[index] ); case RAWSXP: return( (bool)RAW(x)[index] ) ; default: - throwException( "cannot cast SEXP to bool", "CastException" ) ; + Rcpp::throw("cannot cast SEXP to bool"); + } + } catch(std::exception &ex) { + forward_exception_to_r(ex); } return (bool)0 ; // -Wall, should not happen since we only call this when we know it works } @@ -218,21 +255,25 @@ } std::string GET_bytes( SEXP x, int index ){ - switch( TYPEOF(x)) { + try { + switch( TYPEOF(x)) { case RAWSXP: if (index == 0) { return(std::string((const char *) RAW(x), (size_t) LENGTH(x))); } else { - throwException( "cannot cast SEXP to bytes", "CastException" ) ; + Rcpp::throw("cannot cast SEXP to bytes"); } case VECSXP: if (TYPEOF(VECTOR_ELT(x, index)) == RAWSXP) { return(std::string((const char *) RAW(VECTOR_ELT(x, index)), (size_t) LENGTH(VECTOR_ELT(x, index)))); } else { - throwException( "cannot cast SEXP to bytes", "CastException" ) ; + Rcpp::throw("cannot cast SEXP to bytes"); } default: - throwException( "cannot cast SEXP to bytes", "CastException" ) ; + Rcpp::throw("cannot cast SEXP to bytes"); + } + } catch(std::exception &ex) { + forward_exception_to_r(ex); } return "" ; // -Wall, should not happen since we only call this when we know it works } @@ -289,7 +330,7 @@ * */ void CHECK_values_for_enum( const GPB::FieldDescriptor* field_desc, SEXP value ){ - + BEGIN_RCPP const GPB::EnumDescriptor* enum_desc = field_desc->enum_type() ; // N.B. n undefined if TYPEOF(value) not a vector, but we catch that below. int n = LENGTH(value) ; @@ -318,7 +359,7 @@ } } if( !ok ){ - throwException( "wrong value for enum", "WrongEnumValueException" ) ; + Rcpp::throw("wrong value for enum"); } } @@ -347,28 +388,26 @@ } } if( !ok ){ - throwException( "wrong value for enum", "WrongEnumValueException" ) ; + Rcpp::throw("wrong value for enum"); } } - break ; } // }}} default: - throwException( "impossible to convert to a enum" , "ConversionException" ) ; + Rcpp::throw("impossible to convert to a enum"); } - - + VOID_END_RCPP } /** * check that the values are suitable for the field descriptor */ void CHECK_messages( const GPB::FieldDescriptor* field_desc, SEXP values ){ - + BEGIN_RCPP if( TYPEOF( values ) != VECSXP ){ - throwException( "expecting a list of messages", "ConversionException" ) ; + Rcpp::throw("expecting a list of messages"); } const char* target = field_desc->message_type()->full_name().c_str() ; @@ -376,10 +415,10 @@ for( int i=0; itype() ){ case TYPE_MESSAGE: case TYPE_GROUP: @@ -407,14 +447,13 @@ /* check that this is a message of the appropriate type */ if( !isMessage( value, field_desc->message_type()->full_name().c_str() ) ){ - throwException( "incorrect type", "IncorrectMessageTypeException" ) ; + Rcpp::throw("incorrect type"); } break ; } default: { - throwException( "impossible to convert to a message" , - "ConversionException" ) ; + Rcpp::("impossible to convert to a message"); } } break ; @@ -453,7 +492,7 @@ } } if( !ok ){ - throwException( "wrong value for enum", "WrongEnumValueException" ) ; + Rcpp::throw("wrong value for enum"); } } break ; @@ -481,7 +520,7 @@ } } if( !ok ){ - throwException( "wrong value for enum", "WrongEnumValueException" ) ; + Rcpp::throw("wrong value for enum"); } } @@ -490,7 +529,7 @@ // }}} default: - throwException( "impossible to convert to a enum" , "ConversionException" ) ; + Rcpp::throw("impossible to convert to a enum"); } break ; } @@ -514,6 +553,7 @@ } } // }}} + VOID_END_RCPP } /** @@ -524,7 +564,7 @@ * @param field_desc pointer to field descriptor to update * @param value new value for the field * @param value_size size of the new value for the field - * + * @throws Rcpp::exception on error (uncaught) * @return void, the message is modified by reference */ void setNonRepeatedMessageField(GPB::Message* message, @@ -532,8 +572,7 @@ const GPB::FieldDescriptor* field_desc, SEXP value, int value_size) { if (value_size > 1) { - throwException( "cannot set non-repeated field to vector of length > 1", - "CastException" ) ; + Rcpp::throw("cannot set non-repeated field to vector of length > 1"); } switch( GPB::FieldDescriptor::TypeToCppType( field_desc->type() ) ){ // {{{ simple cases using macro expansion @@ -552,19 +591,16 @@ // TODO(mstokely): Rcpp should handle this! if ((TYPEOF(value) == LGLSXP) && (LOGICAL(value)[0] == NA_LOGICAL)) { - throwException("NA boolean values can not be stored in " - "bool protocol buffer fields", - "CastException"); + Rcpp::throw("NA boolean values can not be stored in " + "bool protocol buffer fields"); } else if ((TYPEOF(value) == INTSXP) && (INTEGER(value)[0] == R_NaInt)) { - throwException( "NA boolean values can not be stored in " - "bool protocol buffer fields", - "CastException"); + Rcpp::throw("NA boolean values can not be stored in " + "bool protocol buffer fields"); } else if ((TYPEOF(value) == REALSXP) && (REAL(value)[0] == R_NaReal)) { - throwException( "NA boolean values can not be stored in " - "bool protocol buffer fields", - "CastException"); + Rcpp::throw("NA boolean values can not be stored in " + "bool protocol buffer fields"); } ref->SetBool(message, field_desc, Rcpp::as(value)); break ; @@ -631,7 +667,7 @@ #endif #undef HANDLE_SINGLE_FIELD default: - throwException("Unsupported type", "ConversionException"); + Rcpp::throw("Unsupported type"); // }}} // {{{ string @@ -653,8 +689,7 @@ { /* check if value is a message */ if( !Rf_inherits( value, "Message" ) ){ - throwException( "Can only convert S4 objects of class 'Message'", - "ConversionException" ) ; + Rcpp::throw("Can only convert S4 objects of class 'Message'"); } GPB::Message* __mess = GET_MESSAGE_POINTER_FROM_S4(value); ref->SetString(message, field_desc, @@ -663,8 +698,7 @@ } default: { - throwException( "Cannot convert to string", - "ConversionException" ) ; + Rcpp::throw("Cannot convert to string"); } } break ; @@ -679,13 +713,12 @@ const char* type = mess->GetDescriptor()->full_name().c_str() ; const char* target = field_desc->message_type()->full_name().c_str() ; if( strcmp( type, target ) ){ - throwException( "wrong message type", "WrongMessageException" ) ; + Rcpp::throw("wrong message type"); } GPB::Message* m = ref->MutableMessage( message, field_desc ) ; m->CopyFrom( *mess ) ; } else { - throwException( "type mismatch, expecting a 'Message' object", - "TypeMismatchException" ) ; + Rcpp::throw("type mismatch, expecting a 'Message' object"); } break ; } @@ -704,8 +737,7 @@ int val = Rcpp::as(value) ; const GPB::EnumValueDescriptor* evd = enum_desc->FindValueByNumber(val) ; if( !evd ){ - throwException( "wrong value for enum", - "WrongEnumValueException" ) ; + Rcpp::throw("wrong value for enum"); } else { ref->SetEnum( message, field_desc, evd ); } @@ -716,7 +748,7 @@ std::string val = Rcpp::as( value ) ; const GPB::EnumValueDescriptor* evd = enum_desc->FindValueByName(val) ; if( !evd ){ - throwException( "wrong value for enum", "WrongEnumValueException" ) ; + Rcpp::throw("wrong value for enum"); } else { ref->SetEnum( message, field_desc, evd ); } @@ -724,7 +756,7 @@ } default: { - throwException( "cannot set enum value", "WrongTypeEnumValueException" ) ; + Rcpp::throw("cannot set enum value"); } } } @@ -741,7 +773,7 @@ * @param field_desc pointer to field descriptor to update * @param value new value for the field * @param value_size size of the new value for the field - * + * @throws Rcpp::exception on error (uncaught) * @return void, the message is modified by reference */ @@ -799,8 +831,7 @@ default: { - throwException( "Cannot convert to int32", - "ConversionException" ) ; + Rcpp::throw("Cannot convert to int32"); } } break ; @@ -838,8 +869,7 @@ } default: - throwException( "Cannot convert to int64", - "ConversionException" ) ; + Rcpp::throw("Cannot convert to int64"); } break ; } @@ -873,8 +903,7 @@ break ; } default: - throwException( "Cannot convert to uint32", - "ConversionException" ) ; + Rcpp::throw("Cannot convert to uint32"); } break ; } @@ -908,8 +937,7 @@ break ; } default: - throwException( "Cannot convert to int64", - "ConversionException" ) ; + Rcpp::throw("Cannot convert to int64"); } break ; } @@ -940,8 +968,7 @@ break ; } default: - throwException( "Cannot convert to double", - "ConversionException" ) ; + Rcpp::throw("Cannot convert to double"); } break ; } @@ -973,8 +1000,7 @@ break ; } default: - throwException( "Cannot convert to float", - "ConversionException" ) ; + Rcpp::throw("Cannot convert to float"); } break ; } @@ -1006,8 +1032,7 @@ break ; } default: - throwException( "Cannot convert to bool", - "ConversionException" ) ; + Rcpp::throw("Cannot convert to bool"); } break ; } @@ -1058,8 +1083,7 @@ { /* check if value is a message */ if( !Rf_inherits( value, "Message" ) ){ - throwException( "Can only convert S4 objects of class 'Message' ", - "ConversionException" ) ; + Rcpp::throw("Can only convert S4 objects of class 'Message'"); } GPB::Message* __mess = GET_MESSAGE_POINTER_FROM_S4( value ) ; ref->SetRepeatedString(message, field_desc, 0, @@ -1110,8 +1134,7 @@ break ; } default: - throwException( "Cannot convert to string", - "ConversionException" ) ; + Rcpp::throw("Cannot convert to string"); } break ; } @@ -1156,7 +1179,7 @@ } } } else{ - throwException( "type mismatch, expecting a 'Message' object or a list of them", "TypeMismatchException" ) ; + Rcpp::throw("type mismatch, expecting a 'Message' object or a list of them"); } break ; } @@ -1220,7 +1243,7 @@ // {{{ default default: { - throwException( "cannot set enum value", "WrongTypeEnumValueException" ) ; + Rcpp::throw("cannot set enum value"); } // }}} } @@ -1240,6 +1263,7 @@ * @return allways NULL, the message is modified by reference */ SEXP setMessageField( SEXP pointer, SEXP name, SEXP value ){ + BEGIN_RCPP // {{{ grab data #ifdef RPB_DEBUG Rprintf( "\n" ) ; @@ -1249,7 +1273,6 @@ PRINT_DEBUG_INFO( "value", value ) ; #endif - try { /* grab the Message pointer */ GPB::Message* message = GET_MESSAGE_POINTER_FROM_XP(pointer) ; @@ -1282,7 +1305,7 @@ } else if( TYPEOF(value) == VECSXP && allAreRaws( value ) ){ value_size = LENGTH(value) ; } else { - throwException( "cannot convert to string", "ConversionException" ) ; + Rcpp::throw("cannot convert to string"); } } // }}} @@ -1295,10 +1318,7 @@ #ifdef RPB_DEBUG Rprintf( "\n" ) ; #endif - return R_NilValue ; - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } + END_RCPP } RPB_FUNCTION_VOID_2( update_message, Rcpp::XPtr message, Rcpp::List list ){ Modified: pkg/src/rprotobuf.cpp =================================================================== --- pkg/src/rprotobuf.cpp 2013-12-27 09:11:21 UTC (rev 607) +++ pkg/src/rprotobuf.cpp 2013-12-27 20:04:29 UTC (rev 608) @@ -123,7 +123,7 @@ * @param descriptor a "Descriptor" R object */ SEXP newProtoMessage( SEXP descriptor ){ - + try { #ifdef RPB_DEBUG Rprintf( "\n" ) ; /* FIXME: the message type, we don't really need that*/ @@ -141,13 +141,16 @@ /* grab the Message from the factory */ const GPB::Message* message = PROTOTYPE( desc ) ; if( !message ){ - throwException( "could not call factory->GetPrototype(desc)->New()", "MessageCreationException" ) ; + Rcpp_error("could not call factory->GetPrototype(desc)->New()"); } #ifdef RPB_DEBUG Rprintf( "\n" ) ; #endif return( S4_Message( message ) ) ; + } catch(std::exception &ex) { + forward_exception_to_r(ex); + } } /** @@ -221,6 +224,7 @@ GPB::FieldDescriptor* getFieldDescriptor(GPB::Message* message, SEXP name){ + try { GPB::FieldDescriptor* field_desc = (GPB::FieldDescriptor*)0; const GPB::Descriptor* desc = message->GetDescriptor() ; std::string error_message = "could not get FieldDescriptor for field"; @@ -230,7 +234,7 @@ if (Rf_inherits( name, "FieldDescriptor") ){ field_desc = GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(name); } else { - throwException( "S4 class is not a FieldDescriptor", "NoSuchFieldException" ) ; + Rcpp::throw("S4 class is not a FieldDescriptor"); } break ; } @@ -254,9 +258,12 @@ } } if( !field_desc ){ - throwException( error_message.c_str(), "NoSuchFieldException" ) ; + Rcpp::throw(error_message.c_str()); } return field_desc ; + } catch(std::exception &ex) { + forward_exception_to_r(ex); + } } RPB_FUNCTION_VOID_1( check_libprotobuf_version, int minversion ){ Modified: pkg/src/wrapper_EnumDescriptor.cpp =================================================================== --- pkg/src/wrapper_EnumDescriptor.cpp 2013-12-27 09:11:21 UTC (rev 607) +++ pkg/src/wrapper_EnumDescriptor.cpp 2013-12-27 20:04:29 UTC (rev 608) @@ -70,7 +70,7 @@ const GPB::EnumValueDescriptor* evd = d->FindValueByName(name) ; if( !evd ){ /* or maybe it should just be NA */ - throwException( "cannot get the value", "UnknownEnumValueException" ) ; + Rcpp::throw("cannot get the value"); } return evd->number(); } Modified: pkg/src/wrapper_FieldDescriptor.cpp =================================================================== --- pkg/src/wrapper_FieldDescriptor.cpp 2013-12-27 09:11:21 UTC (rev 607) +++ pkg/src/wrapper_FieldDescriptor.cpp 2013-12-27 20:04:29 UTC (rev 608) @@ -83,7 +83,7 @@ RPB_FUNCTION_1(S4_EnumDescriptor, METHOD(enum_type), Rcpp::XPtr d){ if( d->cpp_type() != CPPTYPE_ENUM ){ - throwException( "not an enum type field", "NotEnumType" ); + Rcpp::throw("not an enum type field"); } return S4_EnumDescriptor( d->enum_type() ) ; } Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-12-27 09:11:21 UTC (rev 607) +++ pkg/src/wrapper_Message.cpp 2013-12-27 20:04:29 UTC (rev 608) @@ -8,53 +8,55 @@ /* helpers */ - /* this is only to be called for repeated fields */ - int MESSAGE_GET_REPEATED_INT( GPB::Message* message, GPB::FieldDescriptor* field_desc, int index ){ +/* this is only to be called for repeated fields */ +int MESSAGE_GET_REPEATED_INT(GPB::Message* message, + GPB::FieldDescriptor* field_desc, int index ){ + BEGIN_RCPP + const GPB::Reflection* ref = message->GetReflection() ; - const GPB::Reflection* ref = message->GetReflection() ; - - switch( field_desc->type() ){ - case TYPE_INT32: - case TYPE_SINT32: - case TYPE_SFIXED32: - return (int) ref->GetRepeatedInt32( *message, field_desc, index ) ; - case TYPE_INT64: - case TYPE_SINT64: - case TYPE_SFIXED64: - return (int) ref->GetRepeatedInt64( *message, field_desc, index ) ; - case TYPE_UINT32: - case TYPE_FIXED32: - return (int) ref->GetRepeatedUInt32( *message, field_desc, index ) ; - case TYPE_UINT64: - case TYPE_FIXED64: - return (int) ref->GetRepeatedUInt64( *message, field_desc, index ) ; - case TYPE_ENUM: - return ref->GetRepeatedEnum( *message, field_desc, index )->number() ; - default: - throwException( "cannot cast to int", "CastException" ) ; - } - return 0 ; // -Wall + switch( field_desc->type() ){ + case TYPE_INT32: + case TYPE_SINT32: + case TYPE_SFIXED32: + return (int) ref->GetRepeatedInt32( *message, field_desc, index ) ; + case TYPE_INT64: + case TYPE_SINT64: + case TYPE_SFIXED64: + return (int) ref->GetRepeatedInt64( *message, field_desc, index ) ; + case TYPE_UINT32: + case TYPE_FIXED32: + return (int) ref->GetRepeatedUInt32( *message, field_desc, index ) ; + case TYPE_UINT64: + case TYPE_FIXED64: + return (int) ref->GetRepeatedUInt64( *message, field_desc, index ) ; + case TYPE_ENUM: + return ref->GetRepeatedEnum( *message, field_desc, index )->number() ; + default: + Rcpp_error("cannot cast to int"); } + VOID_END_RCPP + return 0 ; // -Wall +} - /* this is only to be called for repeated fields */ - double MESSAGE_GET_REPEATED_DOUBLE( GPB::Message* message, GPB::FieldDescriptor* field_desc, int index ){ +/* this is only to be called for repeated fields */ +double MESSAGE_GET_REPEATED_DOUBLE(GPB::Message* message, + GPB::FieldDescriptor* field_desc, + int index ){ + BEGIN_RCPP + const GPB::Reflection* ref = message->GetReflection() ; - const GPB::Reflection* ref = message->GetReflection() ; - - switch( field_desc->type() ){ - case TYPE_FLOAT: - return (double) ref->GetRepeatedFloat( *message, field_desc, index ) ; - case TYPE_DOUBLE: - return (double) ref->GetRepeatedDouble( *message, field_desc, index ) ; - default: - throwException( "cannot cast to double", "CastException" ) ; - } - return 0 ; // -Wall + switch( field_desc->type() ){ + case TYPE_FLOAT: + return (double) ref->GetRepeatedFloat( *message, field_desc, index ) ; + case TYPE_DOUBLE: + return (double) ref->GetRepeatedDouble( *message, field_desc, index ) ; + default: + Rcpp_error("cannot cast to double"); } - + VOID_END_RCPP + return 0; // -Wall +} - - #undef METHOD #define METHOD(__NAME__) RCPP_PP_CAT(Message__,__NAME__) @@ -457,6 +459,7 @@ } bool identical_messages_( GPB::Message* m1, GPB::Message* m2, double tol ){ + BEGIN_RCPP const GPB::Descriptor* d1 = m1->GetDescriptor() ; const GPB::Descriptor* d2 = m2->GetDescriptor() ; @@ -563,7 +566,7 @@ break ; } default: - throwException( "unknown type" , "UnknownTypeException" ) ; + Rcpp_error("unknown type"); } } else { @@ -632,15 +635,14 @@ break ; } default: - throwException( "unknown type" , "UnknownTypeException" ) ; + Rcpp_error("unknown type"); } } } - - /* finally */ - return true ; - + VOID_END_RCPP + /* finally */ + return true ; } RPB_FUNCTION_2( bool, identical_messages, Rcpp::XPtr m1, Rcpp::XPtr m2){ @@ -686,384 +688,379 @@ * @param field field tag number or name * @param values values to append */ -RPB_FUNCTION_VOID_3( METHOD(add_values), Rcpp::XPtr message, SEXP field, SEXP values){ - const Reflection * ref = message->GetReflection() ; - const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ); +RPB_FUNCTION_VOID_3( METHOD(add_values), Rcpp::XPtr message, + SEXP field, SEXP values){ + const Reflection * ref = message->GetReflection() ; + const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ); - if( values == R_NilValue || LENGTH(values) == 0 ){ - return ; - } + if( values == R_NilValue || LENGTH(values) == 0 ){ + return ; + } - if( field_desc->is_repeated() ){ - /* first check */ - switch( field_desc->type() ){ - case TYPE_ENUM: + if( field_desc->is_repeated() ){ + /* first check */ + switch( field_desc->type() ){ + case TYPE_ENUM: + { + CHECK_values_for_enum( field_desc, values) ; + break ; + } + case TYPE_MESSAGE: + case TYPE_GROUP: + { + CHECK_messages( field_desc, values ) ; + break ; + } + default: + {// nothing + } + } + + int value_size = LENGTH( values ) ; + /* then add the values */ + switch( field_desc->type() ){ + // {{{ int32 + case TYPE_INT32: + case TYPE_SINT32: + case TYPE_SFIXED32: + { + switch( TYPEOF( values ) ){ + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: { - CHECK_values_for_enum( field_desc, values) ; - break ; + for( int i=0; iAddInt32( message, field_desc, GET_int32(values,i) ) ; } - case TYPE_MESSAGE: - case TYPE_GROUP: + break ; + } + default: { - CHECK_messages( field_desc, values ) ; - break ; [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rprotobuf -r 608 From noreply at r-forge.r-project.org Fri Dec 27 22:10:36 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 22:10:36 +0100 (CET) Subject: [Rprotobuf-commits] r609 - pkg/src Message-ID: <20131227211036.71924185992@r-forge.r-project.org> Author: murray Date: 2013-12-27 22:10:36 +0100 (Fri, 27 Dec 2013) New Revision: 609 Modified: pkg/src/extractors.cpp pkg/src/mutators.cpp pkg/src/rprotobuf.cpp pkg/src/rprotobuf.h pkg/src/wrapper_EnumDescriptor.cpp pkg/src/wrapper_FieldDescriptor.cpp pkg/src/wrapper_Message.cpp pkg/src/wrapper_ServiceDescriptor.cpp Log: Oops, s/Rcpp::throw/Rcpp::stop/. Modified: pkg/src/extractors.cpp =================================================================== --- pkg/src/extractors.cpp 2013-12-27 20:04:29 UTC (rev 608) +++ pkg/src/extractors.cpp 2013-12-27 21:10:36 UTC (rev 609) @@ -42,7 +42,7 @@ // This should not happen, its a bug in the code. string message = string("Error converting int64 to string, unset ") + kIntStringOptionName + " option."; - Rcpp::throw(message.c_str()); + Rcpp::stop(message.c_str()); } return Rcpp::CharacterVector(ss.str()); } else { @@ -139,11 +139,11 @@ } return res; } else { - Rcpp::throw("unknown field type with CPP_TYPE STRING"); + Rcpp::stop("unknown field type with CPP_TYPE STRING"); } default: - Rcpp::throw("Unsupported type"); + Rcpp::stop("Unsupported type"); } } else { @@ -176,7 +176,7 @@ std::string s = ref->GetString(*message, fieldDesc); return Rcpp::wrap(std::vector(s.begin(), s.end())); } else { - Rcpp::throw("unknown field type with CPP_TYPE STRING"); + Rcpp::stop("unknown field type with CPP_TYPE STRING"); } case CPPTYPE_ENUM : return Rcpp::wrap( ref->GetEnum( *message, fieldDesc )->number() ) ; @@ -186,7 +186,7 @@ break ; default: - Rcpp::throw("Unsupported type"); + Rcpp::stop("Unsupported type"); } } Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-27 20:04:29 UTC (rev 608) +++ pkg/src/mutators.cpp 2013-12-27 21:10:36 UTC (rev 609) @@ -35,7 +35,6 @@ */ /* FIXME: should we convert the NA's */ double GET_double( SEXP x, int index ){ - try { switch( TYPEOF(x) ){ case INTSXP: return( (double)INTEGER(x)[index] ) ; @@ -46,17 +45,13 @@ case RAWSXP: return( (double)RAW(x)[index] ) ; default: - Rcpp::throw("cannot cast SEXP to double"); + Rcpp::stop("cannot cast SEXP to double"); } - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } return 0.0 ; // -Wall } // }}} float GET_float( SEXP x, int index ){ - try { switch( TYPEOF(x) ){ case INTSXP: return( (float)INTEGER(x)[index] ) ; @@ -67,16 +62,12 @@ case RAWSXP: return( (float)RAW(x)[index] ) ; default: - Rcpp::throw("cannot cast SEXP to double"); + Rcpp::stop("cannot cast SEXP to double"); } - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } return (float)0.0 ; // -Wall } int GET_int( SEXP x, int index ){ - try { switch( TYPEOF(x) ){ case INTSXP: return( INTEGER(x)[index] ); @@ -87,48 +78,36 @@ case RAWSXP: return( (int)RAW(x)[index] ) ; default: - Rcpp::throw( "cannot cast SEXP to int" ); + Rcpp::stop( "cannot cast SEXP to int" ); } - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } return 0 ; // -Wall, should not happen since we only call this when we know it works } template ValueType Int64FromString(const string &value) { - try { std::stringstream ss(value); ValueType ret; if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { string message = "Provided character value '" + value + "' cannot be cast to 64-bit integer."; - Rcpp::throw(message.c_str()); + Rcpp::stop(message.c_str()); } return ret; - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } } template ValueType Int32FromString(const string &value) { - try { std::stringstream ss(value); ValueType ret; if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { string message = "Provided character value '" + value + "' cannot be cast to 32-bit integer."; - Rcpp::throw(message.c_str()); + Rcpp::stop(message.c_str()); } return ret; - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } } int32 GET_int32( SEXP x, int index ){ - try { switch( TYPEOF(x) ){ case INTSXP: return( (int32)INTEGER(x)[index] ); @@ -141,16 +120,12 @@ case STRSXP: return Int32FromString(CHAR(STRING_ELT(x, index))); default: - Rcpp::throw( "cannot cast SEXP to int32"); + Rcpp::stop( "cannot cast SEXP to int32"); } - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } return (int32)0 ; // -Wall, should not happen since we only call this when we know it works } int64 GET_int64( SEXP x, int index ){ - try { switch( TYPEOF(x) ){ case INTSXP: return( (int64)INTEGER(x)[index] ); @@ -163,16 +138,12 @@ case STRSXP: return Int64FromString(CHAR(STRING_ELT(x, index))); default: - Rcpp::throw("cannot cast SEXP to int64"); + Rcpp::stop("cannot cast SEXP to int64"); } - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } return (int64)0 ; // -Wall, should not happen since we only call this when we know it works } uint32 GET_uint32( SEXP x, int index ){ - try { switch( TYPEOF(x) ){ case INTSXP: return( (uint32)INTEGER(x)[index] ); @@ -185,16 +156,12 @@ case STRSXP: return Int32FromString(CHAR(STRING_ELT(x, index))); default: - Rcpp::throw("cannot cast SEXP to uint32"); + Rcpp::stop("cannot cast SEXP to uint32"); } - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } return (uint32)0 ; // -Wall, should not happen since we only call this when we know it works } uint64 GET_uint64( SEXP x, int index ){ - try { switch( TYPEOF(x) ){ case INTSXP: return( (uint64)INTEGER(x)[index] ); @@ -207,43 +174,36 @@ case STRSXP: return Int64FromString(CHAR(STRING_ELT(x, index))); default: - Rcpp::throw("cannot cast SEXP to uint64"); + Rcpp::stop("cannot cast SEXP to uint64"); } - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } return (uint64)0 ; // -Wall, should not happen since we only call this when we know it works } bool GET_bool( SEXP x, int index ){ - try { switch( TYPEOF(x) ){ case INTSXP: if (INTEGER(x)[index] == R_NaInt) { - Rcpp::throw("NA boolean values can not be stored in " + Rcpp::stop("NA boolean values can not be stored in " "bool protocol buffer fields"); } return( (bool)INTEGER(x)[index] ); case REALSXP: if (REAL(x)[index] == R_NaReal) { - Rcpp::throw("NA boolean values can not be stored in " + Rcpp::stop("NA boolean values can not be stored in " "bool protocol buffer fields"); } return( (bool)REAL(x)[index] ); case LGLSXP: if (LOGICAL(x)[index] == NA_LOGICAL) { - Rcpp::throw("NA boolean values can not be stored in " + Rcpp::stop("NA boolean values can not be stored in " "bool protocol buffer fields"); } return( (bool)LOGICAL(x)[index] ); case RAWSXP: return( (bool)RAW(x)[index] ) ; default: - Rcpp::throw("cannot cast SEXP to bool"); + Rcpp::stop("cannot cast SEXP to bool"); } - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } return (bool)0 ; // -Wall, should not happen since we only call this when we know it works } @@ -255,26 +215,22 @@ } std::string GET_bytes( SEXP x, int index ){ - try { switch( TYPEOF(x)) { case RAWSXP: if (index == 0) { return(std::string((const char *) RAW(x), (size_t) LENGTH(x))); } else { - Rcpp::throw("cannot cast SEXP to bytes"); + Rcpp::stop("cannot cast SEXP to bytes"); } case VECSXP: if (TYPEOF(VECTOR_ELT(x, index)) == RAWSXP) { return(std::string((const char *) RAW(VECTOR_ELT(x, index)), (size_t) LENGTH(VECTOR_ELT(x, index)))); } else { - Rcpp::throw("cannot cast SEXP to bytes"); + Rcpp::stop("cannot cast SEXP to bytes"); } default: - Rcpp::throw("cannot cast SEXP to bytes"); + Rcpp::stop("cannot cast SEXP to bytes"); } - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } return "" ; // -Wall, should not happen since we only call this when we know it works } @@ -359,7 +315,7 @@ } } if( !ok ){ - Rcpp::throw("wrong value for enum"); + Rcpp::stop("wrong value for enum"); } } @@ -388,7 +344,7 @@ } } if( !ok ){ - Rcpp::throw("wrong value for enum"); + Rcpp::stop("wrong value for enum"); } } break ; @@ -396,7 +352,7 @@ // }}} default: - Rcpp::throw("impossible to convert to a enum"); + Rcpp::stop("impossible to convert to a enum"); } VOID_END_RCPP } @@ -407,7 +363,7 @@ void CHECK_messages( const GPB::FieldDescriptor* field_desc, SEXP values ){ BEGIN_RCPP if( TYPEOF( values ) != VECSXP ){ - Rcpp::throw("expecting a list of messages"); + Rcpp::stop("expecting a list of messages"); } const char* target = field_desc->message_type()->full_name().c_str() ; @@ -415,7 +371,7 @@ for( int i=0; itype() ){ case TYPE_MESSAGE: case TYPE_GROUP: @@ -447,13 +402,13 @@ /* check that this is a message of the appropriate type */ if( !isMessage( value, field_desc->message_type()->full_name().c_str() ) ){ - Rcpp::throw("incorrect type"); + Rcpp::stop("incorrect type"); } break ; } default: { - Rcpp::("impossible to convert to a message"); + Rcpp::stop("impossible to convert to a message"); } } break ; @@ -492,7 +447,7 @@ } } if( !ok ){ - Rcpp::throw("wrong value for enum"); + Rcpp::stop("wrong value for enum"); } } break ; @@ -520,7 +475,7 @@ } } if( !ok ){ - Rcpp::throw("wrong value for enum"); + Rcpp::stop("wrong value for enum"); } } @@ -529,7 +484,7 @@ // }}} default: - Rcpp::throw("impossible to convert to a enum"); + Rcpp::stop("impossible to convert to a enum"); } break ; } @@ -553,7 +508,6 @@ } } // }}} - VOID_END_RCPP } /** @@ -572,7 +526,7 @@ const GPB::FieldDescriptor* field_desc, SEXP value, int value_size) { if (value_size > 1) { - Rcpp::throw("cannot set non-repeated field to vector of length > 1"); + Rcpp::stop("cannot set non-repeated field to vector of length > 1"); } switch( GPB::FieldDescriptor::TypeToCppType( field_desc->type() ) ){ // {{{ simple cases using macro expansion @@ -591,15 +545,15 @@ // TODO(mstokely): Rcpp should handle this! if ((TYPEOF(value) == LGLSXP) && (LOGICAL(value)[0] == NA_LOGICAL)) { - Rcpp::throw("NA boolean values can not be stored in " + Rcpp::stop("NA boolean values can not be stored in " "bool protocol buffer fields"); } else if ((TYPEOF(value) == INTSXP) && (INTEGER(value)[0] == R_NaInt)) { - Rcpp::throw("NA boolean values can not be stored in " + Rcpp::stop("NA boolean values can not be stored in " "bool protocol buffer fields"); } else if ((TYPEOF(value) == REALSXP) && (REAL(value)[0] == R_NaReal)) { - Rcpp::throw("NA boolean values can not be stored in " + Rcpp::stop("NA boolean values can not be stored in " "bool protocol buffer fields"); } ref->SetBool(message, field_desc, Rcpp::as(value)); @@ -667,7 +621,7 @@ #endif #undef HANDLE_SINGLE_FIELD default: - Rcpp::throw("Unsupported type"); + Rcpp::stop("Unsupported type"); // }}} // {{{ string @@ -689,7 +643,7 @@ { /* check if value is a message */ if( !Rf_inherits( value, "Message" ) ){ - Rcpp::throw("Can only convert S4 objects of class 'Message'"); + Rcpp::stop("Can only convert S4 objects of class 'Message'"); } GPB::Message* __mess = GET_MESSAGE_POINTER_FROM_S4(value); ref->SetString(message, field_desc, @@ -698,7 +652,7 @@ } default: { - Rcpp::throw("Cannot convert to string"); + Rcpp::stop("Cannot convert to string"); } } break ; @@ -713,12 +667,12 @@ const char* type = mess->GetDescriptor()->full_name().c_str() ; const char* target = field_desc->message_type()->full_name().c_str() ; if( strcmp( type, target ) ){ - Rcpp::throw("wrong message type"); + Rcpp::stop("wrong message type"); } GPB::Message* m = ref->MutableMessage( message, field_desc ) ; m->CopyFrom( *mess ) ; } else { - Rcpp::throw("type mismatch, expecting a 'Message' object"); + Rcpp::stop("type mismatch, expecting a 'Message' object"); } break ; } @@ -737,7 +691,7 @@ int val = Rcpp::as(value) ; const GPB::EnumValueDescriptor* evd = enum_desc->FindValueByNumber(val) ; if( !evd ){ - Rcpp::throw("wrong value for enum"); + Rcpp::stop("wrong value for enum"); } else { ref->SetEnum( message, field_desc, evd ); } @@ -748,7 +702,7 @@ std::string val = Rcpp::as( value ) ; const GPB::EnumValueDescriptor* evd = enum_desc->FindValueByName(val) ; if( !evd ){ - Rcpp::throw("wrong value for enum"); + Rcpp::stop("wrong value for enum"); } else { ref->SetEnum( message, field_desc, evd ); } @@ -756,7 +710,7 @@ } default: { - Rcpp::throw("cannot set enum value"); + Rcpp::stop("cannot set enum value"); } } } @@ -831,7 +785,7 @@ default: { - Rcpp::throw("Cannot convert to int32"); + Rcpp::stop("Cannot convert to int32"); } } break ; @@ -869,7 +823,7 @@ } default: - Rcpp::throw("Cannot convert to int64"); + Rcpp::stop("Cannot convert to int64"); } break ; } @@ -903,7 +857,7 @@ break ; } default: - Rcpp::throw("Cannot convert to uint32"); + Rcpp::stop("Cannot convert to uint32"); } break ; } @@ -937,7 +891,7 @@ break ; } default: - Rcpp::throw("Cannot convert to int64"); + Rcpp::stop("Cannot convert to int64"); } break ; } @@ -968,7 +922,7 @@ break ; } default: - Rcpp::throw("Cannot convert to double"); + Rcpp::stop("Cannot convert to double"); } break ; } @@ -1000,7 +954,7 @@ break ; } default: - Rcpp::throw("Cannot convert to float"); + Rcpp::stop("Cannot convert to float"); } break ; } @@ -1032,7 +986,7 @@ break ; } default: - Rcpp::throw("Cannot convert to bool"); + Rcpp::stop("Cannot convert to bool"); } break ; } @@ -1083,7 +1037,7 @@ { /* check if value is a message */ if( !Rf_inherits( value, "Message" ) ){ - Rcpp::throw("Can only convert S4 objects of class 'Message'"); + Rcpp::stop("Can only convert S4 objects of class 'Message'"); } GPB::Message* __mess = GET_MESSAGE_POINTER_FROM_S4( value ) ; ref->SetRepeatedString(message, field_desc, 0, @@ -1134,7 +1088,7 @@ break ; } default: - Rcpp::throw("Cannot convert to string"); + Rcpp::stop("Cannot convert to string"); } break ; } @@ -1179,7 +1133,7 @@ } } } else{ - Rcpp::throw("type mismatch, expecting a 'Message' object or a list of them"); + Rcpp::stop("type mismatch, expecting a 'Message' object or a list of them"); } break ; } @@ -1243,7 +1197,7 @@ // {{{ default default: { - Rcpp::throw("cannot set enum value"); + Rcpp::stop("cannot set enum value"); } // }}} } @@ -1305,7 +1259,7 @@ } else if( TYPEOF(value) == VECSXP && allAreRaws( value ) ){ value_size = LENGTH(value) ; } else { - Rcpp::throw("cannot convert to string"); + Rcpp::stop("cannot convert to string"); } } // }}} Modified: pkg/src/rprotobuf.cpp =================================================================== --- pkg/src/rprotobuf.cpp 2013-12-27 20:04:29 UTC (rev 608) +++ pkg/src/rprotobuf.cpp 2013-12-27 21:10:36 UTC (rev 609) @@ -123,7 +123,7 @@ * @param descriptor a "Descriptor" R object */ SEXP newProtoMessage( SEXP descriptor ){ - try { + BEGIN_RCPP #ifdef RPB_DEBUG Rprintf( "\n" ) ; /* FIXME: the message type, we don't really need that*/ @@ -148,9 +148,7 @@ #endif return( S4_Message( message ) ) ; - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } + END_RCPP } /** @@ -234,7 +232,7 @@ if (Rf_inherits( name, "FieldDescriptor") ){ field_desc = GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(name); } else { - Rcpp::throw("S4 class is not a FieldDescriptor"); + Rcpp::stop("S4 class is not a FieldDescriptor"); } break ; } @@ -258,7 +256,7 @@ } } if( !field_desc ){ - Rcpp::throw(error_message.c_str()); + Rcpp::stop(error_message.c_str()); } return field_desc ; } catch(std::exception &ex) { Modified: pkg/src/rprotobuf.h =================================================================== --- pkg/src/rprotobuf.h 2013-12-27 20:04:29 UTC (rev 608) +++ pkg/src/rprotobuf.h 2013-12-27 21:10:36 UTC (rev 609) @@ -106,7 +106,7 @@ #define XPP EXTPTR_PTR #define NEW_S4_OBJECT(CLAZZ) SEXP oo = PROTECT( NEW_OBJECT(MAKE_CLASS(CLAZZ)) ); \ - if (!Rf_inherits(oo, CLAZZ)) throwException(CLAZZ, "CannotCreateObjectException" ); + if (!Rf_inherits(oo, CLAZZ)) Rcpp::stop(CLAZZ); namespace rprotobuf{ @@ -130,9 +130,6 @@ RcppExport SEXP getMessageField( SEXP, SEXP ); RcppExport SEXP extractFieldAsSEXP( const Rcpp::XPtr& , const GPB::FieldDescriptor* ) ; -/* in exceptions.cpp */ -RcppExport SEXP throwException( const char*, const char*) ; - /* in lookup.cpp */ RcppExport SEXP newProtocolBufferLookup(SEXP) ; Modified: pkg/src/wrapper_EnumDescriptor.cpp =================================================================== --- pkg/src/wrapper_EnumDescriptor.cpp 2013-12-27 20:04:29 UTC (rev 608) +++ pkg/src/wrapper_EnumDescriptor.cpp 2013-12-27 21:10:36 UTC (rev 609) @@ -70,7 +70,7 @@ const GPB::EnumValueDescriptor* evd = d->FindValueByName(name) ; if( !evd ){ /* or maybe it should just be NA */ - Rcpp::throw("cannot get the value"); + Rcpp::stop("cannot get the value"); } return evd->number(); } Modified: pkg/src/wrapper_FieldDescriptor.cpp =================================================================== --- pkg/src/wrapper_FieldDescriptor.cpp 2013-12-27 20:04:29 UTC (rev 608) +++ pkg/src/wrapper_FieldDescriptor.cpp 2013-12-27 21:10:36 UTC (rev 609) @@ -83,7 +83,7 @@ RPB_FUNCTION_1(S4_EnumDescriptor, METHOD(enum_type), Rcpp::XPtr d){ if( d->cpp_type() != CPPTYPE_ENUM ){ - Rcpp::throw("not an enum type field"); + Rcpp::stop("not an enum type field"); } return S4_EnumDescriptor( d->enum_type() ) ; } Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-12-27 20:04:29 UTC (rev 608) +++ pkg/src/wrapper_Message.cpp 2013-12-27 21:10:36 UTC (rev 609) @@ -737,7 +737,7 @@ } default: { - Rcpp::throw("Cannot convert to int32"); + Rcpp::stop("Cannot convert to int32"); } } break ; @@ -758,7 +758,7 @@ ref->AddInt64( message, field_desc, GET_int64(values,i) ) ; } default: - Rcpp::throw("Cannot convert to int64"); + Rcpp::stop("Cannot convert to int64"); } break ; } @@ -780,7 +780,7 @@ break ; } default: - Rcpp::throw("Cannot convert to uint32"); + Rcpp::stop("Cannot convert to uint32"); } break ; } @@ -802,7 +802,7 @@ break ; } default: - Rcpp::throw("Cannot convert to int64"); + Rcpp::stop("Cannot convert to int64"); } break ; } @@ -823,7 +823,7 @@ break ; } default: - Rcpp::throw("Cannot convert to double"); + Rcpp::stop("Cannot convert to double"); } break ; } @@ -844,7 +844,7 @@ break ; } default: - Rcpp::throw("Cannot convert to float"); + Rcpp::stop("Cannot convert to float"); } break ; } @@ -865,7 +865,7 @@ break ; } default: - Rcpp::throw("Cannot convert to bool"); + Rcpp::stop("Cannot convert to bool"); } break ; } @@ -879,7 +879,7 @@ ref->AddString( message, field_desc, COPYSTRING( CHAR(STRING_ELT(values,i )) ) ) ; } } else{ - Rcpp::throw("Cannot convert to string"); + Rcpp::stop("Cannot convert to string"); } break ; } @@ -895,7 +895,7 @@ ref->AddString( message, field_desc, GET_bytes(values,i )) ; } } else{ - Rcpp::throw("Cannot convert to bytes"); + Rcpp::stop("Cannot convert to bytes"); } break ; } @@ -914,7 +914,7 @@ ref->AddMessage(message, field_desc)->CopyFrom( *mess ) ; } } else{ - Rcpp::throw("type mismatch, expecting a list of 'Message' objects"); + Rcpp::stop("type mismatch, expecting a list of 'Message' objects"); } break ; } @@ -954,7 +954,7 @@ // {{{ default default: { - Rcpp::throw("cannot set enum value"); + Rcpp::stop("cannot set enum value"); } // }}} } @@ -967,7 +967,7 @@ } } } else{ - Rcpp::throw("add can only be used on repeated fields"); + Rcpp::stop("add can only be used on repeated fields"); } } Modified: pkg/src/wrapper_ServiceDescriptor.cpp =================================================================== --- pkg/src/wrapper_ServiceDescriptor.cpp 2013-12-27 20:04:29 UTC (rev 608) +++ pkg/src/wrapper_ServiceDescriptor.cpp 2013-12-27 21:10:36 UTC (rev 609) @@ -99,7 +99,7 @@ } if( !method_desc ){ - Rcpp::throw("could not get MethodDescriptor"); + Rcpp::stop("could not get MethodDescriptor"); } return S4_MethodDescriptor( method_desc ); From noreply at r-forge.r-project.org Fri Dec 27 22:33:43 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 22:33:43 +0100 (CET) Subject: [Rprotobuf-commits] r610 - in pkg: . src Message-ID: <20131227213343.18903186947@r-forge.r-project.org> Author: murray Date: 2013-12-27 22:33:42 +0100 (Fri, 27 Dec 2013) New Revision: 610 Modified: pkg/ChangeLog pkg/src/mutators.cpp Log: Address a TODO by adding a much more helpful stop error that tells the user which element of a list didn't have the correct message type and what the expected message type was. Remove BEGIN_RCPP/END_RCPP from this function and let the exception percolate up to the callers which have use those macros. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-27 21:10:36 UTC (rev 609) +++ pkg/ChangeLog 2013-12-27 21:33:42 UTC (rev 610) @@ -5,6 +5,9 @@ try/catch block so we catch any exceptions generated by Rcpp::as or other functions and forward it along to an R-language stop() error instead of terminating our R instance. + * src/mutators.cpp (rprotobuf): Add more helpful error message + specifying which element of a list is of the wrong type, and what + the expected type is, when setting a list of messages. * inst/unitTests/runit.messages.R (test.message): Add unit tests for our handling of setting repeated message fields. * src/wrapper_Message.cpp: Add const qualifier to Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-27 21:10:36 UTC (rev 609) +++ pkg/src/mutators.cpp 2013-12-27 21:33:42 UTC (rev 610) @@ -359,9 +359,10 @@ /** * check that the values are suitable for the field descriptor + * + * @throws Rcpp::exception on error (uncaught) */ void CHECK_messages( const GPB::FieldDescriptor* field_desc, SEXP values ){ - BEGIN_RCPP if( TYPEOF( values ) != VECSXP ){ Rcpp::stop("expecting a list of messages"); } @@ -370,11 +371,19 @@ int n = LENGTH(values) ; for( int i=0; i Author: murray Date: 2013-12-27 22:36:08 +0100 (Fri, 27 Dec 2013) New Revision: 611 Modified: pkg/src/rprotobuf.cpp Log: Correct a typo and use the RCPP macros rather than rolling our own try/catch. Modified: pkg/src/rprotobuf.cpp =================================================================== --- pkg/src/rprotobuf.cpp 2013-12-27 21:33:42 UTC (rev 610) +++ pkg/src/rprotobuf.cpp 2013-12-27 21:36:08 UTC (rev 611) @@ -199,7 +199,7 @@ /** * * @param m potentially a message - * @param target the exxpected type + * @param target the expected type * * @return TRUE if m is a a message of the given type */ @@ -222,8 +222,8 @@ GPB::FieldDescriptor* getFieldDescriptor(GPB::Message* message, SEXP name){ - try { GPB::FieldDescriptor* field_desc = (GPB::FieldDescriptor*)0; + BEGIN_RCPP const GPB::Descriptor* desc = message->GetDescriptor() ; std::string error_message = "could not get FieldDescriptor for field"; switch( TYPEOF(name) ){ @@ -259,9 +259,8 @@ Rcpp::stop(error_message.c_str()); } return field_desc ; - } catch(std::exception &ex) { - forward_exception_to_r(ex); - } + VOID_END_RCPP + return field_desc ; } RPB_FUNCTION_VOID_1( check_libprotobuf_version, int minversion ){ From noreply at r-forge.r-project.org Fri Dec 27 23:23:44 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 23:23:44 +0100 (CET) Subject: [Rprotobuf-commits] r612 - pkg/src Message-ID: <20131227222344.A5197186818@r-forge.r-project.org> Author: murray Date: 2013-12-27 23:23:44 +0100 (Fri, 27 Dec 2013) New Revision: 612 Modified: pkg/src/mutators.cpp Log: Add a better stop() message referencing the exact type and correct two typos in comments. Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-27 21:36:08 UTC (rev 611) +++ pkg/src/mutators.cpp 2013-12-27 22:23:44 UTC (rev 612) @@ -411,7 +411,9 @@ /* check that this is a message of the appropriate type */ if( !isMessage( value, field_desc->message_type()->full_name().c_str() ) ){ - Rcpp::stop("incorrect type"); + string message = "Not a message of type '" + + field_desc->message_type()->full_name() + "'"; + Rcpp::stop(message.c_str()); } break ; } @@ -1127,7 +1129,7 @@ for( ; iMutableRepeatedMessage(message, field_desc, i )->CopyFrom( *mess ) ; } @@ -1136,7 +1138,7 @@ for( ; iAddMessage(message, field_desc)->CopyFrom( *mess ) ; } From noreply at r-forge.r-project.org Fri Dec 27 23:24:03 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Fri, 27 Dec 2013 23:24:03 +0100 (CET) Subject: [Rprotobuf-commits] r613 - pkg/src Message-ID: <20131227222403.58B98186818@r-forge.r-project.org> Author: murray Date: 2013-12-27 23:24:03 +0100 (Fri, 27 Dec 2013) New Revision: 613 Modified: pkg/src/lookup.cpp Log: Correct comment typo. Modified: pkg/src/lookup.cpp =================================================================== --- pkg/src/lookup.cpp 2013-12-27 22:23:44 UTC (rev 612) +++ pkg/src/lookup.cpp 2013-12-27 22:24:03 UTC (rev 613) @@ -174,7 +174,7 @@ * Previously this function returned a stop() error, but this has side * effects such as preventing users from using '<<-' operator in any * scripts that include RProtoBuf. So instead, we now simply return - * NULL to indicate assign is not possible on this lookup talbe + * NULL to indicate assign is not possible on this lookup table * without giving such a hard error. */ SEXP rProtoBufTable_assign(const char * const name, SEXP value, R_ObjectTable *tb){ From noreply at r-forge.r-project.org Sat Dec 28 00:31:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 00:31:27 +0100 (CET) Subject: [Rprotobuf-commits] r614 - pkg/src Message-ID: <20131227233127.EDCDF186967@r-forge.r-project.org> Author: murray Date: 2013-12-28 00:31:27 +0100 (Sat, 28 Dec 2013) New Revision: 614 Modified: pkg/src/wrapper_MethodDescriptor.cpp Log: Whitespace change only. Use consistent indentation and spacing around paramters. Enforced by: clang-format -style="{BasedOnStyle: google, IndentWidth: 4}" -i *.cpp Modified: pkg/src/wrapper_MethodDescriptor.cpp =================================================================== --- pkg/src/wrapper_MethodDescriptor.cpp 2013-12-27 22:24:03 UTC (rev 613) +++ pkg/src/wrapper_MethodDescriptor.cpp 2013-12-27 23:31:27 UTC (rev 614) @@ -1,52 +1,63 @@ #include "rprotobuf.h" #include "RcppMacros.h" -namespace rprotobuf{ +namespace rprotobuf { #undef METHOD -#define METHOD(__NAME__) RCPP_PP_CAT(MethodDescriptor__,__NAME__) +#define METHOD(__NAME__) RCPP_PP_CAT(MethodDescriptor__, __NAME__) -RPB_XP_METHOD_0( METHOD(as_character) , GPB::MethodDescriptor , DebugString) +RPB_XP_METHOD_0(METHOD(as_character), GPB::MethodDescriptor, DebugString) -RPB_FUNCTION_1(S4_Message, METHOD(as_Message), Rcpp::XPtr d ){ - GPB::MethodDescriptorProto* message = new GPB::MethodDescriptorProto() ; - d->CopyTo( message ); - return S4_Message( message ) ; +RPB_FUNCTION_1(S4_Message, METHOD(as_Message), + Rcpp::XPtr d) { + GPB::MethodDescriptorProto* message = new GPB::MethodDescriptorProto(); + d->CopyTo(message); + return S4_Message(message); } - -RPB_FUNCTION_1( S4_FileDescriptor, METHOD(fileDescriptor), Rcpp::XPtr desc){ - return S4_FileDescriptor( desc->service()->file() ); + +RPB_FUNCTION_1(S4_FileDescriptor, METHOD(fileDescriptor), + Rcpp::XPtr desc) { + return S4_FileDescriptor(desc->service()->file()); } - -RPB_FUNCTION_1( S4_Descriptor, METHOD(input_type) , Rcpp::XPtr method){ - return method->input_type() ; + +RPB_FUNCTION_1(S4_Descriptor, METHOD(input_type), + Rcpp::XPtr method) { + return method->input_type(); } -RPB_FUNCTION_1( S4_Descriptor, METHOD(output_type), Rcpp::XPtr method){ - return method->output_type() ; +RPB_FUNCTION_1(S4_Descriptor, METHOD(output_type), + Rcpp::XPtr method) { + return method->output_type(); } -RPB_FUNCTION_1( S4_Message, get_method_input_prototype, Rcpp::XPtr method ){ - const GPB::Descriptor* desc = method->input_type(); - return S4_Message( PROTOTYPE( desc ) ) ; +RPB_FUNCTION_1(S4_Message, get_method_input_prototype, + Rcpp::XPtr method) { + const GPB::Descriptor* desc = method->input_type(); + return S4_Message(PROTOTYPE(desc)); } -RPB_FUNCTION_1( S4_Message, get_method_output_prototype, Rcpp::XPtr method ){ - const GPB::Descriptor* desc = method->output_type(); - return S4_Message( PROTOTYPE( desc ) ) ; +RPB_FUNCTION_1(S4_Message, get_method_output_prototype, + Rcpp::XPtr method) { + const GPB::Descriptor* desc = method->output_type(); + return S4_Message(PROTOTYPE(desc)); } -RPB_FUNCTION_2(bool, valid_input_message, Rcpp::XPtr method, Rcpp::XPtr message){ - return message->GetDescriptor() == method->input_type() ; +RPB_FUNCTION_2(bool, valid_input_message, + Rcpp::XPtr method, + Rcpp::XPtr message) { + return message->GetDescriptor() == method->input_type(); } -RPB_FUNCTION_2(bool, valid_output_message, Rcpp::XPtr method, Rcpp::XPtr message){ - return message->GetDescriptor() == method->output_type() ; +RPB_FUNCTION_2(bool, valid_output_message, + Rcpp::XPtr method, + Rcpp::XPtr message) { + return message->GetDescriptor() == method->output_type(); } -RPB_FUNCTION_2( std::string, METHOD(name), Rcpp::XPtr d, bool full){ - return full ? d->full_name() : d->name() ; +RPB_FUNCTION_2(std::string, METHOD(name), Rcpp::XPtr d, + bool full) { + return full ? d->full_name() : d->name(); } #undef METHOD -} // namespace rprotobuf +} // namespace rprotobuf From noreply at r-forge.r-project.org Sat Dec 28 00:36:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 00:36:35 +0100 (CET) Subject: [Rprotobuf-commits] r615 - pkg/src Message-ID: <20131227233635.569F9186AFD@r-forge.r-project.org> Author: murray Date: 2013-12-28 00:36:34 +0100 (Sat, 28 Dec 2013) New Revision: 615 Modified: pkg/src/wrapper_ZeroCopyInputStream.cpp Log: Format through clang-format. This file seemed to use tab indentation from the "namespace {" but many other files don't indent within the namespace. We are standardizing for now on 4-space indents instead of a mismatch of tab stops and space indents. Modified: pkg/src/wrapper_ZeroCopyInputStream.cpp =================================================================== --- pkg/src/wrapper_ZeroCopyInputStream.cpp 2013-12-27 23:31:27 UTC (rev 614) +++ pkg/src/wrapper_ZeroCopyInputStream.cpp 2013-12-27 23:36:34 UTC (rev 615) @@ -1,43 +1,41 @@ #include "rprotobuf.h" -namespace rprotobuf{ +namespace rprotobuf { - - SEXP ZeroCopyInputStream_Next( SEXP xp ){ - GPB::io::ZeroCopyInputStream* stream = GET_ZCIS(xp) ; - int s = 0 ; - const void* in ; - bool res = stream->Next( &in, &s ); - Rcpp::RawVector result ; - if( !res ){ - throw std::range_error( "cannot read from stream" ) ; - } else{ - result.assign( reinterpret_cast(in), reinterpret_cast(in) + s ) ; - } - return result ; - } - - SEXP ZeroCopyInputStream_BackUp(SEXP xp, SEXP size){ - GPB::io::ZeroCopyInputStream* stream = GET_ZCIS(xp); - int s = GET_int(size, 0) ; - if( s <= 0 ){ - Rf_error( "can only BackUp with positive numbers" ) ; - } - stream->BackUp( s ) ; - return R_NilValue ; - } - - - SEXP ZeroCopyInputStream_Skip(SEXP xp, SEXP size){ - GPB::io::ZeroCopyInputStream* stream = GET_ZCIS(xp); - int s = GET_int(size, 0) ; - bool res = stream->Skip(s) ; - return( Rf_ScalarLogical( res ? _TRUE_ : _FALSE_ ) ) ; - } - - SEXP ZeroCopyInputStream_ByteCount(SEXP xp){ - GPB::io::ZeroCopyInputStream* stream = GET_ZCIS(xp); - return( Rf_ScalarReal((double)stream->ByteCount())) ; - } +SEXP ZeroCopyInputStream_Next(SEXP xp) { + GPB::io::ZeroCopyInputStream* stream = GET_ZCIS(xp); + int s = 0; + const void* in; + bool res = stream->Next(&in, &s); + Rcpp::RawVector result; + if (!res) { + throw std::range_error("cannot read from stream"); + } else { + result.assign(reinterpret_cast(in), + reinterpret_cast(in) + s); + } + return result; +} +SEXP ZeroCopyInputStream_BackUp(SEXP xp, SEXP size) { + GPB::io::ZeroCopyInputStream* stream = GET_ZCIS(xp); + int s = GET_int(size, 0); + if (s <= 0) { + Rf_error("can only BackUp with positive numbers"); + } + stream->BackUp(s); + return R_NilValue; } + +SEXP ZeroCopyInputStream_Skip(SEXP xp, SEXP size) { + GPB::io::ZeroCopyInputStream* stream = GET_ZCIS(xp); + int s = GET_int(size, 0); + bool res = stream->Skip(s); + return (Rf_ScalarLogical(res ? _TRUE_ : _FALSE_)); +} + +SEXP ZeroCopyInputStream_ByteCount(SEXP xp) { + GPB::io::ZeroCopyInputStream* stream = GET_ZCIS(xp); + return (Rf_ScalarReal((double)stream->ByteCount())); +} +} From noreply at r-forge.r-project.org Sat Dec 28 00:37:33 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 00:37:33 +0100 (CET) Subject: [Rprotobuf-commits] r616 - pkg/src Message-ID: <20131227233733.135B5186B00@r-forge.r-project.org> Author: murray Date: 2013-12-28 00:37:32 +0100 (Sat, 28 Dec 2013) New Revision: 616 Modified: pkg/src/wrapper_ServiceDescriptor.cpp Log: clang-format 4-space indents. Modified: pkg/src/wrapper_ServiceDescriptor.cpp =================================================================== --- pkg/src/wrapper_ServiceDescriptor.cpp 2013-12-27 23:36:34 UTC (rev 615) +++ pkg/src/wrapper_ServiceDescriptor.cpp 2013-12-27 23:37:32 UTC (rev 616) @@ -1,110 +1,114 @@ #include "rprotobuf.h" #include "RcppMacros.h" -namespace rprotobuf{ +namespace rprotobuf { #undef METHOD -#define METHOD(__NAME__) RCPP_PP_CAT(ServiceDescriptor__,__NAME__) - - RPB_XP_METHOD_0( METHOD(length),GPB::ServiceDescriptor, method_count ) - RPB_XP_METHOD_0( METHOD(method_count),GPB::ServiceDescriptor, method_count ) - RPB_XP_METHOD_0( METHOD(as_character) , GPB::ServiceDescriptor , DebugString) - - RPB_XP_METHOD_CAST_1( METHOD(getMethodByIndex) , GPB::ServiceDescriptor , method , S4_MethodDescriptor ) - RPB_XP_METHOD_CAST_1( METHOD(getMethodByName) , GPB::ServiceDescriptor , FindMethodByName, S4_MethodDescriptor ) +#define METHOD(__NAME__) RCPP_PP_CAT(ServiceDescriptor__, __NAME__) - RPB_FUNCTION_1( Rcpp::CharacterVector, METHOD(getMethodNames), Rcpp::XPtr desc){ - int nmeths = desc->method_count() ; - Rcpp::CharacterVector res( nmeths ); - - for( int i=0; imethod(i)->name() ; - } - return res ; - } - - /** - * @param xp (GPB::ServiceDescriptor*) external pointer - * @return the descriptor as an R list - */ - RPB_FUNCTION_1( Rcpp::List, METHOD(as_list), Rcpp::XPtr desc ){ - int n = desc->method_count() ; - - Rcpp::CharacterVector names(n) ; - Rcpp::List res(n); - for( int i=0; imethod(i) ; - res[i] = S4_MethodDescriptor( met ); - names[i] = met->name() ; - } - res.names() = names ; - return res; - } +RPB_XP_METHOD_0(METHOD(length), GPB::ServiceDescriptor, method_count) +RPB_XP_METHOD_0(METHOD(method_count), GPB::ServiceDescriptor, method_count) +RPB_XP_METHOD_0(METHOD(as_character), GPB::ServiceDescriptor, DebugString) - RPB_FUNCTION_1(S4_Message, METHOD(as_Message), Rcpp::XPtr d ){ - GPB::ServiceDescriptorProto* message = new GPB::ServiceDescriptorProto() ; - d->CopyTo( message ); - return S4_Message( message ) ; - } - - RPB_FUNCTION_1( S4_FileDescriptor, METHOD(fileDescriptor), Rcpp::XPtr desc){ - return S4_FileDescriptor( desc->file() ); - } - - RPB_FUNCTION_2( std::string, METHOD(name), Rcpp::XPtr d, bool full){ - return full ? d->full_name() : d->name() ; - } - +RPB_XP_METHOD_CAST_1(METHOD(getMethodByIndex), GPB::ServiceDescriptor, method, + S4_MethodDescriptor) +RPB_XP_METHOD_CAST_1(METHOD(getMethodByName), GPB::ServiceDescriptor, + FindMethodByName, S4_MethodDescriptor) +RPB_FUNCTION_1(Rcpp::CharacterVector, METHOD(getMethodNames), + Rcpp::XPtr desc) { + int nmeths = desc->method_count(); + Rcpp::CharacterVector res(nmeths); + + for (int i = 0; i < nmeths; i++) { + res[i] = desc->method(i)->name(); + } + return res; +} + /** + * @param xp (GPB::ServiceDescriptor*) external pointer + * @return the descriptor as an R list + */ +RPB_FUNCTION_1(Rcpp::List, METHOD(as_list), + Rcpp::XPtr desc) { + int n = desc->method_count(); + + Rcpp::CharacterVector names(n); + Rcpp::List res(n); + for (int i = 0; i < n; i++) { + const GPB::MethodDescriptor* met = desc->method(i); + res[i] = S4_MethodDescriptor(met); + names[i] = met->name(); + } + res.names() = names; + return res; +} + +RPB_FUNCTION_1(S4_Message, METHOD(as_Message), + Rcpp::XPtr d) { + GPB::ServiceDescriptorProto* message = new GPB::ServiceDescriptorProto(); + d->CopyTo(message); + return S4_Message(message); +} + +RPB_FUNCTION_1(S4_FileDescriptor, METHOD(fileDescriptor), + Rcpp::XPtr desc) { + return S4_FileDescriptor(desc->file()); +} + +RPB_FUNCTION_2(std::string, METHOD(name), Rcpp::XPtr d, + bool full) { + return full ? d->full_name() : d->name(); +} + +/** * extract a method descriptor from a service descriptor using its * name or position * * @param pointer (GPB::ServiceDescriptor*) external pointer * @param name name or position of the method */ -SEXP get_service_method( SEXP pointer, SEXP name ){ +SEXP get_service_method(SEXP pointer, SEXP name) { - /* grab the Message pointer */ - Rcpp::XPtr desc(pointer) ; + /* grab the Message pointer */ + Rcpp::XPtr desc(pointer); - GPB::MethodDescriptor* method_desc = static_cast(0); - - switch( TYPEOF( name) ){ - case STRSXP: - { - /* what we are looking for */ - const char * what = CHAR( STRING_ELT(name, 0 ) ) ; - - /* the method descriptor */ - method_desc = (GPB::MethodDescriptor*)desc->FindMethodByName( what ) ; - - break ; - } - case REALSXP: - { - - /* the method descriptor */ - method_desc = (GPB::MethodDescriptor*)desc->method( (int)REAL(name)[0] ) ; - - break ; - } - case INTSXP: - { - /* the method descriptor */ - method_desc = (GPB::MethodDescriptor*)desc->method( INTEGER(name)[0] ) ; - - break ; - } - } - - if( !method_desc ){ - Rcpp::stop("could not get MethodDescriptor"); - } - return S4_MethodDescriptor( method_desc ); - + GPB::MethodDescriptor* method_desc = static_cast(0); + + switch (TYPEOF(name)) { + case STRSXP: { + /* what we are looking for */ + const char* what = CHAR(STRING_ELT(name, 0)); + + /* the method descriptor */ + method_desc = (GPB::MethodDescriptor*)desc->FindMethodByName(what); + + break; + } + case REALSXP: { + + /* the method descriptor */ + method_desc = + (GPB::MethodDescriptor*)desc->method((int)REAL(name)[0]); + + break; + } + case INTSXP: { + /* the method descriptor */ + method_desc = + (GPB::MethodDescriptor*)desc->method(INTEGER(name)[0]); + + break; + } + } + + if (!method_desc) { + Rcpp::stop("could not get MethodDescriptor"); + } + return S4_MethodDescriptor(method_desc); } #undef METHOD -} // namespace rprotobuf +} // namespace rprotobuf From noreply at r-forge.r-project.org Sat Dec 28 00:39:38 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 00:39:38 +0100 (CET) Subject: [Rprotobuf-commits] r617 - pkg/src Message-ID: <20131227233938.5E3BD180484@r-forge.r-project.org> Author: murray Date: 2013-12-28 00:39:37 +0100 (Sat, 28 Dec 2013) New Revision: 617 Modified: pkg/src/wrapper_EnumValueDescriptor.cpp Log: Consistent spacing/indentation with clang-format. Modified: pkg/src/wrapper_EnumValueDescriptor.cpp =================================================================== --- pkg/src/wrapper_EnumValueDescriptor.cpp 2013-12-27 23:37:32 UTC (rev 616) +++ pkg/src/wrapper_EnumValueDescriptor.cpp 2013-12-27 23:39:37 UTC (rev 617) @@ -22,31 +22,35 @@ #include "rprotobuf.h" #include "RcppMacros.h" -namespace rprotobuf{ +namespace rprotobuf { #undef METHOD -#define METHOD(__NAME__) RCPP_PP_CAT(EnumValueDescriptor__,__NAME__) +#define METHOD(__NAME__) RCPP_PP_CAT(EnumValueDescriptor__, __NAME__) -RPB_XP_METHOD_0( METHOD(as_character) , GPB::EnumValueDescriptor , DebugString) ; +RPB_XP_METHOD_0(METHOD(as_character), GPB::EnumValueDescriptor, DebugString); -RPB_FUNCTION_1(S4_Message, METHOD(as_Message) , Rcpp::XPtr d ){ - GPB::EnumValueDescriptorProto* message = new GPB::EnumValueDescriptorProto() ; - d->CopyTo( message ); - return S4_Message(message) ; +RPB_FUNCTION_1(S4_Message, METHOD(as_Message), + Rcpp::XPtr d) { + GPB::EnumValueDescriptorProto* message = + new GPB::EnumValueDescriptorProto(); + d->CopyTo(message); + return S4_Message(message); } - -RPB_FUNCTION_2( std::string, METHOD(name), Rcpp::XPtr d, bool full) { - return full ? d->full_name() : d->name() ; + +RPB_FUNCTION_2(std::string, METHOD(name), + Rcpp::XPtr d, bool full) { + return full ? d->full_name() : d->name(); } -RPB_FUNCTION_1( int, METHOD(number), Rcpp::XPtr d) { - return d->number() ; +RPB_FUNCTION_1(int, METHOD(number), Rcpp::XPtr d) { + return d->number(); } -RPB_FUNCTION_1(S4_EnumDescriptor, METHOD(enum_type), Rcpp::XPtr d ){ - return S4_EnumDescriptor( d->type()); +RPB_FUNCTION_1(S4_EnumDescriptor, METHOD(enum_type), + Rcpp::XPtr d) { + return S4_EnumDescriptor(d->type()); } #undef METHOD -} // namespace rprotobuf +} // namespace rprotobuf From noreply at r-forge.r-project.org Sat Dec 28 00:42:11 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 00:42:11 +0100 (CET) Subject: [Rprotobuf-commits] r618 - pkg/src Message-ID: <20131227234212.00B2D183F5B@r-forge.r-project.org> Author: murray Date: 2013-12-28 00:42:11 +0100 (Sat, 28 Dec 2013) New Revision: 618 Modified: pkg/src/wrapper_FieldDescriptor.cpp pkg/src/wrapper_FileDescriptor.cpp Log: Consistent spacing & indentations from clang-format. Modified: pkg/src/wrapper_FieldDescriptor.cpp =================================================================== --- pkg/src/wrapper_FieldDescriptor.cpp 2013-12-27 23:39:37 UTC (rev 617) +++ pkg/src/wrapper_FieldDescriptor.cpp 2013-12-27 23:42:11 UTC (rev 618) @@ -25,86 +25,90 @@ namespace rprotobuf { #undef METHOD -#define METHOD(__NAME__) RCPP_PP_CAT(FieldDescriptor__,__NAME__) +#define METHOD(__NAME__) RCPP_PP_CAT(FieldDescriptor__, __NAME__) - RPB_XP_METHOD_0( METHOD(as_character) , GPB::FieldDescriptor, DebugString) - RPB_XP_METHOD_0( METHOD(is_extension) , GPB::FieldDescriptor, is_extension) - RPB_XP_METHOD_0( METHOD(number) , GPB::FieldDescriptor, number) - RPB_XP_METHOD_0( METHOD(type) , GPB::FieldDescriptor, type ) - RPB_XP_METHOD_0( METHOD(cpp_type) , GPB::FieldDescriptor, cpp_type ) - RPB_XP_METHOD_0( METHOD(label) , GPB::FieldDescriptor, label ) - RPB_XP_METHOD_0( METHOD(is_repeated) , GPB::FieldDescriptor, is_repeated ) - RPB_XP_METHOD_0( METHOD(is_optional) , GPB::FieldDescriptor, is_optional ) - RPB_XP_METHOD_0( METHOD(is_required) , GPB::FieldDescriptor, is_required ) - RPB_XP_METHOD_0( METHOD(has_default_value) , GPB::FieldDescriptor, has_default_value ) +RPB_XP_METHOD_0(METHOD(as_character), GPB::FieldDescriptor, DebugString) +RPB_XP_METHOD_0(METHOD(is_extension), GPB::FieldDescriptor, is_extension) +RPB_XP_METHOD_0(METHOD(number), GPB::FieldDescriptor, number) +RPB_XP_METHOD_0(METHOD(type), GPB::FieldDescriptor, type) +RPB_XP_METHOD_0(METHOD(cpp_type), GPB::FieldDescriptor, cpp_type) +RPB_XP_METHOD_0(METHOD(label), GPB::FieldDescriptor, label) +RPB_XP_METHOD_0(METHOD(is_repeated), GPB::FieldDescriptor, is_repeated) +RPB_XP_METHOD_0(METHOD(is_optional), GPB::FieldDescriptor, is_optional) +RPB_XP_METHOD_0(METHOD(is_required), GPB::FieldDescriptor, is_required) +RPB_XP_METHOD_0(METHOD(has_default_value), GPB::FieldDescriptor, + has_default_value) - RPB_FUNCTION_1( S4_Descriptor, METHOD(containing_type), Rcpp::XPtr d){ - return S4_Descriptor( d->containing_type() ) ; - } - -#define RPB_HANDLE_CASE(__CPP__,__LC__) \ -case CPPTYPE_##__CPP__: \ - { \ - return Rcpp::wrap( d->default_value_##__LC__() ); \ - break ; \ - } +RPB_FUNCTION_1(S4_Descriptor, METHOD(containing_type), + Rcpp::XPtr d) { + return S4_Descriptor(d->containing_type()); +} - RPB_FUNCTION_1( SEXP, METHOD(default_value) , Rcpp::XPtr d ){ - switch( d->cpp_type() ){ - - RPB_HANDLE_CASE(INT32,int32) - RPB_HANDLE_CASE(UINT32,uint32) +#define RPB_HANDLE_CASE(__CPP__, __LC__) \ + case CPPTYPE_##__CPP__: { \ + return Rcpp::wrap(d->default_value_##__LC__()); \ + break; \ + } + +RPB_FUNCTION_1(SEXP, METHOD(default_value), + Rcpp::XPtr d) { + switch (d->cpp_type()) { + + RPB_HANDLE_CASE(INT32, int32) + RPB_HANDLE_CASE(UINT32, uint32) #ifdef RCPP_HAS_LONG_LONG_TYPES - RPB_HANDLE_CASE(INT64,int64) - RPB_HANDLE_CASE(UINT64,uint64) + RPB_HANDLE_CASE(INT64, int64) + RPB_HANDLE_CASE(UINT64, uint64) #endif - RPB_HANDLE_CASE(DOUBLE,double) - RPB_HANDLE_CASE(FLOAT,float) - RPB_HANDLE_CASE(BOOL,bool) - RPB_HANDLE_CASE(STRING,string) + RPB_HANDLE_CASE(DOUBLE, double) + RPB_HANDLE_CASE(FLOAT, float) + RPB_HANDLE_CASE(BOOL, bool) + RPB_HANDLE_CASE(STRING, string) - case CPPTYPE_ENUM: - { - return Rf_ScalarInteger( d->default_value_enum()->number() ) ; - break ; - } - default: - break ; - } - return R_NilValue ; - } - - RPB_FUNCTION_1(S4_Descriptor, METHOD(message_type), Rcpp::XPtr d){ - if( d->cpp_type() != CPPTYPE_MESSAGE ){ - throw Rcpp::not_compatible( "not a message type field" ) ; - } - return S4_Descriptor( d->message_type() ) ; - } - - RPB_FUNCTION_1(S4_EnumDescriptor, METHOD(enum_type), Rcpp::XPtr d){ - if( d->cpp_type() != CPPTYPE_ENUM ){ - Rcpp::stop("not an enum type field"); - } - return S4_EnumDescriptor( d->enum_type() ) ; - } + case CPPTYPE_ENUM: { + return Rf_ScalarInteger(d->default_value_enum()->number()); + break; + } + default: + break; + } + return R_NilValue; +} - RPB_FUNCTION_1(S4_Message, METHOD(as_Message), Rcpp::XPtr d ){ - GPB::FieldDescriptorProto* message = new GPB::FieldDescriptorProto() ; - d->CopyTo( message ); - return S4_Message( message ) ; - } - - RPB_FUNCTION_1( S4_FileDescriptor, METHOD(fileDescriptor), Rcpp::XPtr desc){ - return S4_FileDescriptor( desc->file() ); - } +RPB_FUNCTION_1(S4_Descriptor, METHOD(message_type), + Rcpp::XPtr d) { + if (d->cpp_type() != CPPTYPE_MESSAGE) { + throw Rcpp::not_compatible("not a message type field"); + } + return S4_Descriptor(d->message_type()); +} - RPB_FUNCTION_2( std::string, METHOD(name), Rcpp::XPtr d, bool full){ - return full ? d->full_name() : d->name() ; - } - - +RPB_FUNCTION_1(S4_EnumDescriptor, METHOD(enum_type), + Rcpp::XPtr d) { + if (d->cpp_type() != CPPTYPE_ENUM) { + Rcpp::stop("not an enum type field"); + } + return S4_EnumDescriptor(d->enum_type()); +} + +RPB_FUNCTION_1(S4_Message, METHOD(as_Message), + Rcpp::XPtr d) { + GPB::FieldDescriptorProto* message = new GPB::FieldDescriptorProto(); + d->CopyTo(message); + return S4_Message(message); +} + +RPB_FUNCTION_1(S4_FileDescriptor, METHOD(fileDescriptor), + Rcpp::XPtr desc) { + return S4_FileDescriptor(desc->file()); +} + +RPB_FUNCTION_2(std::string, METHOD(name), Rcpp::XPtr d, + bool full) { + return full ? d->full_name() : d->name(); +} + #undef RPB_HANDLE_CASE #undef METHOD - -} // namespace rprotobuf +} // namespace rprotobuf Modified: pkg/src/wrapper_FileDescriptor.cpp =================================================================== --- pkg/src/wrapper_FileDescriptor.cpp 2013-12-27 23:39:37 UTC (rev 617) +++ pkg/src/wrapper_FileDescriptor.cpp 2013-12-27 23:42:11 UTC (rev 618) @@ -1,96 +1,98 @@ #include "rprotobuf.h" #include "RcppMacros.h" -namespace rprotobuf{ +namespace rprotobuf { #undef METHOD -#define METHOD(__NAME__) RCPP_PP_CAT(FileDescriptor__,__NAME__) +#define METHOD(__NAME__) RCPP_PP_CAT(FileDescriptor__, __NAME__) -RPB_XP_METHOD_0( METHOD(as_character) , GPB::FileDescriptor , DebugString) ; +RPB_XP_METHOD_0(METHOD(as_character), GPB::FileDescriptor, DebugString); -RPB_FUNCTION_1(S4_Message, METHOD(as_Message), Rcpp::XPtr d ){ - GPB::FileDescriptorProto* message = new GPB::FileDescriptorProto() ; - d->CopyTo( message ); - return S4_Message( message ) ; +RPB_FUNCTION_1(S4_Message, METHOD(as_Message), + Rcpp::XPtr d) { + GPB::FileDescriptorProto* message = new GPB::FileDescriptorProto(); + d->CopyTo(message); + return S4_Message(message); } +RPB_FUNCTION_1(Rcpp::CharacterVector, METHOD(getMemberNames), + Rcpp::XPtr desc) { + int ntypes = desc->message_type_count(); + int nenums = desc->enum_type_count(); + int nserv = desc->service_count(); + int nexts = desc->extension_count(); -RPB_FUNCTION_1( Rcpp::CharacterVector, METHOD(getMemberNames), Rcpp::XPtr desc ){ - int ntypes = desc->message_type_count() ; - int nenums = desc->enum_type_count() ; - int nserv = desc->service_count() ; - int nexts = desc->extension_count() ; - - Rcpp::CharacterVector res( ntypes + nenums + nserv + nexts ) ; - int i=0; - int j=0; - while( imessage_type(i)->name() ; - i++; - j++; - } - i=0; - while( ienum_type(i)->name() ; - i++; - j++; - } - i = 0; - while( iservice(i)->name() ; - i++; - j++; - } - i = 0; - while( iextension(i)->name() ; - i++; - j++; - } - return res ; - + Rcpp::CharacterVector res(ntypes + nenums + nserv + nexts); + int i = 0; + int j = 0; + while (i < ntypes) { + res[j] = desc->message_type(i)->name(); + i++; + j++; + } + i = 0; + while (i < nenums) { + res[j] = desc->enum_type(i)->name(); + i++; + j++; + } + i = 0; + while (i < nserv) { + res[j] = desc->service(i)->name(); + i++; + j++; + } + i = 0; + while (i < nexts) { + res[j] = desc->extension(i)->name(); + i++; + j++; + } + return res; } /** * @param xp (GPB::FileDescriptor*) external pointer * @return the descriptor as an R list */ -RPB_FUNCTION_1( Rcpp::List, METHOD(as_list), Rcpp::XPtr desc ){ - int ntypes = desc->message_type_count() ; - int nenums = desc->enum_type_count() ; - int nserv = desc->service_count() ; - int nexts = desc->extension_count() ; - int n = ntypes + nenums + nserv + nexts; - - Rcpp::CharacterVector names(n) ; - Rcpp::List res( n ); - int i=0; - int j=0; - for( i=0; imessage_type(i) ) ; - names[j] = desc->message_type(i)->name() ; - } - for( i=0; ienum_type(i) ); - names[j] = desc->enum_type(i)->name() ; - } - for( i=0; iservice(i) ); - names[j] = desc->service(i)->name() ; - } - for( i=0; iextension(i) ); - // always use full names for extensions - names[j] = desc->extension(i)->full_name() ; - } - res.names() = names ; - return res; +RPB_FUNCTION_1(Rcpp::List, METHOD(as_list), + Rcpp::XPtr desc) { + int ntypes = desc->message_type_count(); + int nenums = desc->enum_type_count(); + int nserv = desc->service_count(); + int nexts = desc->extension_count(); + int n = ntypes + nenums + nserv + nexts; + + Rcpp::CharacterVector names(n); + Rcpp::List res(n); + int i = 0; + int j = 0; + for (i = 0; i < ntypes; j++, i++) { + res[j] = S4_Descriptor(desc->message_type(i)); + names[j] = desc->message_type(i)->name(); + } + for (i = 0; i < nenums; j++, i++) { + res[j] = S4_EnumDescriptor(desc->enum_type(i)); + names[j] = desc->enum_type(i)->name(); + } + for (i = 0; i < nserv; j++, i++) { + res[j] = S4_ServiceDescriptor(desc->service(i)); + names[j] = desc->service(i)->name(); + } + for (i = 0; i < nexts; j++, i++) { + res[j] = S4_FieldDescriptor(desc->extension(i)); + // always use full names for extensions + names[j] = desc->extension(i)->full_name(); + } + res.names() = names; + return res; } -RPB_FUNCTION_1( std::string, METHOD(name), Rcpp::XPtr desc ){ - return desc->name() ; +RPB_FUNCTION_1(std::string, METHOD(name), + Rcpp::XPtr desc) { + return desc->name(); } #undef METHOD -} // namespace rprotobuf +} // namespace rprotobuf From noreply at r-forge.r-project.org Sat Dec 28 00:44:50 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 00:44:50 +0100 (CET) Subject: [Rprotobuf-commits] r619 - pkg/src Message-ID: <20131227234450.B778B18631D@r-forge.r-project.org> Author: murray Date: 2013-12-28 00:44:50 +0100 (Sat, 28 Dec 2013) New Revision: 619 Modified: pkg/src/wrapper_Descriptor.cpp pkg/src/wrapper_EnumDescriptor.cpp Log: whitespace change only, clang-format consistency. Modified: pkg/src/wrapper_Descriptor.cpp =================================================================== --- pkg/src/wrapper_Descriptor.cpp 2013-12-27 23:42:11 UTC (rev 618) +++ pkg/src/wrapper_Descriptor.cpp 2013-12-27 23:44:50 UTC (rev 619) @@ -1,19 +1,19 @@ #include "rprotobuf.h" #include "RcppMacros.h" -namespace rprotobuf{ +namespace rprotobuf { #undef METHOD -#define METHOD(__NAME__) RCPP_PP_CAT(Descriptor__,__NAME__) +#define METHOD(__NAME__) RCPP_PP_CAT(Descriptor__, __NAME__) -RPB_XP_METHOD_0( METHOD(as_character), GPB::Descriptor , DebugString) -RPB_XP_METHOD_0( METHOD(field_count), GPB::Descriptor, field_count ) -RPB_XP_METHOD_0( METHOD(nested_type_count), GPB::Descriptor, nested_type_count ) -RPB_XP_METHOD_0( METHOD(enum_type_count), GPB::Descriptor, enum_type_count ) +RPB_XP_METHOD_0(METHOD(as_character), GPB::Descriptor, DebugString) +RPB_XP_METHOD_0(METHOD(field_count), GPB::Descriptor, field_count) +RPB_XP_METHOD_0(METHOD(nested_type_count), GPB::Descriptor, nested_type_count) +RPB_XP_METHOD_0(METHOD(enum_type_count), GPB::Descriptor, enum_type_count) -RPB_XP_METHOD_CAST_0( METHOD(containing_type), GPB::Descriptor, containing_type, S4_Descriptor ) +RPB_XP_METHOD_CAST_0(METHOD(containing_type), GPB::Descriptor, containing_type, + S4_Descriptor) - /** * returns the names of the members contained in the descriptor * (nested types, enums, fields) @@ -22,177 +22,197 @@ * * @return member names, as an R character vector (STRSXP) */ -RPB_FUNCTION_1( Rcpp::CharacterVector, METHOD(getMemberNames), Rcpp::XPtr desc ){ - - int nfields = desc->field_count() ; - int ntypes = desc->nested_type_count() ; - int nenums = desc->enum_type_count() ; - - Rcpp::CharacterVector res(nfields + ntypes + nenums ) ; - int j=0; - for (int i=0; ifield(i)->name() ; - } - for (int i=0;inested_type(i)->name() ; - } - for (int i=0; ienum_type(i)->name(); - } - return( res ); +RPB_FUNCTION_1(Rcpp::CharacterVector, METHOD(getMemberNames), + Rcpp::XPtr desc) { + + int nfields = desc->field_count(); + int ntypes = desc->nested_type_count(); + int nenums = desc->enum_type_count(); + + Rcpp::CharacterVector res(nfields + ntypes + nenums); + int j = 0; + for (int i = 0; i < nfields; i++, j++) { + res[j] = desc->field(i)->name(); + } + for (int i = 0; i < ntypes; i++, j++) { + res[j] = desc->nested_type(i)->name(); + } + for (int i = 0; i < nenums; i++, j++) { + res[j] = desc->enum_type(i)->name(); + } + return (res); } /** * @param xp external pointer to a Descriptor * @return the descriptor as an R list */ -RPB_FUNCTION_1( Rcpp::List, METHOD(as_list), Rcpp::XPtr desc ){ - - int nfields = desc->field_count() ; - int ntypes = desc->nested_type_count() ; - int nenums = desc->enum_type_count() ; - int n = nfields + ntypes + nenums ; - - Rcpp::CharacterVector names(n) ; - Rcpp::List res(n); - int i=0; - int j=0; - for( i=0; ifield(i) ; - res[j] = S4_FieldDescriptor( fd ); - names[j] = fd->name() ; - } - for( i=0; inested_type(i) ; - res[j] = S4_Descriptor( d ); - names[j] = d->name() ; - } - for( i=0; ienum_type(i) ; - res[j] = S4_EnumDescriptor( ed ); - names[j] = ed->name() ; - } - res.names() = names ; - - return res; +RPB_FUNCTION_1(Rcpp::List, METHOD(as_list), Rcpp::XPtr desc) { + + int nfields = desc->field_count(); + int ntypes = desc->nested_type_count(); + int nenums = desc->enum_type_count(); + int n = nfields + ntypes + nenums; + + Rcpp::CharacterVector names(n); + Rcpp::List res(n); + int i = 0; + int j = 0; + for (i = 0; i < nfields; j++, i++) { + const GPB::FieldDescriptor* fd = desc->field(i); + res[j] = S4_FieldDescriptor(fd); + names[j] = fd->name(); + } + for (i = 0; i < ntypes; j++, i++) { + const GPB::Descriptor* d = desc->nested_type(i); + res[j] = S4_Descriptor(d); + names[j] = d->name(); + } + for (i = 0; i < nenums; j++, i++) { + const GPB::EnumDescriptor* ed = desc->enum_type(i); + res[j] = S4_EnumDescriptor(ed); + names[j] = ed->name(); + } + res.names() = names; + + return res; } -RPB_FUNCTION_1(S4_Message, METHOD(as_Message) , Rcpp::XPtr d ){ - GPB::DescriptorProto* message = new GPB::DescriptorProto() ; - d->CopyTo( message ); - return message ; +RPB_FUNCTION_1(S4_Message, METHOD(as_Message), Rcpp::XPtr d) { + GPB::DescriptorProto* message = new GPB::DescriptorProto(); + d->CopyTo(message); + return message; } -RPB_FUNCTION_2( S4_FieldDescriptor, METHOD(field), Rcpp::XPtr d, int i){ - return d->field( i ) ; +RPB_FUNCTION_2(S4_FieldDescriptor, METHOD(field), Rcpp::XPtr d, + int i) { + return d->field(i); } -RPB_FUNCTION_2( S4_FieldDescriptor, METHOD(FindFieldByNumber), Rcpp::XPtr d, int num){ - return d->FindFieldByNumber( num ) ; +RPB_FUNCTION_2(S4_FieldDescriptor, METHOD(FindFieldByNumber), + Rcpp::XPtr d, int num) { + return d->FindFieldByNumber(num); } -RPB_FUNCTION_2( S4_FieldDescriptor, METHOD(FindFieldByName), Rcpp::XPtr d, std::string nam ){ - return d->FindFieldByName( nam ) ; +RPB_FUNCTION_2(S4_FieldDescriptor, METHOD(FindFieldByName), + Rcpp::XPtr d, std::string nam) { + return d->FindFieldByName(nam); } -RPB_FUNCTION_2( S4_Descriptor, METHOD(nested_type), Rcpp::XPtr d, int i){ - return d->nested_type( i ) ; +RPB_FUNCTION_2(S4_Descriptor, METHOD(nested_type), + Rcpp::XPtr d, int i) { + return d->nested_type(i); } -RPB_FUNCTION_2( S4_Descriptor, METHOD(FindNestedTypeByName), Rcpp::XPtr d, std::string nam){ - return d->FindNestedTypeByName( nam ) ; +RPB_FUNCTION_2(S4_Descriptor, METHOD(FindNestedTypeByName), + Rcpp::XPtr d, std::string nam) { + return d->FindNestedTypeByName(nam); } -RPB_FUNCTION_2( S4_EnumDescriptor, METHOD(enum_type), Rcpp::XPtr d, int i){ - return d->enum_type( i ) ; +RPB_FUNCTION_2(S4_EnumDescriptor, METHOD(enum_type), + Rcpp::XPtr d, int i) { + return d->enum_type(i); } // FIXME: two methods cant have the same name -// RPB_FUNCTION_2( S4_EnumDescriptor, METHOD(enum_type), Rcpp::XPtr d, std::string name){ +// RPB_FUNCTION_2( S4_EnumDescriptor, METHOD(enum_type), +// Rcpp::XPtr d, std::string name){ // return d->FindEnumTypeByName( i ) ; // } -RPB_FUNCTION_1( S4_FileDescriptor, METHOD(fileDescriptor), Rcpp::XPtr desc){ - return S4_FileDescriptor( desc->file() ); +RPB_FUNCTION_1(S4_FileDescriptor, METHOD(fileDescriptor), + Rcpp::XPtr desc) { + return S4_FileDescriptor(desc->file()); } -RPB_FUNCTION_2( std::string, METHOD(name), Rcpp::XPtr d, bool full){ - return full ? d->full_name() : d->name() ; +RPB_FUNCTION_2(std::string, METHOD(name), Rcpp::XPtr d, + bool full) { + return full ? d->full_name() : d->name(); } -RPB_FUNCTION_2( S4_Message, METHOD(readMessageFromFile), Rcpp::XPtr desc, std::string filename ){ - /* open the file to read in binary mode */ - int file = open( filename.c_str() , O_RDONLY | O_BINARY); - - /* 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()" ) ; - } - - /* read the message from the file */ - message->ParsePartialFromFileDescriptor( file ); - close( file ) ; - return( S4_Message( message ) ) ; +RPB_FUNCTION_2(S4_Message, METHOD(readMessageFromFile), + Rcpp::XPtr desc, std::string filename) { + /* open the file to read in binary mode */ + int file = open(filename.c_str(), O_RDONLY | O_BINARY); + + /* 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()"); + } + + /* read the message from the file */ + message->ParsePartialFromFileDescriptor(file); + close(file); + return (S4_Message(message)); } -RPB_FUNCTION_2( S4_Message, METHOD(readMessageFromConnection), Rcpp::XPtr desc, int conn_id ){ - RconnectionCopyingInputStream wrapper( conn_id ) ; - GPB::io::CopyingInputStreamAdaptor stream( &wrapper ) ; - GPB::io::CodedInputStream coded_stream(&stream ) ; - - /* 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()" ) ; - } - message->ParsePartialFromCodedStream( &coded_stream) ; - - S4_Message res( message ) ; - return res ; +RPB_FUNCTION_2(S4_Message, METHOD(readMessageFromConnection), + Rcpp::XPtr desc, int conn_id) { + RconnectionCopyingInputStream wrapper(conn_id); + GPB::io::CopyingInputStreamAdaptor stream(&wrapper); + GPB::io::CodedInputStream coded_stream(&stream); + + /* 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()"); + } + message->ParsePartialFromCodedStream(&coded_stream); + + S4_Message res(message); + return res; } -RPB_FUNCTION_2( S4_Message, METHOD(readMessageFromRawVector), Rcpp::XPtr desc, Rcpp::RawVector raw){ - GPB::io::ArrayInputStream ais( (void*)raw.begin(), raw.size() ); - GPB::io::CodedInputStream stream( &ais ) ; - - GPB::Message* message = PROTOTYPE( desc ) ; - if( !message ){ - throw std::range_error( "could not call factory->GetPrototype(desc)->New()" ) ; - } - - message->MergePartialFromCodedStream( &stream ) ; - return( S4_Message( message ) ) ; +RPB_FUNCTION_2(S4_Message, METHOD(readMessageFromRawVector), + Rcpp::XPtr desc, Rcpp::RawVector raw) { + GPB::io::ArrayInputStream ais((void*)raw.begin(), raw.size()); + GPB::io::CodedInputStream stream(&ais); + + GPB::Message* message = PROTOTYPE(desc); + if (!message) { + throw std::range_error( + "could not call factory->GetPrototype(desc)->New()"); + } + + message->MergePartialFromCodedStream(&stream); + return (S4_Message(message)); } -RPB_FUNCTION_2( S4_Message, METHOD(readASCIIFromString), Rcpp::XPtr desc, std::string input){ - GPB::Message* message = PROTOTYPE( desc ) ; - if (GPB::TextFormat::ParseFromString( input, message ) ) { - return( S4_Message( message ) ) ; - } else { - throw std::range_error("Could not parse ASCII protocol buffer from text string."); - } +RPB_FUNCTION_2(S4_Message, METHOD(readASCIIFromString), + Rcpp::XPtr desc, std::string input) { + GPB::Message* message = PROTOTYPE(desc); + if (GPB::TextFormat::ParseFromString(input, message)) { + return (S4_Message(message)); + } else { + throw std::range_error( + "Could not parse ASCII protocol buffer from text string."); + } } -RPB_FUNCTION_2( S4_Message, METHOD(readASCIIFromConnection), Rcpp::XPtr desc, int conn_id){ - RconnectionCopyingInputStream wrapper( conn_id ) ; - GPB::io::CopyingInputStreamAdaptor stream( &wrapper ) ; +RPB_FUNCTION_2(S4_Message, METHOD(readASCIIFromConnection), + Rcpp::XPtr 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()" ) ; - } - if (!GPB::TextFormat::Parse( &stream, message ) ) { - throw std::range_error("Could not parse ASCII protocol buffer."); - } else { - if (wrapper.Failure()) { - throw std::range_error("Could not read ASCII protocol buffer."); - } - return( S4_Message( message ) ); + /* 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()"); + } + if (!GPB::TextFormat::Parse(&stream, message)) { + throw std::range_error("Could not parse ASCII protocol buffer."); + } else { + if (wrapper.Failure()) { + throw std::range_error("Could not read ASCII protocol buffer."); } + return (S4_Message(message)); + } } #undef METHOD -} // namespace rprotobuf +} // namespace rprotobuf Modified: pkg/src/wrapper_EnumDescriptor.cpp =================================================================== --- pkg/src/wrapper_EnumDescriptor.cpp 2013-12-27 23:42:11 UTC (rev 618) +++ pkg/src/wrapper_EnumDescriptor.cpp 2013-12-27 23:44:50 UTC (rev 619) @@ -22,57 +22,62 @@ #include "rprotobuf.h" #include "RcppMacros.h" -namespace rprotobuf{ +namespace rprotobuf { #undef METHOD -#define METHOD(__NAME__) RCPP_PP_CAT(EnumDescriptor__,__NAME__) +#define METHOD(__NAME__) RCPP_PP_CAT(EnumDescriptor__, __NAME__) - RPB_XP_METHOD_0(METHOD(as_character), GPB::EnumDescriptor , DebugString) ; - RPB_XP_METHOD_0(METHOD(length) ,GPB::EnumDescriptor,value_count) - RPB_XP_METHOD_0(METHOD(value_count) ,GPB::EnumDescriptor,value_count) - - RPB_FUNCTION_1(S4_Descriptor, METHOD(containing_type), Rcpp::XPtr d ){ - return S4_Descriptor( d->containing_type() ) ; - } +RPB_XP_METHOD_0(METHOD(as_character), GPB::EnumDescriptor, DebugString); +RPB_XP_METHOD_0(METHOD(length), GPB::EnumDescriptor, value_count) +RPB_XP_METHOD_0(METHOD(value_count), GPB::EnumDescriptor, value_count) - RPB_FUNCTION_2( S4_EnumValueDescriptor, METHOD(getValueByIndex) , Rcpp::XPtr d, int index){ - if ((index >= 0) && (index < d->value_count())) { - return S4_EnumValueDescriptor( d->value(index) ) ; - } else { - return S4_EnumValueDescriptor(NULL); - } - } - - RPB_FUNCTION_2( S4_EnumValueDescriptor, METHOD(getValueByNumber), Rcpp::XPtr d, int i ){ - return S4_EnumValueDescriptor( d->FindValueByNumber(i) ) ; - } - RPB_FUNCTION_2( S4_EnumValueDescriptor, METHOD(getValueByName) , Rcpp::XPtr d , std::string name ){ - return S4_EnumValueDescriptor( d->FindValueByName(name) ) ; - } +RPB_FUNCTION_1(S4_Descriptor, METHOD(containing_type), + Rcpp::XPtr d) { + return S4_Descriptor(d->containing_type()); +} - RPB_FUNCTION_1(S4_Message, METHOD(as_Message), Rcpp::XPtr d ){ - GPB::EnumDescriptorProto* message = new GPB::EnumDescriptorProto() ; - d->CopyTo( message ); - return S4_Message(message) ; - } - +RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByIndex), + Rcpp::XPtr d, int index) { + if ((index >= 0) && (index < d->value_count())) { + return S4_EnumValueDescriptor(d->value(index)); + } else { + return S4_EnumValueDescriptor(NULL); + } +} + +RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByNumber), + Rcpp::XPtr d, int i) { + return S4_EnumValueDescriptor(d->FindValueByNumber(i)); +} +RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByName), + Rcpp::XPtr d, std::string name) { + return S4_EnumValueDescriptor(d->FindValueByName(name)); +} + +RPB_FUNCTION_1(S4_Message, METHOD(as_Message), + Rcpp::XPtr d) { + GPB::EnumDescriptorProto* message = new GPB::EnumDescriptorProto(); + d->CopyTo(message); + return S4_Message(message); +} + /** * Get the value of the enum called name * * @param xp external pointer to an EnumDescriptor * @param name the name of the enum - * + * * @param the value associated with the name */ -RPB_FUNCTION_2(int,get_value_of_enum, - Rcpp::XPtr d, std::string name){ - - const GPB::EnumValueDescriptor* evd = d->FindValueByName(name) ; - if( !evd ){ - /* or maybe it should just be NA */ - Rcpp::stop("cannot get the value"); +RPB_FUNCTION_2(int, get_value_of_enum, Rcpp::XPtr d, + std::string name) { + + const GPB::EnumValueDescriptor* evd = d->FindValueByName(name); + if (!evd) { + /* or maybe it should just be NA */ + Rcpp::stop("cannot get the value"); } - return evd->number(); + return evd->number(); } /** @@ -82,48 +87,52 @@ * @param name the name of the enum * @return logical */ -RPB_FUNCTION_2(bool,has_enum_name, - Rcpp::XPtr d, std::string name){ - const GPB::EnumValueDescriptor* evd = d->FindValueByName(name) ; - return (evd != NULL); +RPB_FUNCTION_2(bool, has_enum_name, Rcpp::XPtr d, + std::string name) { + const GPB::EnumValueDescriptor* evd = d->FindValueByName(name); + return (evd != NULL); } /** * @param xp external pointer to a Descriptor * @return the descriptor as an R list */ -RPB_FUNCTION_1( Rcpp::IntegerVector, METHOD(as_list), Rcpp::XPtr d ){ - - int n = d->value_count() ; - Rcpp::IntegerVector values(n) ; - Rcpp::CharacterVector names(n) ; - - for( int i=0; ivalue(i) ; - values[i] = value_d->number() ; - names[i] = value_d->name() ; - } - values.names() = names ; - return values; +RPB_FUNCTION_1(Rcpp::IntegerVector, METHOD(as_list), + Rcpp::XPtr d) { + + int n = d->value_count(); + Rcpp::IntegerVector values(n); + Rcpp::CharacterVector names(n); + + for (int i = 0; i < n; i++) { + const GPB::EnumValueDescriptor* value_d = d->value(i); + values[i] = value_d->number(); + names[i] = value_d->name(); + } + values.names() = names; + return values; } -RPB_FUNCTION_1( Rcpp::CharacterVector, METHOD(getConstantNames), Rcpp::XPtr d){ - int n = d->value_count() ; - Rcpp::CharacterVector res( n) ; - for( int i=0; ivalue(i)->name() ; - } - return res ; +RPB_FUNCTION_1(Rcpp::CharacterVector, METHOD(getConstantNames), + Rcpp::XPtr d) { + int n = d->value_count(); + Rcpp::CharacterVector res(n); + for (int i = 0; i < n; i++) { + res[i] = d->value(i)->name(); + } + return res; } -RPB_FUNCTION_1( S4_FileDescriptor, METHOD(fileDescriptor), Rcpp::XPtr desc){ - return S4_FileDescriptor( desc->file() ); +RPB_FUNCTION_1(S4_FileDescriptor, METHOD(fileDescriptor), + Rcpp::XPtr desc) { + return S4_FileDescriptor(desc->file()); } -RPB_FUNCTION_2( std::string, METHOD(name), Rcpp::XPtr d, bool full){ - return full ? d->full_name() : d->name() ; +RPB_FUNCTION_2(std::string, METHOD(name), Rcpp::XPtr d, + bool full) { + return full ? d->full_name() : d->name(); } #undef METHOD -} // namespace rprotobuf +} // namespace rprotobuf From noreply at r-forge.r-project.org Sat Dec 28 00:46:01 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 00:46:01 +0100 (CET) Subject: [Rprotobuf-commits] r620 - pkg/src Message-ID: <20131227234601.98A55184B6B@r-forge.r-project.org> Author: murray Date: 2013-12-28 00:46:01 +0100 (Sat, 28 Dec 2013) New Revision: 620 Modified: pkg/src/wrapper_ArrayInputStream.cpp pkg/src/wrapper_ArrayOutputStream.cpp Log: whitespace change only: clang-format Modified: pkg/src/wrapper_ArrayInputStream.cpp =================================================================== --- pkg/src/wrapper_ArrayInputStream.cpp 2013-12-27 23:44:50 UTC (rev 619) +++ pkg/src/wrapper_ArrayInputStream.cpp 2013-12-27 23:46:01 UTC (rev 620) @@ -2,10 +2,10 @@ #include "rprotobuf.h" #include "RcppMacros.h" -namespace rprotobuf{ +namespace rprotobuf { - RPB_FUNCTION_2( S4_ArrayInputStream, ArrayInputStream__new, Rcpp::RawVector payload, int block_size){ - return S4_ArrayInputStream( payload, block_size ); - } - +RPB_FUNCTION_2(S4_ArrayInputStream, ArrayInputStream__new, + Rcpp::RawVector payload, int block_size) { + return S4_ArrayInputStream(payload, block_size); } +} Modified: pkg/src/wrapper_ArrayOutputStream.cpp =================================================================== --- pkg/src/wrapper_ArrayOutputStream.cpp 2013-12-27 23:44:50 UTC (rev 619) +++ pkg/src/wrapper_ArrayOutputStream.cpp 2013-12-27 23:46:01 UTC (rev 620) @@ -2,10 +2,10 @@ #include "rprotobuf.h" #include "RcppMacros.h" -namespace rprotobuf{ +namespace rprotobuf { - RPB_FUNCTION_2( S4_ArrayOutputStream, ArrayOutputStream__new, int size, int block_size){ - return S4_ArrayOutputStream( size, block_size ) ; - } - +RPB_FUNCTION_2(S4_ArrayOutputStream, ArrayOutputStream__new, int size, + int block_size) { + return S4_ArrayOutputStream(size, block_size); } +} From noreply at r-forge.r-project.org Sat Dec 28 00:48:20 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 00:48:20 +0100 (CET) Subject: [Rprotobuf-commits] r621 - pkg/src Message-ID: <20131227234820.1DD8A1864A0@r-forge.r-project.org> Author: murray Date: 2013-12-28 00:48:19 +0100 (Sat, 28 Dec 2013) New Revision: 621 Modified: pkg/src/RSourceTree.cpp pkg/src/RWarningErrorCollector.cpp pkg/src/RconnectionCopyingInputStream.cpp Log: whitespace change only: clang-format Modified: pkg/src/RSourceTree.cpp =================================================================== --- pkg/src/RSourceTree.cpp 2013-12-27 23:46:01 UTC (rev 620) +++ pkg/src/RSourceTree.cpp 2013-12-27 23:48:19 UTC (rev 621) @@ -3,57 +3,54 @@ namespace rprotobuf { - RSourceTree::RSourceTree() : directories() {} - - GPB::io::ZeroCopyInputStream * RSourceTree::Open(const std::string & filename){ - /* first, try to open the file as it is */ - int file_descriptor = open(filename.c_str(), O_RDONLY); - if (file_descriptor < 0) { - /* then try the directories */ - std::set::iterator it ; - it = directories.begin() ; - std::string file ; - while( it != directories.end() ){ - file = *it ; - file += "/" ; - file += filename ; - file_descriptor = open( file.c_str() , O_RDONLY) ; - if( file_descriptor > 0 ) break ; - it++; - } - } - - if( file_descriptor < 0 ){ - return NULL ; - } - - GPB::io::FileInputStream* result = new GPB::io::FileInputStream(file_descriptor); - result->SetCloseOnDelete(true); - return result; - } - - void RSourceTree::addDirectory( const std::string& directory){ - directories.insert( directory ) ; - } - void RSourceTree::addDirectories( SEXP dirs ){ - int n = LENGTH(dirs); - for( int i=0; i::iterator it; + it = directories.begin(); + std::string file; + while (it != directories.end()) { + file = *it; + file += "/"; + file += filename; + file_descriptor = open(file.c_str(), O_RDONLY); + if (file_descriptor > 0) break; + it++; + } + } + if (file_descriptor < 0) { + return NULL; + } + + GPB::io::FileInputStream* result = + new GPB::io::FileInputStream(file_descriptor); + result->SetCloseOnDelete(true); + return result; +} + +void RSourceTree::addDirectory(const std::string& directory) { + directories.insert(directory); +} +void RSourceTree::addDirectories(SEXP dirs) { + int n = LENGTH(dirs); + for (int i = 0; i < n; i++) { + directories.insert(std::string(CHAR(STRING_ELT(dirs, i)))); + } +} + +void RSourceTree::removeDirectory(const std::string& directory) { + directories.erase(directory); +} +void RSourceTree::removeDirectories(SEXP dirs) { + int n = LENGTH(dirs); + for (int i = 0; i < n; i++) { + directories.erase(std::string(CHAR(STRING_ELT(dirs, i)))); + } +} + +} // namespace rprotobuf Modified: pkg/src/RWarningErrorCollector.cpp =================================================================== --- pkg/src/RWarningErrorCollector.cpp 2013-12-27 23:46:01 UTC (rev 620) +++ pkg/src/RWarningErrorCollector.cpp 2013-12-27 23:48:19 UTC (rev 621) @@ -1,13 +1,13 @@ #include "rprotobuf.h" -#include "RWarningErrorCollector.h" +#include "RWarningErrorCollector.h" namespace rprotobuf { - void RWarningErrorCollector::AddError(const std::string& filename, int line, int column, - const std::string& message) { - - Rprintf( "%s:%d:%d:%s\n", filename.c_str(), line+1, column+1, message.c_str() ) ; - } +void RWarningErrorCollector::AddError(const std::string& filename, int line, + int column, const std::string& message) { -} // namespace rprotobuf + Rprintf("%s:%d:%d:%s\n", filename.c_str(), line + 1, column + 1, + message.c_str()); +} +} // namespace rprotobuf Modified: pkg/src/RconnectionCopyingInputStream.cpp =================================================================== --- pkg/src/RconnectionCopyingInputStream.cpp 2013-12-27 23:46:01 UTC (rev 620) +++ pkg/src/RconnectionCopyingInputStream.cpp 2013-12-27 23:48:19 UTC (rev 621) @@ -1,35 +1,35 @@ #include "rprotobuf.h" #include "RconnectionCopyingInputStream.h" -namespace rprotobuf{ - /* N.B. connection must be opened in binary mode due to call - * to readBin below. */ - RconnectionCopyingInputStream::RconnectionCopyingInputStream(int id) : - connection_id(id), - failure(false) {} - - /** - * call readBin to read size bytes from R - * - * @param buffer buffer to fill with at most size bytes - * @param size maximum number of bytes - * - * @return the number of bytes actually read - */ - int RconnectionCopyingInputStream::Read(void * buffer, int size){ - Rcpp::Language call( "readBin", connection_id, Rcpp::RawVector(0), size ) ; - Rcpp::RawVector res ; - try{ - res = call.eval(); - } catch( ... ){ - /* Failed to read anything from the connection, - * could have been permissions, or connection opened - * in the wrong type, etc. */ - failure = true; - return -1 ; - } - int len = res.size() ; - memcpy( buffer, reinterpret_cast(res.begin()), len) ; - return len ; - } +namespace rprotobuf { +/* N.B. connection must be opened in binary mode due to call + * to readBin below. */ +RconnectionCopyingInputStream::RconnectionCopyingInputStream(int id) + : connection_id(id), failure(false) {} + +/** + * call readBin to read size bytes from R + * + * @param buffer buffer to fill with at most size bytes + * @param size maximum number of bytes + * + * @return the number of bytes actually read + */ +int RconnectionCopyingInputStream::Read(void* buffer, int size) { + Rcpp::Language call("readBin", connection_id, Rcpp::RawVector(0), size); + Rcpp::RawVector res; + try { + res = call.eval(); + } + catch (...) { + /* Failed to read anything from the connection, + * could have been permissions, or connection opened + * in the wrong type, etc. */ + failure = true; + return -1; + } + int len = res.size(); + memcpy(buffer, reinterpret_cast(res.begin()), len); + return len; } +} From noreply at r-forge.r-project.org Sat Dec 28 00:56:26 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 00:56:26 +0100 (CET) Subject: [Rprotobuf-commits] r622 - / Message-ID: <20131227235626.74C9A18657E@r-forge.r-project.org> Author: murray Date: 2013-12-28 00:56:26 +0100 (Sat, 28 Dec 2013) New Revision: 622 Added: STYLE Log: Add notes about clang-format. Added: STYLE =================================================================== --- STYLE (rev 0) +++ STYLE 2013-12-27 23:56:26 UTC (rev 622) @@ -0,0 +1,22 @@ +The RProtoBuf code base is a mix of many coding styles regarding +indentation, spaces, braces, and more. + +Murray proposes running the whole code base through + + clang-format -style="{BasedOnStyle: google, IndentWidth: 4}" -i *.cpp + +There are a number of other parameters that can be set however, see the full output of + + clang-format -dump-config + +One changes have been made locally, you can view the diff with whitespace omitted with : + + svn diff -x -w + +This will still pull up all the changes where lines were broken at 80 +characters or braces changed lines, but will ignore most of the pure +whitespace changes for reviewing purposes before submitting. + +After the code base has been converted with clang-format, the emacs +metadata comments at the top of each file will need to be updated as +well. \ No newline at end of file From noreply at r-forge.r-project.org Sat Dec 28 01:54:18 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 01:54:18 +0100 (CET) Subject: [Rprotobuf-commits] r623 - papers/rjournal Message-ID: <20131228005418.DC52318657E@r-forge.r-project.org> Author: murray Date: 2013-12-28 01:54:18 +0100 (Sat, 28 Dec 2013) New Revision: 623 Modified: papers/rjournal/eddelbuettel-francois-stokely.bib Log: Add rhipe and tierney serialization references. Modified: papers/rjournal/eddelbuettel-francois-stokely.bib =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-27 23:56:26 UTC (rev 622) +++ papers/rjournal/eddelbuettel-francois-stokely.bib 2013-12-28 00:54:18 UTC (rev 623) @@ -13,6 +13,18 @@ year={2013}, publisher={Springer} } + at Manual{rhipe, + title = {RHIPE: A Distributed Environment for the Analysis of Large and Complex Datasets}, + author = {Saptarshi Guha}, + year = {2010}, + url = {http://www.stat.purdue.edu/~sguha/rhipe/}, +} + at misc{serialization, +author= {Tierney, Luke}, +title = {A New Serialization Mechanism for R}, +url = {http://www.cs.uiowa.edu/~luke/R/serialize/serialize.ps}, +year = {2003}, +} @article{eddelbuettel2010exposing, title={Exposing C++ functions and classes with Rcpp modules}, author={Eddelbuettel, Dirk and Fran{\c{c}}ois, Romain}, From noreply at r-forge.r-project.org Sat Dec 28 02:43:57 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 02:43:57 +0100 (CET) Subject: [Rprotobuf-commits] r624 - papers/rjournal Message-ID: <20131228014357.D8176186506@r-forge.r-project.org> Author: murray Date: 2013-12-28 02:43:57 +0100 (Sat, 28 Dec 2013) New Revision: 624 Added: papers/rjournal/histogram-mapreduce-diag1.pdf Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw Log: Add a large new section showing how RProtoBuf can be used to serialize all of the example datasets that ship with R, and compare the sizes with R's built-in serialziation method. Steal a section on applications/MapReduce from the HistogramTools vignette. To be improved further. Combine each of the class slot and method tables into a single table for each class. Add a brief section on type coercion issues for e.g. bools and int64s. Improve the wording in various places. Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-28 00:54:18 UTC (rev 623) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-28 01:43:57 UTC (rev 624) @@ -11,6 +11,7 @@ \title{RProtoBuf: Efficient Cross-Language Data Serialization in R} \author{by Dirk Eddelbuettel, Romain Fran\c{c}ois, and Murray Stokely} + \maketitle \abstract{Modern data collection and analysis pipelines often involve @@ -62,6 +63,10 @@ basics of protocol buffers and \CRANpkg{RProtoBuf}, we illustrate several common use cases for protocol buffers in data analysis. +XXX Related work on IDLs (greatly expanded ) + +XXX Design tradeoffs: reflection vs proto compiler + \section{Protocol Buffers} Once the data serialization needs get complex enough, application @@ -474,13 +479,17 @@ \subsection{Messages} The \texttt{Message} S4 class represents Protocol Buffer Messages and -is the core abstraction of \CRANpkg{RProtoBuf}. The class contains -the slots \texttt{pointer} and \texttt{type} as described on the -Table~\ref{Message-class-table}. +is the core abstraction of \CRANpkg{RProtoBuf}. Each \texttt{Message} +contains a pointer to a \texttt{Descriptor} which defines the schema +of the data defined in the Message, as well as a number of +\texttt{FieldDescriptors} for the individual fields of the message. A +complete list of the slots and methods for \texttt{Messages} +is available in Table~\ref{Message-methods-table}. \begin{table}[h] \centering -\begin{tabular}{|cp{10cm}|} +\begin{small} +\begin{tabular}{l|p{10cm}} \hline \textbf{Slot} & \textbf{Description} \\ \hline @@ -489,26 +498,10 @@ \url{http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.message.html#Message} \\ \hline \texttt{type} & Fully qualified name of the message. For example a \texttt{Person} message -has its \texttt{type} slot set to \texttt{tutorial.Person} \\ +has its \texttt{type} slot set to \texttt{tutorial.Person} \\[.3cm] \hline -\end{tabular} -\caption{\label{Message-class-table}Description of slots for the \texttt{Message} S4 class} -\end{table} - -Each \texttt{Message} contains a pointer to a \texttt{Descriptor} -which defines the schema of the data defined in the Message, as well -as a number of \texttt{FieldDescriptors} for the individual fields of -the message. In addition to the field name extractors of -\texttt{Messages} introduced in the previous section, a complete list -of Message methods is available in Table~\ref{Message-methods-table}. - -\begin{table}[h] -\centering -\begin{small} -\begin{tabular}{l|l} \textbf{Method} & \textbf{Description} \\ \hline -\hline \texttt{has} & Indicates if a message has a given field. \\ \texttt{clone} & Creates a clone of the message \\ \texttt{isInitialized} & Indicates if a message has all its required fields set\\ @@ -534,36 +527,17 @@ \hline \end{tabular} \end{small} -\caption{\label{Message-methods-table}Description of methods for the \texttt{Message} S4 class} +\caption{\label{Message-methods-table}Description of slots and methods for the \texttt{Message} S4 class} \end{table} \subsection{Descriptors} -Message descriptors are represented in R with the -\emph{Descriptor} S4 class. The class contains -the slots \texttt{pointer} and \texttt{type} : +Message descriptors are represented in R with the \emph{Descriptor} S4 +class. The class contains the slots \texttt{pointer} and +\texttt{type}. Similarly to messages, the \verb|$| operator can be +used to retrieve descriptors that are contained in the descriptor, or +invoke pseudo-methods. -\begin{table}[h] -\centering -\begin{tabular}{|cp{10cm}|} -\hline -\textbf{Slot} & \textbf{Description} \\ -\hline -\texttt{pointer} & External pointer to the \texttt{Descriptor} object of the C++ proto library. Documentation for the -\texttt{Descriptor} class is available from the protocol buffer project page: -\url{http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.descriptor.html#Descriptor} \\ -\hline -\texttt{type} & Fully qualified path of the message type. \\ -\hline -\end{tabular} -\caption{\label{Descriptor-class-table}Description of slots for the \texttt{Descriptor} S4 class} -\end{table} - -Similarly to messages, the \verb|$| operator can be used to retrieve -descriptors that are contained in the descriptor, or invoke -pseudo-methods. Thise can be used to extract field descriptors, enum -descriptors, or descriptors for a nested type. - <<>>= # field descriptor tutorial.Person$email @@ -578,15 +552,23 @@ @ Table~\ref{Descriptor-methods-table} provides a complete list of the -avalailable methods for Descriptors. +slots and avalailable methods for Descriptors. \begin{table}[h] \centering \begin{small} -\begin{tabular}{l|l} +\begin{tabular}{l|p{10cm}} +\hline +\textbf{Slot} & \textbf{Description} \\ +\hline +\texttt{pointer} & External pointer to the \texttt{Descriptor} object of the C++ proto library. Documentation for the +\texttt{Descriptor} class is available from the protocol buffer project page: +\url{http://code.google.com/apis/protocolbuffers/docs/reference/cpp/google.protobuf.descriptor.html#Descriptor} \\ +\hline +\texttt{type} & Fully qualified path of the message type. \\[.3cm] +\hline \textbf{Method} & \textbf{Description} \\ \hline -\hline \texttt{new} & Creates a prototype of a message described by this descriptor.\\ \texttt{read} & Reads a message from a file or binary connection.\\ \texttt{readASCII} & Read a message in ASCII format from a file or @@ -614,10 +596,10 @@ \hline \end{tabular} \end{small} -\caption{\label{Descriptor-methods-table}Description of methods for the \texttt{Descriptor} S4 class} +\caption{\label{Descriptor-methods-table}Description of slots and methods for the \texttt{Descriptor} S4 class} \end{table} -\subsection{field descriptors} +\subsection{Field Descriptors} \label{subsec-field-descriptor} The class \emph{FieldDescriptor} represents field @@ -628,7 +610,8 @@ \begin{table}[h] \centering -\begin{tabular}{|cp{10cm}|} +\begin{small} +\begin{tabular}{l|p{10cm}} \hline \textbf{Slot} & \textbf{Description} \\ \hline @@ -638,21 +621,10 @@ \hline \texttt{full\_name} & Fully qualified name of the field \\ \hline -\texttt{type} & Name of the message type where the field is declared \\ +\texttt{type} & Name of the message type where the field is declared \\[.3cm] \hline -\end{tabular} -\caption{\label{FieldDescriptor-class-table}Description of slots for the \texttt{FieldDescriptor} S4 class} -\end{table} - - -\begin{table}[h] -\centering -\begin{small} -\begin{tabular}{l|l} -\hline \textbf{Method} & \textbf{Description} \\ \hline -\hline \texttt{as.character} & Character representation of a descriptor\\ \texttt{toString} & Character representation of a descriptor (same as \texttt{as.character}) \\ @@ -675,14 +647,15 @@ \hline \end{tabular} \end{small} -\caption{\label{fielddescriptor-methods-table}Description of methods for the \texttt{FieldDescriptor} S4 class} +\caption{\label{fielddescriptor-methods-table}Description of slots and + methods for the \texttt{FieldDescriptor} S4 class} \end{table} % TODO(ms): Useful distinction to make -- FieldDescriptor does not do % separate '$' dispatch like Messages, Descriptors, and % EnumDescriptors do. Should it? -\subsection{enum descriptors} +\subsection{Enum Descriptors} \label{subsec-enum-descriptor} The class \emph{EnumDescriptor} is an R wrapper @@ -701,7 +674,8 @@ \begin{table}[h] \centering -\begin{tabular}{|cp{10cm}|} +\begin{small} +\begin{tabular}{l|p{10cm}} \hline \textbf{Slot} & \textbf{Description} \\ \hline @@ -711,20 +685,10 @@ \hline \texttt{full\_name} & Fully qualified name of the enum \\ \hline -\texttt{type} & Name of the message type where the enum is declared \\ +\texttt{type} & Name of the message type where the enum is declared \\[.3cm] \hline -\end{tabular} -\caption{\label{EnumDescriptor-class-table}Description of slots for the \texttt{EnumDescriptor} S4 class} -\end{table} - -\begin{table}[h] -\centering -\begin{small} -\begin{tabular}{l|l} -\hline \textbf{Method} & \textbf{Description} \\ \hline -\hline \texttt{as.list} & return a named integer vector with the values of the enum and their names.\\ \texttt{as.character} & character representation of a descriptor\\ @@ -741,10 +705,10 @@ \hline \end{tabular} \end{small} -\caption{\label{enumdescriptor-methods-table}Description of methods for the \texttt{EnumDescriptor} S4 class} +\caption{\label{enumdescriptor-methods-table}Description of slots and methods for the \texttt{EnumDescriptor} S4 class} \end{table} -\subsection{file descriptors} +\subsection{File Descriptors} \label{subsec-file-descriptor} The class \emph{FileDescriptor} is an R wrapper @@ -763,7 +727,8 @@ \begin{table}[h] \centering -\begin{tabular}{|cp{10cm}|} +\begin{small} +\begin{tabular}{l|p{10cm}} \hline \textbf{slot} & \textbf{description} \\ \hline @@ -773,20 +738,10 @@ \hline \texttt{filename} & fully qualified pathname of the \texttt{.proto} file.\\ \hline -\texttt{package} & package name defined in this \texttt{.proto} file.\\ +\texttt{package} & package name defined in this \texttt{.proto} file.\\[.3cm] \hline -\end{tabular} -\caption{\label{FileDescriptor-class-table}Description of slots for the \texttt{FileDescriptor} S4 class} -\end{table} - -\begin{table}[h] -\centering -\begin{small} -\begin{tabular}{l|l} -\hline \textbf{Method} & \textbf{Description} \\ \hline -\hline \texttt{name} & Return the filename for this FileDescriptorProto.\\ \texttt{package} & Return the file-level package name specified in this FileDescriptorProto.\\ \texttt{as.character} & character representation of a descriptor. \\ @@ -796,10 +751,10 @@ \hline \end{tabular} \end{small} -\caption{\label{filedescriptor-methods-table}Description of methods for the \texttt{FileDescriptor} S4 class} +\caption{\label{filedescriptor-methods-table}Description of slots and methods for the \texttt{FileDescriptor} S4 class} \end{table} -\subsection{enum value descriptors} +\subsection{Enum Value Descriptors} \label{subsec-enumvalue-descriptor} The class \emph{EnumValueDescriptor} is an R wrapper @@ -817,7 +772,8 @@ \begin{table}[h] \centering -\begin{tabular}{|cp{10cm}|} +\begin{small} +\begin{tabular}{l|p{10cm}} \hline \textbf{slot} & \textbf{description} \\ \hline @@ -825,20 +781,10 @@ \hline \texttt{name} & simple name of the enum value \\ \hline -\texttt{full\_name} & fully qualified name of the enum value \\ +\texttt{full\_name} & fully qualified name of the enum value \\[.3cm] \hline -\end{tabular} -\caption{\label{EnumValueDescriptor-class-table}Description of slots for the \texttt{EnumValueDescriptor} S4 class} -\end{table} - -\begin{table}[h] -\centering -\begin{small} -\begin{tabular}{l|l} -\hline \textbf{Method} & \textbf{Description} \\ \hline -\hline \texttt{number} & return the number of this EnumValueDescriptor. \\ \texttt{name} & Return the name of the enum value descriptor.\\ \texttt{enum\_type} & return the EnumDescriptor type of this EnumValueDescriptor. \\ @@ -848,15 +794,93 @@ \hline \end{tabular} \end{small} -\caption{\label{enumvaluedescriptor-methods-table}Description of methods for the \texttt{EnumValueDescriptor} S4 class} +\caption{\label{EnumValueDescriptor-methods-table}Description of slots + and methods for the \texttt{EnumValueDescriptor} S4 class} \end{table} \section{Type Coercion} +One of the benefits of using an Interface Definition Language (IDL) +like Protocol Buffers is that it provides a highly portable basic type +system that different language and hardware implementations can map to +the most appropriate type in different environments. +Table~\ref{table-get-types} details the correspondance between the +field type and the type of data that is retrieved by \verb|$| and \verb|[[| +extractors. + +\begin{table}[h] +\centering +\begin{small} +\begin{tabular}{|c|p{5cm}p{5cm}|} +\hline +field type & R type (non repeated) & R type (repeated) \\ +\hline +\hline +double & \texttt{double} vector & \texttt{double} vector \\ +float & \texttt{double} vector & \texttt{double} vector \\ +\hline +int32 & \texttt{integer} vector & \texttt{integer} vector \\ +uint32 & \texttt{integer} vector & \texttt{integer} vector \\ +sint32 & \texttt{integer} vector & \texttt{integer} vector \\ +fixed32 & \texttt{integer} vector & \texttt{integer} vector \\ +sfixed32 & \texttt{integer} vector & \texttt{integer} vector \\ +\hline +int64 & \texttt{integer} or \texttt{character} +vector \footnotemark & \texttt{integer} or \texttt{character} vector \\ +uint64 & \texttt{integer} or \texttt{character} vector & \texttt{integer} or \texttt{character} vector \\ +sint64 & \texttt{integer} or \texttt{character} vector & \texttt{integer} or \texttt{character} vector \\ +fixed64 & \texttt{integer} or \texttt{character} vector & \texttt{integer} or \texttt{character} vector \\ +sfixed64 & \texttt{integer} or \texttt{character} vector & \texttt{integer} or \texttt{character} vector \\ +\hline +bool & \texttt{logical} vector & \texttt{logical} vector \\ +\hline +string & \texttt{character} vector & \texttt{character} vector \\ +bytes & \texttt{character} vector & \texttt{character} vector \\ +\hline +enum & \texttt{integer} vector & \texttt{integer} vector \\ +\hline +message & \texttt{S4} object of class \texttt{Message} & \texttt{list} of \texttt{S4} objects of class \texttt{Message} \\ +\hline +\end{tabular} +\end{small} +\caption{\label{table-get-types}Correspondance between field type and + R type retrieved by the extractors. \footnotesize{1. R lacks native + 64-bit integers, so the \texttt{RProtoBuf.int64AsString} option is + available to return large integers as characters to avoid losing + precision. This option is described in Section~\ref{sec:int64}}.} +\end{table} + \subsection{Booleans} -Bools -Int64s. +R booleans can accept three values: \texttt{TRUE}, \texttt{FALSE}, and +\texttt{NA}. However, most other languages, including the protocol +buffer schema, only accept \text{TRUE} or \text{FALSE}. This means +that we simply can not store R logical vectors that include all three +possible values as booleans. The library will refuse to store +\texttt{NA}s in protocol buffer boolean fields, and users must instead +choose another type (such as integers) capable of storing three +distinct values. + +<>= + if (!exists("protobuf_unittest.TestAllTypes", + "RProtoBuf:DescriptorPool")) { + unittest.proto.file <- system.file("unitTests", "data", + "unittest.proto", + package="RProtoBuf") + readProtoFiles(file=unittest.proto.file) + } +@ + +<<>>= +a <- new(protobuf_unittest.TestAllTypes) +a$optional_bool <- TRUE +a$optional_bool <- FALSE +<>= +a$optional_bool <- NA +<>= +try(a$optional_bool <- NA,silent=TRUE) +@ + \subsection{64-bit integers} \label{sec:int64} @@ -869,7 +893,7 @@ @ Protocol Buffers are frequently used to pass data between different -systems, however, and most other systems these days have support for +systems, however, and most other modern systems do have support for 64-bit integers. To work around this, RProtoBuf allows users to get and set 64-bit integer types by treating them as characters. @@ -919,11 +943,161 @@ @ -\section{Related work on IDLs (greatly expanded from what you have)} +\section{Evaluation: data.frame to Protocol Buffer Serialization} -\section{Design tradeoffs: reflection vs proto compiler (not addressed - at all in current vignettes)} +Saptarshi Guha wrote the RHIPE package \citep{rhipe} which includes +protocol buffer integration with R. However, this implementation +takes a different approach: any R object is serialized into a message +based on a single catch-all \texttt{proto} schema. Jeroen Ooms took a +similar approach influenced by Saptarshi in his \pkg{RProtoBufUtils} +package. Unlike Saptarshi's package, however, RProtoBufUtils depends +on RProtoBuf for underlying message operations. This package is +available at \url{https://github.com/jeroenooms/RProtoBufUtils}. +The \textbf{RProtoBufUtils} package by Jereoen Ooms provides a +\texttt{serialize\_pb} method to convert R objects into serialized +protocol buffers in this format, and the \texttt{can\_serialize\_pb} +method can be used to determine whether the given R object can safely +be expressed in this way. To show how how this method works, we +attempt to convert all of the built-in datasets from R into this +serialized protocol buffer representation. + +<>= +library(RProtoBufUtils) + +datasets <- subset(as.data.frame(data()$results), Package=="datasets") +datasets$load.name <- sub("\\s+.*$", "", datasets$Item) +n <- nrow(datasets) +@ + +There are \Sexpr{n} standard data sets included in R. We use the +\texttt{can\_serialize\_pb} method to determine how many of those can +be safely converted to a serialized protocol buffer representation. + +<>= +datasets$valid.proto <- sapply(datasets$load.name, function(x) can_serialize_pb(eval(as.name(x)))) +datasets <- subset(datasets, valid.proto==TRUE) +m <- nrow(datasets) +@ + +\Sexpr{m} data sets could be converted to Protocol Buffers +(\Sexpr{format(100*m/n,digits=1)}\%). The next section illustrates how +many bytes were usued to store the data sets under four different +situations (1) normal R serialization, (2) R serialization followed by +gzip, (3) normal protocol buffer serialization, (4) protocol buffer +serialization followed by gzip. + +\subsection{Compression Performance} +\label{sec:compression} + +<>= +datasets$object.size <- unname(sapply(datasets$load.name, function(x) object.size(eval(as.name(x))))) + +datasets$R.serialize.size <- unname(sapply(datasets$load.name, function(x) length(serialize(eval(as.name(x)), NULL)))) + +datasets$R.serialize.size <- unname(sapply(datasets$load.name, function(x) length(serialize(eval(as.name(x)), NULL)))) + +datasets$R.serialize.size.gz <- unname(sapply(datasets$load.name, function(x) length(memCompress(serialize(eval(as.name(x)), NULL), "gzip")))) + +datasets$RProtoBuf.serialize.size <- unname(sapply(datasets$load.name, function(x) length(serialize_pb(eval(as.name(x)), NULL)))) + +datasets$RProtoBuf.serialize.size.gz <- unname(sapply(datasets$load.name, function(x) length(memCompress(serialize_pb(eval(as.name(x)), NULL), "gzip")))) + +clean.df <- data.frame(dataset=datasets$load.name, + object.size=datasets$object.size, + "serialized"=datasets$R.serialize.size, + "gzipped serialized"=datasets$R.serialize.size.gz, + "RProtoBuf"=datasets$RProtoBuf.serialize.size, + "gzipped RProtoBuf"=datasets$RProtoBuf.serialize.size.gz, + check.names=FALSE) +@ + +Table~\ref{tab:compression} shows the sizes of 50 sample R datasets as +returned by object.size() compared to the serialized sizes. +The summary compression sizes are listed below, and a full table for a +sample of 50 datasets is included on the next page. Sizes are comparable +but protocol buffers provide simple getters and setters in multiple +languages instead of requiring other programs to parse the R +serialization format \citep{serialization}. One takeaway from this +table is that RProtoBuf does not in general provide any significant +space-savings over R's normal serialization mechanism. The benefit +from RProtoBuf comes from its interoperability with other +environments. + +TODO comparison of protobuf serialization sizes/times for various vectors. Compared to R's native serialization. Discussion of the RHIPE approach of serializing any/all R objects, vs more specific protocol buffers for specific R objects. + +% N.B. see table.Rnw for how this table is created. +% +% latex table generated in R 3.0.2 by xtable 1.7-0 package +% Fri Dec 27 17:00:03 2013 +\begin{table}[ht] +\begin{center} +\scalebox{0.9}{ +\begin{tabular}{l|r|r|r|r|r} + \hline +Data Set & object.size & \multicolumn{2}{c|}{R Serialization} & +\multicolumn{2}{c}{RProtoBuf Serialization} \\ + & & Default & gzipped & Default & gzipped \\ + \hline +uspop & 584.00 & 268 & 172 & 211 & 148 \\ + Titanic & 1960.00 & 633 & 257 & 481 & 249 \\ + volcano & 42656.00 & 42517 & 5226 & 42476 & 4232 \\ + euro.cross & 2728.00 & 1319 & 910 & 1207 & 891 \\ + attenu & 14568.00 & 8234 & 2165 & 7771 & 2336 \\ + ToothGrowth & 2568.00 & 1486 & 349 & 1239 & 391 \\ + lynx & 1344.00 & 1028 & 429 & 971 & 404 \\ + nottem & 2352.00 & 2036 & 627 & 1979 & 641 \\ + sleep & 2752.00 & 746 & 282 & 483 & 260 \\ + co2 & 4176.00 & 3860 & 1473 & 3803 & 1453 \\ + austres & 1144.00 & 828 & 439 & 771 & 410 \\ + ability.cov & 1944.00 & 716 & 357 & 589 & 341 \\ + EuStockMarkets & 60664.00 & 59785 & 21232 & 59674 & 19882 \\ + treering & 64272.00 & 63956 & 17647 & 63900 & 17758 \\ + freeny.x & 1944.00 & 1445 & 1311 & 1372 & 1289 \\ + Puromycin & 2088.00 & 813 & 306 & 620 & 320 \\ + warpbreaks & 2768.00 & 1231 & 310 & 811 & 343 \\ + BOD & 1088.00 & 334 & 182 & 226 & 168 \\ + sunspots & 22992.00 & 22676 & 6482 & 22620 & 6742 \\ + beaver2 & 4184.00 & 3423 & 751 & 3468 & 840 \\ + anscombe & 2424.00 & 991 & 375 & 884 & 352 \\ + esoph & 5624.00 & 3111 & 548 & 2240 & 665 \\ + PlantGrowth & 1680.00 & 646 & 303 & 459 & 314 \\ + infert & 15848.00 & 14328 & 1172 & 13197 & 1404 \\ + BJsales & 1632.00 & 1316 & 496 & 1259 & 465 \\ + stackloss & 1688.00 & 917 & 293 & 844 & 283 \\ + crimtab & 7936.00 & 4641 & 713 & 1655 & 576 \\ + LifeCycleSavings & 6048.00 & 3014 & 1420 & 2825 & 1407 \\ + Harman74.cor & 9144.00 & 6056 & 2045 & 5861 & 2070 \\ + nhtemp & 912.00 & 596 & 240 & 539 & 223 \\ + faithful & 5136.00 & 4543 & 1339 & 4936 & 1776 \\ + freeny & 5296.00 & 2465 & 1518 & 2271 & 1507 \\ + discoveries & 1232.00 & 916 & 199 & 859 & 180 \\ + state.x77 & 7168.00 & 4251 & 1754 & 4068 & 1756 \\ + pressure & 1096.00 & 498 & 277 & 427 & 273 \\ + fdeaths & 1008.00 & 692 & 291 & 635 & 272 \\ + euro & 976.00 & 264 & 186 & 202 & 161 \\ + LakeHuron & 1216.00 & 900 & 420 & 843 & 404 \\ + mtcars & 6736.00 & 3798 & 1204 & 3633 & 1206 \\ + precip & 4992.00 & 1793 & 813 & 1615 & 815 \\ + state.area & 440.00 & 422 & 246 & 405 & 235 \\ + attitude & 3024.00 & 1990 & 544 & 1920 & 561 \\ + randu & 10496.00 & 9794 & 8859 & 10441 & 9558 \\ + state.name & 3088.00 & 844 & 408 & 724 & 415 \\ + airquality & 5496.00 & 4551 & 1241 & 2874 & 1294 \\ + airmiles & 624.00 & 308 & 170 & 251 & 148 \\ + quakes & 33112.00 & 32246 & 9898 & 29063 & 11595 \\ + islands & 3496.00 & 1232 & 563 & 1098 & 561 \\ + OrchardSprays & 3600.00 & 2164 & 445 & 1897 & 483 \\ + WWWusage & 1232.00 & 916 & 274 & 859 & 251 \\ + \hline +\end{tabular} +} +\caption{Serialization sizes with R's built-in serialization and + RProtoBuf for 50 sample R datasets.} +\label{tab:compression} +\end{center} +\end{table} + \subsection{Performance considerations} TODO RProtoBuf is quite flexible and easy to use for interactive @@ -936,11 +1110,7 @@ about this to clarify the goals and strengths of RProtoBuf and its reflection and object mapping. -\subsection{Serialization comparison} -TODO comparison of protobuf serialization sizes/times for various vectors. Compared to R's native serialization. Discussion of the RHIPE approach of serializing any/all R objects, vs more specific protocol buffers for specific R objects. - - \section{Descriptor lookup} \label{sec-lookup} @@ -958,34 +1128,58 @@ implemented by the \texttt{RProtoBuf} package by calling an internal method of the \texttt{protobuf} C++ library. -\section{Other approaches} +%\section{Other approaches} -Saptarshi Guha wrote another package that deals with integration -of protocol buffer messages with R, taking a different angle : -serializing any R object as a message, based on a single catch-all -\texttt{proto} file. Saptarshi's package is available at -\url{http://ml.stat.purdue.edu/rhipe/doc/html/ProtoBuffers.html}. - -Jeroen Ooms took a similar approach influenced by Saptarshi in his -\pkg{RProtoBufUtils} package. Unlike Saptarshi's package, -RProtoBufUtils depends on RProtoBuf for underlying message operations. -This package is available at -\url{https://github.com/jeroenooms/RProtoBufUtils}. - % Phillip Yelland wrote another implementation, currently proprietary, % that has significant speed advantages when querying fields from a % large number of protocol buffers, but is less user friendly for the % basic cases documented here. -\section{Basic usage example - tutorial.Person} +%\section{Basic usage example - tutorial.Person} -\section{Application: distributed Data Collection with MapReduce} +\section{Application: Distributed Data Collection with MapReduce} -We could describe a common MapReduce pattern of having the MR written -in another language output protocol buffers that are later pulled into -R. There is some text about this in section 2 of -http://cran.r-project.org/web/packages/HistogramTools/vignettes/HistogramTools.pdf +TODO(mstokely): Make this better. +Many large data sets in fields such as particle physics and +information processing are stored in binned or histogram form in order +to reduce the data storage requirements +\citep{scott2009multivariate}. Protocol Buffers make a particularly +good data transport format in distributed MapReduces environments +where large numbers of computers process a large data set for analysis. + +There are two common patterns for generating histograms of large data +sets with MapReduce. In the first method, each mapper task can +generate a histogram over a subset of the data that is has been +assigned, and then the histograms of each mapper are sent to one or +more reducer tasks to merge. + +In the second method, each mapper rounds a data point to a bucket +width and outputs that bucket as a key and '1' as a value. Reducers +then sum up all of the values with the same key and output to a data store. + +In both methods, the mapper tasks must choose identical +bucket boundaries even though they are analyzing disjoint parts of the +input set that may cover different ranges, or we must implement +multiple phases. + +\begin{figure}[h!] +\begin{center} +\includegraphics[width=\textwidth]{histogram-mapreduce-diag1.pdf} +\end{center} +\caption{Diagram of MapReduce Histogram Generation Pattern} +\label{fig:mr-histogram-pattern1} +\end{figure} + +Figure~\ref{fig:mr-histogram-pattern1} illustrates the second method +described above for histogram generation of large data sets with +MapReduce. + +This package is designed to be helpful if some of the Map or Reduce +tasks are written in R, or if those components are written in other +languages and only the resulting output histograms need to be +manipulated in R. + \section{Application: Sending/receiving Interaction With Servers} Unlike Apache Thrift, Protocol Buffers do not include a concrete RPC Added: papers/rjournal/histogram-mapreduce-diag1.pdf =================================================================== (Binary files differ) Property changes on: papers/rjournal/histogram-mapreduce-diag1.pdf ___________________________________________________________________ Added: svn:mime-type + application/octet-stream From noreply at r-forge.r-project.org Sat Dec 28 05:45:52 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 05:45:52 +0100 (CET) Subject: [Rprotobuf-commits] r625 - pkg/R Message-ID: <20131228044553.0631A186247@r-forge.r-project.org> Author: murray Date: 2013-12-28 05:45:51 +0100 (Sat, 28 Dec 2013) New Revision: 625 Modified: pkg/R/merge.R Log: Replace last call to throw with stop() since we deleted throw() earlier today. Modified: pkg/R/merge.R =================================================================== --- pkg/R/merge.R 2013-12-28 01:43:57 UTC (rev 624) +++ pkg/R/merge.R 2013-12-28 04:45:51 UTC (rev 625) @@ -3,9 +3,7 @@ c( x = "Message", y = "Message" ), function( x, y , ... ){ if( !identical( x at type, y at type ) ){ - throw( - sprintf( "incompatible message types, cannot merge '%s' and '%s'", x at type, y at type ), - "IncompatibleType" ) + stop(sprintf("incompatible message types, cannot merge '%s' and '%s'", x at type, y at type)) } message <- .Call( "Message__merge", x at pointer, y at pointer ) From noreply at r-forge.r-project.org Sat Dec 28 20:08:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Sat, 28 Dec 2013 20:08:35 +0100 (CET) Subject: [Rprotobuf-commits] r626 - in pkg: . src Message-ID: <20131228190836.1D618186D4E@r-forge.r-project.org> Author: murray Date: 2013-12-28 20:08:34 +0100 (Sat, 28 Dec 2013) New Revision: 626 Modified: pkg/ChangeLog pkg/src/extractors.cpp Log: Handle large uint32s properly by casting to double before calling Rcpp::wrap since wrap is broken for uint32s still. With this change, we correctly get a large uint32 instead of -1 : foo$large_uint32 [1] 4294967295 Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-28 04:45:51 UTC (rev 625) +++ pkg/ChangeLog 2013-12-28 19:08:34 UTC (rev 626) @@ -1,3 +1,11 @@ +2013-12-28 Murray Stokely + + * src/extractors.cpp (rprotobuf): Correct handling of uint32 for + single values greater than 2^31 by returning as R numeric types + to avoid losing precision since R doesn't have unsigned int + types but C++ does. Works around an Rcpp bug + https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 + 2013-12-27 Murray Stokely * src/mutators.cpp: Refactor setMessageField into four separate Modified: pkg/src/extractors.cpp =================================================================== --- pkg/src/extractors.cpp 2013-12-28 04:45:51 UTC (rev 625) +++ pkg/src/extractors.cpp 2013-12-28 19:08:34 UTC (rev 626) @@ -97,6 +97,8 @@ return Rcpp::wrap( RepeatedFieldImporter(ref, *message, fieldDesc) ) ; \ HANDLE_REPEATED_FIELD(CPPTYPE_INT32, GPB::int32) ; + // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 + // See https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 HANDLE_REPEATED_FIELD(CPPTYPE_UINT32, GPB::uint32) ; HANDLE_REPEATED_FIELD(CPPTYPE_DOUBLE, double) ; HANDLE_REPEATED_FIELD(CPPTYPE_FLOAT, float) ; @@ -155,10 +157,13 @@ return Rcpp::wrap( ref->Get##SUFFIX(*message, fieldDesc ) ) ; HANDLE_SINGLE_FIELD( CPPTYPE_INT32, Int32 ); - HANDLE_SINGLE_FIELD( CPPTYPE_UINT32, UInt32 ); HANDLE_SINGLE_FIELD( CPPTYPE_DOUBLE, Double ); HANDLE_SINGLE_FIELD( CPPTYPE_FLOAT, Float ); HANDLE_SINGLE_FIELD( CPPTYPE_BOOL, Bool ); + // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 + // See https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 + case CPPTYPE_UINT32: + return Rcpp::wrap( double(ref->GetUInt32(*message, fieldDesc))); #ifdef RCPP_HAS_LONG_LONG_TYPES // Handle these types separately since Rcpp::wrap doesn't // do the right thing. From noreply at r-forge.r-project.org Mon Dec 30 00:17:39 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 00:17:39 +0100 (CET) Subject: [Rprotobuf-commits] r627 - papers/rjournal Message-ID: <20131229231739.8EEC4184C34@r-forge.r-project.org> Author: edd Date: 2013-12-30 00:17:34 +0100 (Mon, 30 Dec 2013) New Revision: 627 Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw Log: some edits for typos etc Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-28 19:08:34 UTC (rev 626) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-29 23:17:34 UTC (rev 627) @@ -11,6 +11,11 @@ \title{RProtoBuf: Efficient Cross-Language Data Serialization in R} \author{by Dirk Eddelbuettel, Romain Fran\c{c}ois, and Murray Stokely} +%% DE: I tend to have wider option(width=...) so this +%% guarantees better line breaks +<>= +options(width=65, prompt="R> ", digits=4) +@ \maketitle @@ -34,11 +39,11 @@ isolation \citep{Wegiel:2010:CTT:1932682.1869479}. Different programming languages are often used for the different phases of data analysis -- collection, cleaning, analysis, post-processing, and -presentation in order to take advantage of the unique combination of +presentation in order to take advantage of the unique combination of performance, speed of development, and library support offered by different environments. Each stage of the data analysis pipeline may involve storing intermediate results in a -file or sending them over the network. Programming langauges such as +file or sending them over the network. Programming languages such as Java, Ruby, Python, and R include built-in serialization support, but these formats are tied to the specific programming language in use. % TODO(ms): and they often don't support versioning among other faults. @@ -46,8 +51,8 @@ often used for exporting tabular data. However, CSV files have a number of disadvantages, such as a limitation of exporting only tabular datasets, lack of type-safety, inefficient text representation -and parsing, and abiguities in the format involving special -characters. JSON is another widely supported format used mostly on +and parsing, and ambiguities in the format involving special +characters. JSON is another widely-supported format used mostly on the web that removes many of these disadvantages, but it too suffers from being too slow to parse and also does not provide strong typing between integers and floating point. Large numbers of JSON messages @@ -95,6 +100,8 @@ Introductory section which may include references in parentheses \citep{R}, or cite a reference such as \citet{R} in the text. +%% TODO(de,ms) What follows is oooooold and was lifted from the webpage +%% Rewrite? Protocol buffers are a language-neutral, platform-neutral, extensible way of serializing structured data for use in communications protocols, data storage, and more. @@ -161,6 +168,7 @@ %from a variety of data streams using a variety of different %languages. The definition +%% TODO(de) Can we make this not break the width of the page? \noindent \begin{table} \begin{tabular}{@{\hskip .01\textwidth}p{.40\textwidth}@{\hskip .015\textwidth}|@{\hskip .015\textwidth}p{0.55\textwidth}@{\hskip .01\textwidth}} @@ -196,7 +204,7 @@ person$name <- "Romain" cat(as.character(person)) serialize(person, NULL) -@ +@ \end{minipage} \\ \hline \end{tabular} @@ -228,7 +236,7 @@ New \texttt{.proto} files are imported with the \code{readProtoFiles} function, which can import a single file, all files in a directory, or -all \texttt{.proto} files provided by another R package. +all \texttt{.proto} files provided by another R package. The \texttt{.proto} file syntax for defining the structure of protocol buffer data is described comprehensively on Google Code: @@ -424,7 +432,7 @@ Each R object stores an external pointer to an object managed by the \texttt{protobuf} C++ library. -The \CRANpkg{Rcpp} \citep{eddelbuettel2011rcpp} package is used to +The \CRANpkg{Rcpp} package \citep{eddelbuettel2011rcpp} is used to facilitate the integration of the R and C++ code for these objects. % Message, Descriptor, FieldDescriptor, EnumDescriptor, @@ -768,7 +776,7 @@ tutorial.Person$PhoneType$value(1) tutorial.Person$PhoneType$value(name="HOME") tutorial.Person$PhoneType$value(number=1) -@ +@ \begin{table}[h] \centering @@ -879,7 +887,7 @@ a$optional_bool <- NA <>= try(a$optional_bool <- NA,silent=TRUE) -@ +@ \subsection{64-bit integers} \label{sec:int64} @@ -940,7 +948,7 @@ <>= options("RProtoBuf.int64AsString" = FALSE) -@ +@ \section{Evaluation: data.frame to Protocol Buffer Serialization} @@ -975,8 +983,8 @@ be safely converted to a serialized protocol buffer representation. <>= -datasets$valid.proto <- sapply(datasets$load.name, function(x) can_serialize_pb(eval(as.name(x)))) -datasets <- subset(datasets, valid.proto==TRUE) +#datasets$valid.proto <- sapply(datasets$load.name, function(x) can_serialize_pb(eval(as.name(x)))) +#datasets <- subset(datasets, valid.proto==TRUE) m <- nrow(datasets) @ @@ -1039,56 +1047,56 @@ \multicolumn{2}{c}{RProtoBuf Serialization} \\ & & Default & gzipped & Default & gzipped \\ \hline -uspop & 584.00 & 268 & 172 & 211 & 148 \\ - Titanic & 1960.00 & 633 & 257 & 481 & 249 \\ - volcano & 42656.00 & 42517 & 5226 & 42476 & 4232 \\ - euro.cross & 2728.00 & 1319 & 910 & 1207 & 891 \\ - attenu & 14568.00 & 8234 & 2165 & 7771 & 2336 \\ - ToothGrowth & 2568.00 & 1486 & 349 & 1239 & 391 \\ - lynx & 1344.00 & 1028 & 429 & 971 & 404 \\ - nottem & 2352.00 & 2036 & 627 & 1979 & 641 \\ - sleep & 2752.00 & 746 & 282 & 483 & 260 \\ - co2 & 4176.00 & 3860 & 1473 & 3803 & 1453 \\ - austres & 1144.00 & 828 & 439 & 771 & 410 \\ - ability.cov & 1944.00 & 716 & 357 & 589 & 341 \\ - EuStockMarkets & 60664.00 & 59785 & 21232 & 59674 & 19882 \\ - treering & 64272.00 & 63956 & 17647 & 63900 & 17758 \\ - freeny.x & 1944.00 & 1445 & 1311 & 1372 & 1289 \\ - Puromycin & 2088.00 & 813 & 306 & 620 & 320 \\ - warpbreaks & 2768.00 & 1231 & 310 & 811 & 343 \\ - BOD & 1088.00 & 334 & 182 & 226 & 168 \\ - sunspots & 22992.00 & 22676 & 6482 & 22620 & 6742 \\ - beaver2 & 4184.00 & 3423 & 751 & 3468 & 840 \\ - anscombe & 2424.00 & 991 & 375 & 884 & 352 \\ - esoph & 5624.00 & 3111 & 548 & 2240 & 665 \\ - PlantGrowth & 1680.00 & 646 & 303 & 459 & 314 \\ - infert & 15848.00 & 14328 & 1172 & 13197 & 1404 \\ - BJsales & 1632.00 & 1316 & 496 & 1259 & 465 \\ - stackloss & 1688.00 & 917 & 293 & 844 & 283 \\ - crimtab & 7936.00 & 4641 & 713 & 1655 & 576 \\ - LifeCycleSavings & 6048.00 & 3014 & 1420 & 2825 & 1407 \\ - Harman74.cor & 9144.00 & 6056 & 2045 & 5861 & 2070 \\ - nhtemp & 912.00 & 596 & 240 & 539 & 223 \\ - faithful & 5136.00 & 4543 & 1339 & 4936 & 1776 \\ - freeny & 5296.00 & 2465 & 1518 & 2271 & 1507 \\ - discoveries & 1232.00 & 916 & 199 & 859 & 180 \\ - state.x77 & 7168.00 & 4251 & 1754 & 4068 & 1756 \\ - pressure & 1096.00 & 498 & 277 & 427 & 273 \\ - fdeaths & 1008.00 & 692 & 291 & 635 & 272 \\ - euro & 976.00 & 264 & 186 & 202 & 161 \\ - LakeHuron & 1216.00 & 900 & 420 & 843 & 404 \\ - mtcars & 6736.00 & 3798 & 1204 & 3633 & 1206 \\ - precip & 4992.00 & 1793 & 813 & 1615 & 815 \\ - state.area & 440.00 & 422 & 246 & 405 & 235 \\ - attitude & 3024.00 & 1990 & 544 & 1920 & 561 \\ - randu & 10496.00 & 9794 & 8859 & 10441 & 9558 \\ - state.name & 3088.00 & 844 & 408 & 724 & 415 \\ - airquality & 5496.00 & 4551 & 1241 & 2874 & 1294 \\ - airmiles & 624.00 & 308 & 170 & 251 & 148 \\ - quakes & 33112.00 & 32246 & 9898 & 29063 & 11595 \\ - islands & 3496.00 & 1232 & 563 & 1098 & 561 \\ - OrchardSprays & 3600.00 & 2164 & 445 & 1897 & 483 \\ - WWWusage & 1232.00 & 916 & 274 & 859 & 251 \\ +uspop & 584.00 & 268 & 172 & 211 & 148 \\ + Titanic & 1960.00 & 633 & 257 & 481 & 249 \\ + volcano & 42656.00 & 42517 & 5226 & 42476 & 4232 \\ + euro.cross & 2728.00 & 1319 & 910 & 1207 & 891 \\ + attenu & 14568.00 & 8234 & 2165 & 7771 & 2336 \\ + ToothGrowth & 2568.00 & 1486 & 349 & 1239 & 391 \\ + lynx & 1344.00 & 1028 & 429 & 971 & 404 \\ + nottem & 2352.00 & 2036 & 627 & 1979 & 641 \\ + sleep & 2752.00 & 746 & 282 & 483 & 260 \\ + co2 & 4176.00 & 3860 & 1473 & 3803 & 1453 \\ + austres & 1144.00 & 828 & 439 & 771 & 410 \\ + ability.cov & 1944.00 & 716 & 357 & 589 & 341 \\ + EuStockMarkets & 60664.00 & 59785 & 21232 & 59674 & 19882 \\ + treering & 64272.00 & 63956 & 17647 & 63900 & 17758 \\ + freeny.x & 1944.00 & 1445 & 1311 & 1372 & 1289 \\ + Puromycin & 2088.00 & 813 & 306 & 620 & 320 \\ + warpbreaks & 2768.00 & 1231 & 310 & 811 & 343 \\ + BOD & 1088.00 & 334 & 182 & 226 & 168 \\ + sunspots & 22992.00 & 22676 & 6482 & 22620 & 6742 \\ + beaver2 & 4184.00 & 3423 & 751 & 3468 & 840 \\ + anscombe & 2424.00 & 991 & 375 & 884 & 352 \\ + esoph & 5624.00 & 3111 & 548 & 2240 & 665 \\ + PlantGrowth & 1680.00 & 646 & 303 & 459 & 314 \\ + infert & 15848.00 & 14328 & 1172 & 13197 & 1404 \\ + BJsales & 1632.00 & 1316 & 496 & 1259 & 465 \\ + stackloss & 1688.00 & 917 & 293 & 844 & 283 \\ + crimtab & 7936.00 & 4641 & 713 & 1655 & 576 \\ + LifeCycleSavings & 6048.00 & 3014 & 1420 & 2825 & 1407 \\ + Harman74.cor & 9144.00 & 6056 & 2045 & 5861 & 2070 \\ + nhtemp & 912.00 & 596 & 240 & 539 & 223 \\ + faithful & 5136.00 & 4543 & 1339 & 4936 & 1776 \\ + freeny & 5296.00 & 2465 & 1518 & 2271 & 1507 \\ + discoveries & 1232.00 & 916 & 199 & 859 & 180 \\ + state.x77 & 7168.00 & 4251 & 1754 & 4068 & 1756 \\ + pressure & 1096.00 & 498 & 277 & 427 & 273 \\ + fdeaths & 1008.00 & 692 & 291 & 635 & 272 \\ + euro & 976.00 & 264 & 186 & 202 & 161 \\ + LakeHuron & 1216.00 & 900 & 420 & 843 & 404 \\ + mtcars & 6736.00 & 3798 & 1204 & 3633 & 1206 \\ + precip & 4992.00 & 1793 & 813 & 1615 & 815 \\ + state.area & 440.00 & 422 & 246 & 405 & 235 \\ + attitude & 3024.00 & 1990 & 544 & 1920 & 561 \\ + randu & 10496.00 & 9794 & 8859 & 10441 & 9558 \\ + state.name & 3088.00 & 844 & 408 & 724 & 415 \\ + airquality & 5496.00 & 4551 & 1241 & 2874 & 1294 \\ + airmiles & 624.00 & 308 & 170 & 251 & 148 \\ + quakes & 33112.00 & 32246 & 9898 & 29063 & 11595 \\ + islands & 3496.00 & 1232 & 563 & 1098 & 561 \\ + OrchardSprays & 3600.00 & 2164 & 445 & 1897 & 483 \\ + WWWusage & 1232.00 & 916 & 274 & 859 & 251 \\ \hline \end{tabular} } From noreply at r-forge.r-project.org Mon Dec 30 18:20:59 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 18:20:59 +0100 (CET) Subject: [Rprotobuf-commits] r628 - pkg/src Message-ID: <20131230172059.8E0B418692D@r-forge.r-project.org> Author: murray Date: 2013-12-30 18:20:59 +0100 (Mon, 30 Dec 2013) New Revision: 628 Modified: pkg/src/mutators.cpp Log: Correct a few more parts of the code path that coerced uint32s to int32 and thus truncated precision. Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-29 23:17:34 UTC (rev 627) +++ pkg/src/mutators.cpp 2013-12-30 17:20:59 UTC (rev 628) @@ -592,7 +592,9 @@ Int32FromString(uint32str)); break ; } else { - ref->SetUInt32( message, field_desc, Rcpp::as(value)); + // Rcpp::as is broken for uint32 types, so we just get Rcpp + // to give us a valid double, + ref->SetUInt32( message, field_desc, Rcpp::as(value)); break; } } @@ -855,14 +857,14 @@ /* in any case, fill the values up to field_size */ for( ; iSetRepeatedUInt32( message, field_desc, i, - GET_int32(value,i) ) ; + GET_uint32(value,i) ) ; } /* then add some if needed */ if( value_size > field_size ){ for( ; iAddUInt32( message, field_desc, - GET_int32(value,i) ) ; + GET_uint32(value,i) ) ; } } break ; From noreply at r-forge.r-project.org Mon Dec 30 18:51:28 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 18:51:28 +0100 (CET) Subject: [Rprotobuf-commits] r629 - in pkg: . inst/unitTests src Message-ID: <20131230175128.70AC41869D9@r-forge.r-project.org> Author: murray Date: 2013-12-30 18:51:28 +0100 (Mon, 30 Dec 2013) New Revision: 629 Added: pkg/inst/unitTests/runit.extremevalues.R Modified: pkg/ChangeLog pkg/src/Rcppsupport.h pkg/src/extractors.cpp Log: Finish correcting our uint handling and add a unit test verifying we can store 2^32 -1 properly in repeated or optional uint32 protobuf fields. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-30 17:20:59 UTC (rev 628) +++ pkg/ChangeLog 2013-12-30 17:51:28 UTC (rev 629) @@ -1,3 +1,11 @@ +2013-12-30 Murray Stokely + + * inst/unitTests/runit.extremevalues.R (test.uint32): Add test + verifying that we can store 2^32 - 1 properly in repeated or + optional protobuf fields. + * src/extractors.cpp (rprotobuf): Correct handling of uint32 for + repeated fields. + 2013-12-28 Murray Stokely * src/extractors.cpp (rprotobuf): Correct handling of uint32 for Added: pkg/inst/unitTests/runit.extremevalues.R =================================================================== --- pkg/inst/unitTests/runit.extremevalues.R (rev 0) +++ pkg/inst/unitTests/runit.extremevalues.R 2013-12-30 17:51:28 UTC (rev 629) @@ -0,0 +1,32 @@ +# Copyright 2013 Google Inc. +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + +test.uint32 <- function() { + if (!exists("protobuf_unittest.TestAllTypes", + "RProtoBuf:DescriptorPool")) { + unittest.proto.file <- system.file("unitTests", "data", + "unittest.proto", + package="RProtoBuf") + readProtoFiles(file=unittest.proto.file) + } + + foo <- new(protobuf_unittest.TestAllTypes) + foo$optional_uint32 <- 2^32 - 1 + foo$repeated_uint32 <- c(foo$optional_uint32, foo$optional_uint32) + checkEquals(as.character(foo$optional_uint32), + "4294967295") + checkEquals(foo$optional_uint32, + foo$repeated_uint32[[1]]) Modified: pkg/src/Rcppsupport.h =================================================================== --- pkg/src/Rcppsupport.h 2013-12-30 17:20:59 UTC (rev 628) +++ pkg/src/Rcppsupport.h 2013-12-30 17:51:28 UTC (rev 629) @@ -78,6 +78,29 @@ const GPB::FieldDescriptor* field ; }; +// TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 +// See https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 +class UInt32RepeatedFieldImporter { +public: + // Represent as doubles, since R doesn't have uint32s. + typedef double r_import_type; + UInt32RepeatedFieldImporter(const GPB::Reflection* ref_ , + const GPB::Message& message_, + const GPB::FieldDescriptor* field_): + ref(ref_), message(message_), field(field_){} + inline int size() const { + return ref->FieldSize( message, field ) ; + } + inline double get(int i) const { + return double(ref->GetRepeatedUInt32(message, field, i)); + } + private: + const GPB::Reflection* ref ; + const GPB::Message& message ; + const GPB::FieldDescriptor* field ; +}; + + template class RepeatedFieldImporter{} ; #undef GENERATE__FIELD__IMPORTER__DECL Modified: pkg/src/extractors.cpp =================================================================== --- pkg/src/extractors.cpp 2013-12-30 17:20:59 UTC (rev 628) +++ pkg/src/extractors.cpp 2013-12-30 17:51:28 UTC (rev 629) @@ -97,14 +97,17 @@ return Rcpp::wrap( RepeatedFieldImporter(ref, *message, fieldDesc) ) ; \ HANDLE_REPEATED_FIELD(CPPTYPE_INT32, GPB::int32) ; - // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 - // See https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 - HANDLE_REPEATED_FIELD(CPPTYPE_UINT32, GPB::uint32) ; HANDLE_REPEATED_FIELD(CPPTYPE_DOUBLE, double) ; HANDLE_REPEATED_FIELD(CPPTYPE_FLOAT, float) ; HANDLE_REPEATED_FIELD(CPPTYPE_BOOL, bool) ; HANDLE_REPEATED_FIELD(CPPTYPE_ENUM, enum_field ) ; HANDLE_REPEATED_FIELD(CPPTYPE_MESSAGE, message_field ) ; + // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 + // See https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 + case CPPTYPE_UINT32: + return Rcpp::wrap( + UInt32RepeatedFieldImporter(ref, *message, + fieldDesc)); #ifdef RCPP_HAS_LONG_LONG_TYPES // We can't handle these the same way, because Rcpp::wrap silently // casts int64s to doubles which may cause us to lose precision. From noreply at r-forge.r-project.org Mon Dec 30 18:53:45 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 18:53:45 +0100 (CET) Subject: [Rprotobuf-commits] r630 - pkg/src Message-ID: <20131230175345.8C1251869E3@r-forge.r-project.org> Author: murray Date: 2013-12-30 18:53:45 +0100 (Mon, 30 Dec 2013) New Revision: 630 Modified: pkg/src/Makevars.in Log: Revert a local change manually providing a link to libprotobuf on my Mac that I did not intend to check in. Modified: pkg/src/Makevars.in =================================================================== --- pkg/src/Makevars.in 2013-12-30 17:51:28 UTC (rev 629) +++ pkg/src/Makevars.in 2013-12-30 17:53:45 UTC (rev 630) @@ -4,5 +4,4 @@ ## both Rcpp (ie libRcpp.so and Rcpp.h) and ## ProtoBuf headers and library via the variables PKG_CPPFLAGS= @PKG_CPPFLAGS@ -PKG_LIBS= /usr/local/lib/libprotobuf.a @PKG_LIBS@ - +PKG_LIBS= @PKG_LIBS@ From noreply at r-forge.r-project.org Mon Dec 30 19:03:14 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 19:03:14 +0100 (CET) Subject: [Rprotobuf-commits] r631 - pkg/vignettes Message-ID: <20131230180314.54ACD186ADB@r-forge.r-project.org> Author: murray Date: 2013-12-30 19:03:13 +0100 (Mon, 30 Dec 2013) New Revision: 631 Modified: pkg/vignettes/RProtoBuf-intro.Rnw Log: Note that uint32 types (uint32, fixed32) are stored as doubles now, not as integers, since R does not have an unsigned integer type. Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-30 17:53:45 UTC (rev 630) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-30 18:03:13 UTC (rev 631) @@ -437,10 +437,11 @@ double & \texttt{double} vector & \texttt{double} vector \\ float & \texttt{double} vector & \texttt{double} vector \\ \hline +uint32 & \texttt{double} vector & \texttt{double} vector \\ +fixed32 & \texttt{double} vector & \texttt{double} vector \\ +\hline int32 & \texttt{integer} vector & \texttt{integer} vector \\ -uint32 & \texttt{integer} vector & \texttt{integer} vector \\ sint32 & \texttt{integer} vector & \texttt{integer} vector \\ -fixed32 & \texttt{integer} vector & \texttt{integer} vector \\ sfixed32 & \texttt{integer} vector & \texttt{integer} vector \\ \hline int64 & \texttt{integer} or \texttt{character} @@ -465,7 +466,8 @@ R type retrieved by the extractors. \footnotesize{1. R lacks native 64-bit integers, so the \texttt{RProtoBuf.int64AsString} option is available to return large integers as characters to avoid losing - precision. This option is described in Section~\ref{sec:int64}}.} + precision. This option is described in Section~\ref{sec:int64}}. R + also lacks an unsigned integer type.} \end{table} \subsubsection{Modify fields} @@ -1966,8 +1968,8 @@ <>= extend.proto <- tempfile() writeLines(c( - paste0('import "', system.file("proto/addressbook.proto", - package="RProtoBuf"), '";'), + paste0('import "', + name(tutorial.Person$fileDescriptor(), TRUE), '";'), "package tutorial;", paste0("extend Person {\n optional string nationality = 100;\n}")), extend.proto) From noreply at r-forge.r-project.org Mon Dec 30 19:21:08 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 19:21:08 +0100 (CET) Subject: [Rprotobuf-commits] r632 - pkg/inst/unitTests Message-ID: <20131230182108.21C101868D5@r-forge.r-project.org> Author: murray Date: 2013-12-30 19:21:07 +0100 (Mon, 30 Dec 2013) New Revision: 632 Modified: pkg/inst/unitTests/runit.extremevalues.R Log: Also test that fixed32 types can handle large unsigned values like 2^32 - 1. Modified: pkg/inst/unitTests/runit.extremevalues.R =================================================================== --- pkg/inst/unitTests/runit.extremevalues.R 2013-12-30 18:03:13 UTC (rev 631) +++ pkg/inst/unitTests/runit.extremevalues.R 2013-12-30 18:21:07 UTC (rev 632) @@ -30,3 +30,12 @@ "4294967295") checkEquals(foo$optional_uint32, foo$repeated_uint32[[1]]) + + # fixed32 are a more efficient representation of uint32 + foo$optional_fixed32 <- 2^32 - 1 + foo$repeated_fixed32 <- c(foo$optional_fixed32, foo$optional_fixed32) + checkEquals(as.character(foo$optional_fixed32), + "4294967295") + checkEquals(foo$optional_fixed32, + foo$repeated_fixed32[[1]]) +} From noreply at r-forge.r-project.org Mon Dec 30 19:22:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 19:22:35 +0100 (CET) Subject: [Rprotobuf-commits] r633 - papers/rjournal Message-ID: <20131230182235.3FCDE1868F8@r-forge.r-project.org> Author: murray Date: 2013-12-30 19:22:34 +0100 (Mon, 30 Dec 2013) New Revision: 633 Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw Log: Update the type table to note that uint32 and fixed32 are stored as doubles, not R integers since R doesn't have unsigned integers. Modified: papers/rjournal/eddelbuettel-francois-stokely.Rnw =================================================================== --- papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-30 18:21:07 UTC (rev 632) +++ papers/rjournal/eddelbuettel-francois-stokely.Rnw 2013-12-30 18:22:34 UTC (rev 633) @@ -827,10 +827,11 @@ double & \texttt{double} vector & \texttt{double} vector \\ float & \texttt{double} vector & \texttt{double} vector \\ \hline +uint32 & \texttt{double} vector & \texttt{double} vector \\ +fixed32 & \texttt{double} vector & \texttt{double} vector \\ +\hline int32 & \texttt{integer} vector & \texttt{integer} vector \\ -uint32 & \texttt{integer} vector & \texttt{integer} vector \\ sint32 & \texttt{integer} vector & \texttt{integer} vector \\ -fixed32 & \texttt{integer} vector & \texttt{integer} vector \\ sfixed32 & \texttt{integer} vector & \texttt{integer} vector \\ \hline int64 & \texttt{integer} or \texttt{character} From noreply at r-forge.r-project.org Mon Dec 30 21:27:29 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 21:27:29 +0100 (CET) Subject: [Rprotobuf-commits] r634 - pkg/src Message-ID: <20131230202729.A259A186966@r-forge.r-project.org> Author: murray Date: 2013-12-30 21:27:29 +0100 (Mon, 30 Dec 2013) New Revision: 634 Modified: pkg/src/ZeroCopyInputStreamWrapper.cpp pkg/src/ZeroCopyOutputStreamWrapper.cpp Log: whitespace change only. clang-format * Don't indent one level for everything inside of a namespace { } * Use 4 character indent consistently. Modified: pkg/src/ZeroCopyInputStreamWrapper.cpp =================================================================== --- pkg/src/ZeroCopyInputStreamWrapper.cpp 2013-12-30 18:22:34 UTC (rev 633) +++ pkg/src/ZeroCopyInputStreamWrapper.cpp 2013-12-30 20:27:29 UTC (rev 634) @@ -1,24 +1,25 @@ #include "rprotobuf.h" -namespace rprotobuf{ - - ZeroCopyInputStreamWrapper::ZeroCopyInputStreamWrapper( GPB::io::ZeroCopyInputStream* stream ) : stream(stream){ - coded_stream = new GPB::io::CodedInputStream(stream); - } - - ZeroCopyInputStreamWrapper::~ZeroCopyInputStreamWrapper(){ - /* first clear the coded stream */ - delete coded_stream ; - - /* then the stream itself */ - delete stream ; - } - GPB::io::ZeroCopyInputStream* ZeroCopyInputStreamWrapper::get_stream(){ - return stream ; - } - GPB::io::CodedInputStream* ZeroCopyInputStreamWrapper::get_coded_stream(){ - return coded_stream ; - } +namespace rprotobuf { -} // namespace rprotobuf +ZeroCopyInputStreamWrapper::ZeroCopyInputStreamWrapper( + GPB::io::ZeroCopyInputStream* stream) + : stream(stream) { + coded_stream = new GPB::io::CodedInputStream(stream); +} +ZeroCopyInputStreamWrapper::~ZeroCopyInputStreamWrapper() { + /* first clear the coded stream */ + delete coded_stream; + + /* then the stream itself */ + delete stream; +} +GPB::io::ZeroCopyInputStream* ZeroCopyInputStreamWrapper::get_stream() { + return stream; +} +GPB::io::CodedInputStream* ZeroCopyInputStreamWrapper::get_coded_stream() { + return coded_stream; +} + +} // namespace rprotobuf Modified: pkg/src/ZeroCopyOutputStreamWrapper.cpp =================================================================== --- pkg/src/ZeroCopyOutputStreamWrapper.cpp 2013-12-30 18:22:34 UTC (rev 633) +++ pkg/src/ZeroCopyOutputStreamWrapper.cpp 2013-12-30 20:27:29 UTC (rev 634) @@ -1,24 +1,25 @@ #include "rprotobuf.h" -namespace rprotobuf{ - - ZeroCopyOutputStreamWrapper::ZeroCopyOutputStreamWrapper( GPB::io::ZeroCopyOutputStream* stream ) : stream(stream){ - coded_stream = new GPB::io::CodedOutputStream(stream); - } - - ZeroCopyOutputStreamWrapper::~ZeroCopyOutputStreamWrapper(){ - /* first clear the coded stream */ - delete coded_stream ; - - /* then the stream itself */ - delete stream ; - } - GPB::io::ZeroCopyOutputStream* ZeroCopyOutputStreamWrapper::get_stream(){ - return stream ; - } - GPB::io::CodedOutputStream* ZeroCopyOutputStreamWrapper::get_coded_stream(){ - return coded_stream ; - } +namespace rprotobuf { -} // namespace rprotobuf +ZeroCopyOutputStreamWrapper::ZeroCopyOutputStreamWrapper( + GPB::io::ZeroCopyOutputStream* stream) + : stream(stream) { + coded_stream = new GPB::io::CodedOutputStream(stream); +} +ZeroCopyOutputStreamWrapper::~ZeroCopyOutputStreamWrapper() { + /* first clear the coded stream */ + delete coded_stream; + + /* then the stream itself */ + delete stream; +} +GPB::io::ZeroCopyOutputStream* ZeroCopyOutputStreamWrapper::get_stream() { + return stream; +} +GPB::io::CodedOutputStream* ZeroCopyOutputStreamWrapper::get_coded_stream() { + return coded_stream; +} + +} // namespace rprotobuf From noreply at r-forge.r-project.org Mon Dec 30 21:30:29 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 21:30:29 +0100 (CET) Subject: [Rprotobuf-commits] r635 - pkg/src Message-ID: <20131230203029.DC89A18698E@r-forge.r-project.org> Author: murray Date: 2013-12-30 21:30:29 +0100 (Mon, 30 Dec 2013) New Revision: 635 Modified: pkg/src/wrapper_Message.cpp Log: Whitespace change only from clang-format (See STYLE file). * Consistently wrap lines at 80 chars. * Consistently avoid space inside '(' for argument lists. * Consistenlty place '{' on same line as case statement. Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-12-30 20:27:29 UTC (rev 634) +++ pkg/src/wrapper_Message.cpp 2013-12-30 20:30:29 UTC (rev 635) @@ -2,63 +2,64 @@ #include "fieldtypes.h" #include "RcppMacros.h" -#define SAME(x,y,tol) ( (tol==0.0 && x == y ) || ( ( (x-y)*(x-y) < tol*tol ) ? 1 : 0 ) ) +#define SAME(x, y, tol) \ + ((tol == 0.0 && x == y) || (((x - y) * (x - y) < tol* tol) ? 1 : 0)) -namespace rprotobuf{ +namespace rprotobuf { /* helpers */ /* this is only to be called for repeated fields */ int MESSAGE_GET_REPEATED_INT(GPB::Message* message, - GPB::FieldDescriptor* field_desc, int index ){ - BEGIN_RCPP - const GPB::Reflection* ref = message->GetReflection() ; - - switch( field_desc->type() ){ - case TYPE_INT32: - case TYPE_SINT32: - case TYPE_SFIXED32: - return (int) ref->GetRepeatedInt32( *message, field_desc, index ) ; - case TYPE_INT64: - case TYPE_SINT64: - case TYPE_SFIXED64: - return (int) ref->GetRepeatedInt64( *message, field_desc, index ) ; - case TYPE_UINT32: - case TYPE_FIXED32: - return (int) ref->GetRepeatedUInt32( *message, field_desc, index ) ; - case TYPE_UINT64: - case TYPE_FIXED64: - return (int) ref->GetRepeatedUInt64( *message, field_desc, index ) ; - case TYPE_ENUM: - return ref->GetRepeatedEnum( *message, field_desc, index )->number() ; - default: - Rcpp_error("cannot cast to int"); - } - VOID_END_RCPP - return 0 ; // -Wall + GPB::FieldDescriptor* field_desc, int index) { + BEGIN_RCPP + const GPB::Reflection* ref = message->GetReflection(); + + switch (field_desc->type()) { + case TYPE_INT32: + case TYPE_SINT32: + case TYPE_SFIXED32: + return (int)ref->GetRepeatedInt32(*message, field_desc, index); + case TYPE_INT64: + case TYPE_SINT64: + case TYPE_SFIXED64: + return (int)ref->GetRepeatedInt64(*message, field_desc, index); + case TYPE_UINT32: + case TYPE_FIXED32: + return (int)ref->GetRepeatedUInt32(*message, field_desc, index); + case TYPE_UINT64: + case TYPE_FIXED64: + return (int)ref->GetRepeatedUInt64(*message, field_desc, index); + case TYPE_ENUM: + return ref->GetRepeatedEnum(*message, field_desc, index)->number(); + default: + Rcpp_error("cannot cast to int"); + } + VOID_END_RCPP + return 0; // -Wall } - + /* this is only to be called for repeated fields */ double MESSAGE_GET_REPEATED_DOUBLE(GPB::Message* message, - GPB::FieldDescriptor* field_desc, - int index ){ - BEGIN_RCPP - const GPB::Reflection* ref = message->GetReflection() ; - - switch( field_desc->type() ){ - case TYPE_FLOAT: - return (double) ref->GetRepeatedFloat( *message, field_desc, index ) ; - case TYPE_DOUBLE: - return (double) ref->GetRepeatedDouble( *message, field_desc, index ) ; - default: - Rcpp_error("cannot cast to double"); - } - VOID_END_RCPP - return 0; // -Wall + GPB::FieldDescriptor* field_desc, + int index) { + BEGIN_RCPP + const GPB::Reflection* ref = message->GetReflection(); + + switch (field_desc->type()) { + case TYPE_FLOAT: + return (double)ref->GetRepeatedFloat(*message, field_desc, index); + case TYPE_DOUBLE: + return (double)ref->GetRepeatedDouble(*message, field_desc, index); + default: + Rcpp_error("cannot cast to double"); + } + VOID_END_RCPP + return 0; // -Wall } #undef METHOD -#define METHOD(__NAME__) RCPP_PP_CAT(Message__,__NAME__) +#define METHOD(__NAME__) RCPP_PP_CAT(Message__, __NAME__) /** * clone a message @@ -66,12 +67,12 @@ * @param xp external pointer to a message * @return a new message, clone of the input message */ -RPB_FUNCTION_1( S4_Message, METHOD(clone) , Rcpp::XPtr message ){ - /* cloning message as sheep */ - GPB::Message* sheep = message->New() ; - sheep->CopyFrom( *message ); - - return S4_Message( sheep ) ; +RPB_FUNCTION_1(S4_Message, METHOD(clone), Rcpp::XPtr message) { + /* cloning message as sheep */ + GPB::Message* sheep = message->New(); + sheep->CopyFrom(*message); + + return S4_Message(sheep); } /** @@ -82,10 +83,11 @@ * @param xp external pointer to the Message * @param name name of the field */ -RPB_FUNCTION_2(bool, METHOD(field_exists), Rcpp::XPtr message, std::string name ){ - const GPB::Descriptor* desc = message->GetDescriptor(); - const GPB::FieldDescriptor* field_desc = desc->FindFieldByName( name ) ; - return (field_desc != NULL); +RPB_FUNCTION_2(bool, METHOD(field_exists), Rcpp::XPtr message, + std::string name) { + const GPB::Descriptor* desc = message->GetDescriptor(); + const GPB::FieldDescriptor* field_desc = desc->FindFieldByName(name); + return (field_desc != NULL); } /** @@ -95,72 +97,72 @@ * @param xp external pointer to the Message * @param name name of the field */ -RPB_FUNCTION_2(bool, METHOD(has_field), Rcpp::XPtr message, std::string name ){ +RPB_FUNCTION_2(bool, METHOD(has_field), Rcpp::XPtr 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 ; + 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 */ -RPB_FUNCTION_1( bool, METHOD(is_initialized), Rcpp::XPtr message){ - return message->IsInitialized() ; +RPB_FUNCTION_1(bool, METHOD(is_initialized), Rcpp::XPtr 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 */ -RPB_FUNCTION_VOID_2( METHOD(serialize_to_file) , Rcpp::XPtr 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 ) ; +RPB_FUNCTION_VOID_2(METHOD(serialize_to_file), Rcpp::XPtr 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 + * create a raw vector that contains the content of the serialized * message * * @param xp xternal pointer to the message */ -RPB_FUNCTION_1( Rcpp::RawVector, METHOD(get_payload), Rcpp::XPtr message ){ +RPB_FUNCTION_1(Rcpp::RawVector, METHOD(get_payload), + Rcpp::XPtr 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 ) ; + /* 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); } -RPB_XP_METHOD_VOID_0(METHOD(clear), GPB::Message, Clear ) +RPB_XP_METHOD_VOID_0(METHOD(clear), GPB::Message, Clear) /** * Clear a field of a message @@ -168,63 +170,64 @@ * @param xp (GPB::Message*) external pointer * @param field name or tag of the field */ -RPB_FUNCTION_VOID_2(METHOD(clear_field), Rcpp::XPtr m, SEXP field ){ - const GPB::FieldDescriptor* field_desc = getFieldDescriptor( m, field ) ; - const GPB::Reflection* ref = m->GetReflection(); - ref->ClearField( m, field_desc ) ; +RPB_FUNCTION_VOID_2(METHOD(clear_field), Rcpp::XPtr m, + SEXP field) { + const GPB::FieldDescriptor* field_desc = getFieldDescriptor(m, field); + const GPB::Reflection* ref = m->GetReflection(); + ref->ClearField(m, field_desc); } - /** * @param xp external pointer to a Message * @return the message as an R list */ -RPB_FUNCTION_1( Rcpp::List, METHOD(as_list), Rcpp::XPtr message ){ - - const GPB::Descriptor* desc = message->GetDescriptor() ; - int nf = desc->field_count() ; - - Rcpp::CharacterVector fieldNames(nf) ; - Rcpp::List val( nf ) ; - /* TODO: not use getMessageField */ - for( int i=0; ifield(i) ; - val[i] = - getMessageField( message, Rcpp::CharacterVector::create( fd->name() ) ) ; - fieldNames[i] = fd->name() ; - } - val.names() = fieldNames ; - return val ; +RPB_FUNCTION_1(Rcpp::List, METHOD(as_list), Rcpp::XPtr message) { + + const GPB::Descriptor* desc = message->GetDescriptor(); + int nf = desc->field_count(); + + Rcpp::CharacterVector fieldNames(nf); + Rcpp::List val(nf); + /* TODO: not use getMessageField */ + for (int i = 0; i < nf; i++) { + const GPB::FieldDescriptor* fd = desc->field(i); + val[i] = + getMessageField(message, Rcpp::CharacterVector::create(fd->name())); + fieldNames[i] = fd->name(); + } + val.names() = fieldNames; + return val; } /** - * The number of fields the message has. A field counts in these two situations : + * The number of fields the message has. A field counts in these two situations + *: * - it is repeated and the array size is greater than 0 * - it is not repeated and the message has it * * @param xp external pointer to the Message */ -RPB_FUNCTION_1(int, METHOD(length), Rcpp::XPtr message){ - const GPB::Descriptor* desc = message->GetDescriptor(); - const GPB::Reflection * ref = message->GetReflection() ; - - int nfields = desc->field_count() ; - - int res = 0; - - for( int i=0; ifield( i ) ; - if( field_desc->is_repeated() ){ - if( ref->FieldSize( *message, field_desc ) > 0 ){ - res++ ; - } - } else{ - if( ref->HasField( *message, field_desc ) ){ - res++ ; - } - } - } - return res ; +RPB_FUNCTION_1(int, METHOD(length), Rcpp::XPtr message) { + const GPB::Descriptor* desc = message->GetDescriptor(); + const GPB::Reflection* ref = message->GetReflection(); + + int nfields = desc->field_count(); + + int res = 0; + + for (int i = 0; i < nfields; i++) { + const GPB::FieldDescriptor* field_desc = desc->field(i); + if (field_desc->is_repeated()) { + if (ref->FieldSize(*message, field_desc) > 0) { + res++; + } + } else { + if (ref->HasField(*message, field_desc)) { + res++; + } + } + } + return res; } /** @@ -232,212 +235,197 @@ * * @param xp external pointer to the Message */ -RPB_FUNCTION_1(int, METHOD(num_extensions), Rcpp::XPtr message){ - const GPB::Reflection * ref = message->GetReflection() ; - int nexts = 0; - vector fields; - ref->ListFields(*message, &fields); - for (int i = 0; i < fields.size(); i++) { - if (fields[i]->is_extension()) { - nexts++; - } - } - return nexts ; +RPB_FUNCTION_1(int, METHOD(num_extensions), Rcpp::XPtr message) { + const GPB::Reflection* ref = message->GetReflection(); + int nexts = 0; + vector fields; + ref->ListFields(*message, &fields); + for (int i = 0; i < fields.size(); i++) { + if (fields[i]->is_extension()) { + nexts++; + } + } + return nexts; } /** * Get the message descriptor of a Message - * + * * @param xp (GPB::Message*) external pointer * @return the descriptor, as a Descriptor R S4 object */ -RPB_FUNCTION_1(S4_Descriptor, METHOD(descriptor), Rcpp::XPtr message ){ - return( message->GetDescriptor() ) ; +RPB_FUNCTION_1(S4_Descriptor, METHOD(descriptor), + Rcpp::XPtr message) { + return (message->GetDescriptor()); } -RPB_XP_METHOD_0( METHOD(as_character) , GPB::Message, DebugString) -RPB_XP_METHOD_0( METHOD(bytesize), GPB::Message, ByteSize ) +RPB_XP_METHOD_0(METHOD(as_character), GPB::Message, DebugString) +RPB_XP_METHOD_0(METHOD(bytesize), GPB::Message, ByteSize) -RPB_FUNCTION_2( int, METHOD(field_size), Rcpp::XPtr message, SEXP field ){ - - const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ; - - int res = 0 ; - if( field_desc->is_repeated() ){ - res = message->GetReflection()->FieldSize(*message, field_desc ) ; - } else{ - res = message->GetReflection()->HasField(*message, field_desc) ? 1: 0 ; - } - return res ; +RPB_FUNCTION_2(int, METHOD(field_size), Rcpp::XPtr message, + SEXP field) { + + const GPB::FieldDescriptor* field_desc = getFieldDescriptor(message, field); + + int res = 0; + if (field_desc->is_repeated()) { + res = message->GetReflection()->FieldSize(*message, field_desc); + } else { + res = message->GetReflection()->HasField(*message, field_desc) ? 1 : 0; + } + return res; } -RPB_FUNCTION_1( S4_FileDescriptor, METHOD(fileDescriptor), Rcpp::XPtr message ){ - return S4_FileDescriptor( message->GetDescriptor()->file() ) ; +RPB_FUNCTION_1(S4_FileDescriptor, METHOD(fileDescriptor), + Rcpp::XPtr message) { + return S4_FileDescriptor(message->GetDescriptor()->file()); } +RPB_FUNCTION_VOID_3(METHOD(set_field_size), Rcpp::XPtr message, + SEXP field, int target) { -RPB_FUNCTION_VOID_3( METHOD(set_field_size), Rcpp::XPtr message, SEXP field, int target){ - - const GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, field ) ; - const GPB::Reflection* ref = message->GetReflection() ; - - if( field_desc->is_repeated() ){ - int current = ref->FieldSize(*message, field_desc ) ; - - if( target == 0){ - ref->ClearField( message, field_desc ); - } else if( current > target ){ - while( current != target ){ - ref->RemoveLast( message, field_desc ) ; - current-- ; - } - } else if( current == target ) { - /* nothing to do */ - } else { /* current < target */ - - while( current != target ){ - - switch( field_desc->type() ){ - case TYPE_INT32: - case TYPE_SINT32: - case TYPE_SFIXED32: - { - ref->AddInt32(message, field_desc, (int32)0 ) ; - break ; - } - case TYPE_INT64: - case TYPE_SINT64: - case TYPE_SFIXED64: - { - ref->AddInt64(message, field_desc, (int64)0 ) ; - break ; - } - case TYPE_UINT32: - case TYPE_FIXED32: - { - ref->AddUInt32(message, field_desc, (uint32)0 ) ; - break ; - } - case TYPE_UINT64: - case TYPE_FIXED64: - { - ref->AddUInt32(message, field_desc, (uint64)0 ) ; - break ; - } - case TYPE_DOUBLE: - { - ref->AddDouble(message, field_desc, (double)0.0 ) ; - break ; - } - case TYPE_FLOAT: - { - ref->AddFloat(message, field_desc, (float)0.0 ) ; - break ; - } - case TYPE_BOOL: - { - ref->AddBool(message, field_desc, (bool)0 ) ; - break ; - } - case TYPE_STRING: - case TYPE_BYTES: - { - ref->AddString(message, field_desc, "" ) ; - break ; - } - case TYPE_MESSAGE: - case TYPE_GROUP: - { - /* fill with the prototype for that message type */ - Rf_error( "growing repeated messages not implemented yet, patches welcome" ) ; - break ; - } - case TYPE_ENUM: - { - /* fill with the prototype for that message type */ - Rf_error( "growing repeated enum not implemented yet, patches welcome" ) ; - break ; - } - } /* switch */ - - current++ ; - } /* while */ - - - } - - } else{ - if( target == 0 ){ - if( ref->HasField( *message, field_desc ) ){ - ref->ClearField( message, field_desc ); - } - } else { - if( !ref->HasField( *message, field_desc ) ){ - switch( field_desc->type() ){ - case TYPE_INT32: - case TYPE_SINT32: - case TYPE_SFIXED32: - { - ref->SetInt32(message, field_desc, (int32)0 ) ; - break ; - } - case TYPE_INT64: - case TYPE_SINT64: - case TYPE_SFIXED64: - { - ref->SetInt64(message, field_desc, (int64)0 ) ; - break ; - } - case TYPE_UINT32: - case TYPE_FIXED32: - { - ref->SetUInt32(message, field_desc, (uint32)0 ) ; - break ; - } - case TYPE_UINT64: - case TYPE_FIXED64: - { - ref->SetUInt32(message, field_desc, (uint64)0 ) ; - break ; - } - case TYPE_DOUBLE: - { - ref->SetDouble(message, field_desc, (double)0.0 ) ; - break ; - } - case TYPE_FLOAT: - { - ref->SetFloat(message, field_desc, (float)0.0 ) ; - break ; - } - case TYPE_BOOL: - { - ref->SetBool(message, field_desc, (bool)0 ) ; - break ; - } - case TYPE_STRING: - case TYPE_BYTES: - { - ref->SetString(message, field_desc, "" ) ; - break ; - } - case TYPE_MESSAGE: - case TYPE_GROUP: - { - /* fill with the prototype for that message type */ - Rf_error( "not implemented yet, patches welcome" ) ; - break ; - } - case TYPE_ENUM: - { - /* fill with the prototype for that message type */ - Rf_error( "not implemented yet, patches welcome" ) ; - break ; - } - } - } - } - } + const GPB::FieldDescriptor* field_desc = getFieldDescriptor(message, field); + const GPB::Reflection* ref = message->GetReflection(); + + if (field_desc->is_repeated()) { + int current = ref->FieldSize(*message, field_desc); + + if (target == 0) { + ref->ClearField(message, field_desc); + } else if (current > target) { + while (current != target) { + ref->RemoveLast(message, field_desc); + current--; + } + } else if (current == target) { + /* nothing to do */ + } else {/* current < target */ + + while (current != target) { + + switch (field_desc->type()) { + case TYPE_INT32: + case TYPE_SINT32: + case TYPE_SFIXED32: { + ref->AddInt32(message, field_desc, (int32)0); + break; + } + case TYPE_INT64: + case TYPE_SINT64: + case TYPE_SFIXED64: { + ref->AddInt64(message, field_desc, (int64)0); + break; + } + case TYPE_UINT32: + case TYPE_FIXED32: { + ref->AddUInt32(message, field_desc, (uint32)0); + break; + } + case TYPE_UINT64: + case TYPE_FIXED64: { + ref->AddUInt32(message, field_desc, (uint64)0); + break; + } + case TYPE_DOUBLE: { + ref->AddDouble(message, field_desc, (double)0.0); + break; + } + case TYPE_FLOAT: { + ref->AddFloat(message, field_desc, (float)0.0); + break; + } + case TYPE_BOOL: { + ref->AddBool(message, field_desc, (bool)0); + break; + } + case TYPE_STRING: + case TYPE_BYTES: { + ref->AddString(message, field_desc, ""); + break; + } + case TYPE_MESSAGE: + case TYPE_GROUP: { + /* fill with the prototype for that message type */ + Rf_error( + "growing repeated messages not implemented yet, " + "patches welcome"); + break; + } + case TYPE_ENUM: { + /* fill with the prototype for that message type */ + Rf_error( + "growing repeated enum not implemented yet, " + "patches welcome"); + break; + } + } /* switch */ + + current++; + } /* while */ + } + + } else { + if (target == 0) { + if (ref->HasField(*message, field_desc)) { + ref->ClearField(message, field_desc); + } + } else { + if (!ref->HasField(*message, field_desc)) { + switch (field_desc->type()) { + case TYPE_INT32: + case TYPE_SINT32: + case TYPE_SFIXED32: { + ref->SetInt32(message, field_desc, (int32)0); + break; + } + case TYPE_INT64: + case TYPE_SINT64: + case TYPE_SFIXED64: { + ref->SetInt64(message, field_desc, (int64)0); + break; + } + case TYPE_UINT32: + case TYPE_FIXED32: { + ref->SetUInt32(message, field_desc, (uint32)0); + break; + } + case TYPE_UINT64: + case TYPE_FIXED64: { + ref->SetUInt32(message, field_desc, (uint64)0); + break; + } + case TYPE_DOUBLE: { + ref->SetDouble(message, field_desc, (double)0.0); + break; + } + case TYPE_FLOAT: { + ref->SetFloat(message, field_desc, (float)0.0); + break; + } + case TYPE_BOOL: { + ref->SetBool(message, field_desc, (bool)0); + break; + } + case TYPE_STRING: + case TYPE_BYTES: { + ref->SetString(message, field_desc, ""); + break; + } + case TYPE_MESSAGE: + case TYPE_GROUP: { + /* fill with the prototype for that message type */ + Rf_error("not implemented yet, patches welcome"); + break; + } + case TYPE_ENUM: { + /* fill with the prototype for that message type */ + Rf_error("not implemented yet, patches welcome"); + break; + } + } + } + } + } } /** @@ -447,222 +435,247 @@ * * @return field names, as an R character vector (STRSXP) */ -RPB_FUNCTION_1( Rcpp::CharacterVector, METHOD(fieldNames), Rcpp::XPtr message){ - const GPB::Descriptor* desc = message->GetDescriptor() ; - - int nfields = desc->field_count() ; - Rcpp::CharacterVector res(nfields) ; - for(int i=0; ifield(i)->name() ; - } - return( res ); +RPB_FUNCTION_1(Rcpp::CharacterVector, METHOD(fieldNames), + Rcpp::XPtr message) { + const GPB::Descriptor* desc = message->GetDescriptor(); + + int nfields = desc->field_count(); + Rcpp::CharacterVector res(nfields); + for (int i = 0; i < nfields; i++) { + res[i] = desc->field(i)->name(); + } + return (res); } -bool identical_messages_( GPB::Message* m1, GPB::Message* m2, double tol ){ - BEGIN_RCPP - const GPB::Descriptor* d1 = m1->GetDescriptor() ; - const GPB::Descriptor* d2 = m2->GetDescriptor() ; - - /* first of all, check if this is the same message type */ - if( d1 != d2 ){ - return false ; - } - - const GPB::Reflection* ref = m2->GetReflection() ; - - /* iterate field descriptors */ - int nf = d1->field_count() ; - for( int i=0; ifield( i ) ; - - if( field_desc->is_repeated() ){ - - /* test if the size differs */ - int fs = ref->FieldSize( *m1, field_desc) ; - if( fs != ref->FieldSize( *m2, field_desc) ) return false ; - - /* test all items */ - switch( field_desc->type() ){ - case TYPE_INT32: - case TYPE_SINT32: - case TYPE_SFIXED32: - { - for( int j=0; jGetRepeatedInt32( *m1, field_desc, j ) != ref->GetRepeatedInt32( *m2, field_desc, j ) ) return false ; - } - break ; - } - case TYPE_INT64: - case TYPE_SINT64: - case TYPE_SFIXED64: - { - for( int j=0; jGetRepeatedInt64( *m1, field_desc, j ) != ref->GetRepeatedInt64( *m2, field_desc, j ) ) return false ; - } - break ; - } - case TYPE_UINT32: - case TYPE_FIXED32: - { - for( int j=0; jGetRepeatedUInt32( *m1, field_desc, j ) != ref->GetRepeatedUInt32( *m2, field_desc, j ) ) return false ; - } - break ; - } - case TYPE_UINT64: - case TYPE_FIXED64: - { - for( int j=0; jGetRepeatedUInt64( *m1, field_desc, j ) != ref->GetRepeatedUInt64( *m2, field_desc, j ) ) return false ; - } - break ; - } - case TYPE_DOUBLE: - { - for( int j=0; jGetRepeatedDouble( *m1, field_desc, j ), ref->GetRepeatedDouble( *m2, field_desc, j ), tol) ) return false ; - } - break ; - } - case TYPE_FLOAT: - { - for( int j=0; jGetRepeatedFloat( *m1, field_desc, j ), ref->GetRepeatedFloat( *m2, field_desc, j ), tol) ) return false ; - } - break ; - } - case TYPE_BOOL: - { - for( int j=0; jGetRepeatedBool( *m1, field_desc, j ) != ref->GetRepeatedBool( *m2, field_desc, j ) ) return false ; - } - break ; - } - case TYPE_STRING: - case TYPE_BYTES: - { - for( int j=0; jGetRepeatedString( *m1, field_desc, j ) != ref->GetRepeatedString( *m2, field_desc, j ) ) return false ; - } - break ; - } - case TYPE_ENUM : - { - for( int j=0; jGetRepeatedEnum( *m1, field_desc, j ) != ref->GetRepeatedEnum( *m2, field_desc, j ) ) return false ; - } - break ; - } - case TYPE_MESSAGE: - case TYPE_GROUP: - { - for( int j=0; jGetRepeatedMessage( *m1, field_desc, j ) ; - const GPB::Message* mm2 = &ref->GetRepeatedMessage( *m2, field_desc, j ) ; - if( !identical_messages_( (GPB::Message*)mm1, (GPB::Message*)mm2, tol ) ){ - return false ; - } - } - break ; - } - default: - Rcpp_error("unknown type"); - } - - } else { - - switch( field_desc->type() ){ - case TYPE_INT32: - case TYPE_SINT32: - case TYPE_SFIXED32: - { - if( ref->GetInt32( *m1, field_desc) != ref->GetInt32( *m2, field_desc ) ) return false ; - break ; - } - case TYPE_INT64: - case TYPE_SINT64: - case TYPE_SFIXED64: - { - if( ref->GetInt64( *m1, field_desc) != ref->GetInt64( *m2, field_desc) ) return false ; - break ; - } - case TYPE_UINT32: - case TYPE_FIXED32: - { - if( ref->GetUInt32( *m1, field_desc ) != ref->GetUInt32( *m2, field_desc ) ) return false ; - break ; - } - case TYPE_UINT64: - case TYPE_FIXED64: - { - if( ref->GetUInt64( *m1, field_desc ) != ref->GetUInt64( *m2, field_desc ) ) return false ; - break ; - } - case TYPE_DOUBLE: - { - if( ref->GetDouble( *m1, field_desc ) != ref->GetDouble( *m2, field_desc ) ) return false ; - break ; - } - case TYPE_FLOAT: - { - if( ref->GetFloat( *m1, field_desc ) != ref->GetFloat( *m2, field_desc ) ) return false ; - break ; - } - case TYPE_BOOL: - { - if( ref->GetBool( *m1, field_desc ) != ref->GetBool( *m2, field_desc ) ) return false ; - break ; - } - case TYPE_STRING: - case TYPE_BYTES: - { - if( ref->GetString( *m1, field_desc ) != ref->GetString( *m2, field_desc ) ) return false ; - break ; - } - case TYPE_ENUM : - { - if( ref->GetEnum( *m1, field_desc) != ref->GetEnum( *m2, field_desc ) ) return false ; - break ; - } - case TYPE_MESSAGE: - case TYPE_GROUP: - { - const GPB::Message* mm1 = &ref->GetMessage( *m1, field_desc ) ; - const GPB::Message* mm2 = &ref->GetMessage( *m2, field_desc ) ; - if( !identical_messages_( (GPB::Message*)mm1, (GPB::Message*)mm2, tol ) ){ - return false ; - } - break ; - } - default: - Rcpp_error("unknown type"); - } - - } - } - VOID_END_RCPP - /* finally */ - return true ; +bool identical_messages_(GPB::Message* m1, GPB::Message* m2, double tol) { + BEGIN_RCPP + const GPB::Descriptor* d1 = m1->GetDescriptor(); + const GPB::Descriptor* d2 = m2->GetDescriptor(); + + /* first of all, check if this is the same message type */ + if (d1 != d2) { + return false; + } + + const GPB::Reflection* ref = m2->GetReflection(); + + /* iterate field descriptors */ + int nf = d1->field_count(); + for (int i = 0; i < nf; i++) { + const GPB::FieldDescriptor* field_desc = d1->field(i); + + if (field_desc->is_repeated()) { + + /* test if the size differs */ + int fs = ref->FieldSize(*m1, field_desc); + if (fs != ref->FieldSize(*m2, field_desc)) return false; + + /* test all items */ + switch (field_desc->type()) { + case TYPE_INT32: + case TYPE_SINT32: + case TYPE_SFIXED32: { + for (int j = 0; j < fs; j++) { + if (ref->GetRepeatedInt32(*m1, field_desc, j) != + ref->GetRepeatedInt32(*m2, field_desc, j)) + return false; + } + break; + } + case TYPE_INT64: + case TYPE_SINT64: + case TYPE_SFIXED64: { + for (int j = 0; j < fs; j++) { + if (ref->GetRepeatedInt64(*m1, field_desc, j) != + ref->GetRepeatedInt64(*m2, field_desc, j)) + return false; + } + break; + } + case TYPE_UINT32: + case TYPE_FIXED32: { + for (int j = 0; j < fs; j++) { + if (ref->GetRepeatedUInt32(*m1, field_desc, j) != [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rprotobuf -r 635 From noreply at r-forge.r-project.org Mon Dec 30 21:32:53 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 21:32:53 +0100 (CET) Subject: [Rprotobuf-commits] r636 - pkg/src Message-ID: <20131230203253.3DB1B186A23@r-forge.r-project.org> Author: murray Date: 2013-12-30 21:32:52 +0100 (Mon, 30 Dec 2013) New Revision: 636 Modified: pkg/src/ConnectionCopyingInputStream.cpp pkg/src/ConnectionCopyingOutputStream.cpp pkg/src/ConnectionInputStream.cpp pkg/src/ConnectionOutputStream.cpp Log: Whitespace change only. From clang-format (see STYLE). Modified: pkg/src/ConnectionCopyingInputStream.cpp =================================================================== --- pkg/src/ConnectionCopyingInputStream.cpp 2013-12-30 20:30:29 UTC (rev 635) +++ pkg/src/ConnectionCopyingInputStream.cpp 2013-12-30 20:32:52 UTC (rev 636) @@ -1,27 +1,24 @@ #include "rprotobuf.h" #include "ConnectionCopyingInputStream.h" -namespace rprotobuf{ - - ConnectionCopyingInputStream::ConnectionCopyingInputStream(SEXP con) : - con(con), readBin("readBin") {} - - /** - * call readBin to read size bytes from R - * - * @param buffer buffer to fill with at most size bytes - * @param size maximum number of bytes - * - * @return the number of bytes actually read - */ - int ConnectionCopyingInputStream::Read(void * buffer, int size){ - - /* TODO: error handling */ - Rcpp::RawVector res = readBin( con, Rcpp::RawVector( 0 ), size ) ; - memcpy( buffer, res.begin() , res.size() ) ; - return res.size() ; - } - - -} +namespace rprotobuf { +ConnectionCopyingInputStream::ConnectionCopyingInputStream(SEXP con) + : con(con), readBin("readBin") {} + +/** + * call readBin to read size bytes from R + * + * @param buffer buffer to fill with at most size bytes + * @param size maximum number of bytes + * + * @return the number of bytes actually read + */ +int ConnectionCopyingInputStream::Read(void* buffer, int size) { + + /* TODO: error handling */ + Rcpp::RawVector res = readBin(con, Rcpp::RawVector(0), size); + memcpy(buffer, res.begin(), res.size()); + return res.size(); +} +} Modified: pkg/src/ConnectionCopyingOutputStream.cpp =================================================================== --- pkg/src/ConnectionCopyingOutputStream.cpp 2013-12-30 20:30:29 UTC (rev 635) +++ pkg/src/ConnectionCopyingOutputStream.cpp 2013-12-30 20:32:52 UTC (rev 636) @@ -1,19 +1,18 @@ #include "rprotobuf.h" #include "ConnectionCopyingOutputStream.h" -namespace rprotobuf{ - - ConnectionCopyingOutputStream::ConnectionCopyingOutputStream(SEXP con) : con(con), writeBin("writeBin") {} - - bool ConnectionCopyingOutputStream::Write(const void * buffer, int size){ - - /* we need to take care of error handling */ - Rcpp::RawVector payload(size) ; - memcpy( payload.begin() , buffer, size ) ; - - writeBin( payload, con) ; - return true ; - } - -} +namespace rprotobuf { +ConnectionCopyingOutputStream::ConnectionCopyingOutputStream(SEXP con) + : con(con), writeBin("writeBin") {} + +bool ConnectionCopyingOutputStream::Write(const void* buffer, int size) { + + /* we need to take care of error handling */ + Rcpp::RawVector payload(size); + memcpy(payload.begin(), buffer, size); + + writeBin(payload, con); + return true; +} +} Modified: pkg/src/ConnectionInputStream.cpp =================================================================== --- pkg/src/ConnectionInputStream.cpp 2013-12-30 20:30:29 UTC (rev 635) +++ pkg/src/ConnectionInputStream.cpp 2013-12-30 20:32:52 UTC (rev 636) @@ -2,27 +2,26 @@ #include "ConnectionInputStream.h" #include "ConnectionCopyingInputStream.h" -namespace rprotobuf{ - - ConnectionInputStream::ConnectionInputStream(SEXP con, bool was_open): - GPB::io::CopyingInputStreamAdaptor( new ConnectionCopyingInputStream( con ) ), - was_open(was_open), - con(con) - { - /* clean the wrapped stream on delete */ - SetOwnsCopyingStream(true) ; - } - - ConnectionInputStream::~ConnectionInputStream(){ - if( ! was_open ){ - /* then we need to close it */ - SEXP call = PROTECT( Rf_lang2( Rf_install( "close" ) , con ) ) ; - Rf_eval( call, R_GlobalEnv ) ; - UNPROTECT( 1 ) ; /* call */ - } - /* con will be disposed by the R GC, it is - protected as part of the protection of the - external pointer that wraps this */ - } - -} // namespace rprotobuf +namespace rprotobuf { + +ConnectionInputStream::ConnectionInputStream(SEXP con, bool was_open) + : GPB::io::CopyingInputStreamAdaptor(new ConnectionCopyingInputStream(con)), + was_open(was_open), + con(con) { + /* clean the wrapped stream on delete */ + SetOwnsCopyingStream(true); +} + +ConnectionInputStream::~ConnectionInputStream() { + if (!was_open) { + /* then we need to close it */ + SEXP call = PROTECT(Rf_lang2(Rf_install("close"), con)); + Rf_eval(call, R_GlobalEnv); + UNPROTECT(1); /* call */ + } + /* con will be disposed by the R GC, it is + protected as part of the protection of the + external pointer that wraps this */ +} + +} // namespace rprotobuf Modified: pkg/src/ConnectionOutputStream.cpp =================================================================== --- pkg/src/ConnectionOutputStream.cpp 2013-12-30 20:30:29 UTC (rev 635) +++ pkg/src/ConnectionOutputStream.cpp 2013-12-30 20:32:52 UTC (rev 636) @@ -2,27 +2,27 @@ #include "ConnectionOutputStream.h" #include "ConnectionCopyingOutputStream.h" -namespace rprotobuf{ - - ConnectionOutputStream::ConnectionOutputStream(SEXP con, bool was_open): - GPB::io::CopyingOutputStreamAdaptor( new ConnectionCopyingOutputStream( con ) ), - was_open(was_open), - con(con) - { - /* clean the wrapped stream on delete */ - SetOwnsCopyingStream(true) ; - } - - ConnectionOutputStream::~ConnectionOutputStream(){ - if( ! was_open ){ - /* then we need to close it */ - SEXP call = PROTECT( Rf_lang2( Rf_install( "close" ) , con ) ) ; - Rf_eval( call, R_GlobalEnv ) ; - UNPROTECT( 1 ) ; /* call */ - } - /* con will be disposed by the R GC, it is - protected as part of the protection of the - external pointer that wraps this */ - } - -} // namespace rprotobuf +namespace rprotobuf { + +ConnectionOutputStream::ConnectionOutputStream(SEXP con, bool was_open) + : GPB::io::CopyingOutputStreamAdaptor( + new ConnectionCopyingOutputStream(con)), + was_open(was_open), + con(con) { + /* clean the wrapped stream on delete */ + SetOwnsCopyingStream(true); +} + +ConnectionOutputStream::~ConnectionOutputStream() { + if (!was_open) { + /* then we need to close it */ + SEXP call = PROTECT(Rf_lang2(Rf_install("close"), con)); + Rf_eval(call, R_GlobalEnv); + UNPROTECT(1); /* call */ + } + /* con will be disposed by the R GC, it is + protected as part of the protection of the + external pointer that wraps this */ +} + +} // namespace rprotobuf From noreply at r-forge.r-project.org Mon Dec 30 21:34:11 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 21:34:11 +0100 (CET) Subject: [Rprotobuf-commits] r637 - pkg/src Message-ID: <20131230203411.8D2D5186A3D@r-forge.r-project.org> Author: murray Date: 2013-12-30 21:34:10 +0100 (Mon, 30 Dec 2013) New Revision: 637 Modified: pkg/src/DescriptorPoolLookup.cpp pkg/src/extensions.cpp Log: Whitespace change only (clang-format). * Consistent indentation and wrap at 80 chars. Modified: pkg/src/DescriptorPoolLookup.cpp =================================================================== --- pkg/src/DescriptorPoolLookup.cpp 2013-12-30 20:32:52 UTC (rev 636) +++ pkg/src/DescriptorPoolLookup.cpp 2013-12-30 20:34:10 UTC (rev 637) @@ -22,60 +22,60 @@ #include "rprotobuf.h" #include "DescriptorPoolLookup.h" -namespace rprotobuf{ - - void DescriptorPoolLookup::add( const std::string& element){ - elements.insert( element ); - } - - bool DescriptorPoolLookup::contains( const std::string& element ){ - return elements.find( element ) != elements.end() ; - } - - SEXP DescriptorPoolLookup::getElements(){ - return Rcpp::wrap(elements) ; - } - - std::set DescriptorPoolLookup::elements ; - RWarningErrorCollector DescriptorPoolLookup::error_collector ; - RSourceTree DescriptorPoolLookup::source_tree ; - GPB::compiler::Importer DescriptorPoolLookup::importer(&source_tree, &error_collector) ; - GPB::DynamicMessageFactory DescriptorPoolLookup::message_factory(importer.pool()) ; - - void DescriptorPoolLookup::importProtoFiles(SEXP files, SEXP dirs ){ - source_tree.addDirectories( dirs ) ; - int n = LENGTH(files) ; - for( int j=0; j < n; j++ ){ - const GPB::FileDescriptor* file_desc = importer.Import( CHAR(STRING_ELT(files, j)) ); - if (!file_desc) { - Rf_error("Could not load proto file '%s'\n", - CHAR(STRING_ELT(files, j))); - continue; - } - int ntypes = file_desc->message_type_count() ; - for( int i=0; imessage_type( i ) ; - add( desc->full_name() ); - /* should we bother recursing ? */ - /* TODO(mstokely): add top level enums and services? */ - } - // add top level extensions! - int nexts = file_desc->extension_count() ; - for( int i=0; iextension( i ) ; - add( field_desc->full_name() ); - } - } - // source_tree.removeDirectories( dirs ) ; - } - - const GPB::DescriptorPool* DescriptorPoolLookup::pool(){ - return importer.pool() ; - } - - const GPB::DynamicMessageFactory* DescriptorPoolLookup::factory(){ - return &message_factory ; - } - - -} // namespace rprotobuf +namespace rprotobuf { + +void DescriptorPoolLookup::add(const std::string& element) { + elements.insert(element); +} + +bool DescriptorPoolLookup::contains(const std::string& element) { + return elements.find(element) != elements.end(); +} + +SEXP DescriptorPoolLookup::getElements() { return Rcpp::wrap(elements); } + +std::set DescriptorPoolLookup::elements; +RWarningErrorCollector DescriptorPoolLookup::error_collector; +RSourceTree DescriptorPoolLookup::source_tree; +GPB::compiler::Importer DescriptorPoolLookup::importer(&source_tree, + &error_collector); +GPB::DynamicMessageFactory DescriptorPoolLookup::message_factory( + importer.pool()); + +void DescriptorPoolLookup::importProtoFiles(SEXP files, SEXP dirs) { + source_tree.addDirectories(dirs); + int n = LENGTH(files); + for (int j = 0; j < n; j++) { + const GPB::FileDescriptor* file_desc = + importer.Import(CHAR(STRING_ELT(files, j))); + if (!file_desc) { + Rf_error("Could not load proto file '%s'\n", + CHAR(STRING_ELT(files, j))); + continue; + } + int ntypes = file_desc->message_type_count(); + for (int i = 0; i < ntypes; i++) { + const GPB::Descriptor* desc = file_desc->message_type(i); + add(desc->full_name()); + /* should we bother recursing ? */ + /* TODO(mstokely): add top level enums and services? */ + } + // add top level extensions! + int nexts = file_desc->extension_count(); + for (int i = 0; i < nexts; i++) { + const GPB::FieldDescriptor* field_desc = file_desc->extension(i); + add(field_desc->full_name()); + } + } + // source_tree.removeDirectories( dirs ) ; +} + +const GPB::DescriptorPool* DescriptorPoolLookup::pool() { + return importer.pool(); +} + +const GPB::DynamicMessageFactory* DescriptorPoolLookup::factory() { + return &message_factory; +} + +} // namespace rprotobuf Modified: pkg/src/extensions.cpp =================================================================== --- pkg/src/extensions.cpp 2013-12-30 20:32:52 UTC (rev 636) +++ pkg/src/extensions.cpp 2013-12-30 20:34:10 UTC (rev 637) @@ -25,30 +25,30 @@ namespace rprotobuf { -RcppExport SEXP getExtension( SEXP pointer, SEXP sfielddesc){ - /* grab the Message pointer */ - Rcpp::XPtr message(pointer) ; - const Reflection * ref = message->GetReflection() ; - const GPB::FieldDescriptor* field_desc = - GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(sfielddesc); +RcppExport SEXP getExtension(SEXP pointer, SEXP sfielddesc) { + /* grab the Message pointer */ + Rcpp::XPtr message(pointer); + const Reflection* ref = message->GetReflection(); + const GPB::FieldDescriptor* field_desc = + GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(sfielddesc); - // extractFieldAsSEXP returns a default (e.g. 0) even when - // field doesn't exist, but returning NULL probably makes more - // sense. - // - // TODO(mstokely): move this logic into extractField so that - // all fields get this updated behavior, not just extensions. + // extractFieldAsSEXP returns a default (e.g. 0) even when + // field doesn't exist, but returning NULL probably makes more + // sense. + // + // TODO(mstokely): move this logic into extractField so that + // all fields get this updated behavior, not just extensions. - if (field_desc->is_repeated()) { - if (ref->FieldSize(*message, field_desc) < 1) { - return R_NilValue; - } - } else { - if (!ref->HasField(*message, field_desc)) { - return R_NilValue; - } - } - return( extractFieldAsSEXP(message, field_desc) ); + if (field_desc->is_repeated()) { + if (ref->FieldSize(*message, field_desc) < 1) { + return R_NilValue; + } + } else { + if (!ref->HasField(*message, field_desc)) { + return R_NilValue; + } + } + return (extractFieldAsSEXP(message, field_desc)); } } // namespace rprotobuf From noreply at r-forge.r-project.org Mon Dec 30 21:38:39 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 21:38:39 +0100 (CET) Subject: [Rprotobuf-commits] r638 - pkg/src Message-ID: <20131230203839.8FD74186B66@r-forge.r-project.org> Author: murray Date: 2013-12-30 21:38:38 +0100 (Mon, 30 Dec 2013) New Revision: 638 Modified: pkg/src/SocketCopyingInputStream.cpp pkg/src/lookup.cpp pkg/src/streams.cpp Log: Whitespace change only (clang-format) Consistent indentation, brace placement, and 80-char line wrapping. Modified: pkg/src/SocketCopyingInputStream.cpp =================================================================== --- pkg/src/SocketCopyingInputStream.cpp 2013-12-30 20:34:10 UTC (rev 637) +++ pkg/src/SocketCopyingInputStream.cpp 2013-12-30 20:38:38 UTC (rev 638) @@ -1,25 +1,21 @@ #include "rprotobuf.h" #include "SocketCopyingInputStream.h" -namespace rprotobuf{ - - SocketCopyingInputStream::SocketCopyingInputStream(int id){ - socket_id = id ; - } - - /** - * read from the socket - * - * @param buffer buffer to fill with at most size bytes - * @param size maximum number of bytes - * - * @return the number of bytes actually read - */ - int SocketCopyingInputStream::Read(void * buffer, int size){ - int received = recv( socket_id, buffer, size, 0 ) ; - if( received < 0 ) THROW_SOCKET_ERROR( "recv" ) ; - return received ; - } - -} +namespace rprotobuf { +SocketCopyingInputStream::SocketCopyingInputStream(int id) { socket_id = id; } + +/** + * read from the socket + * + * @param buffer buffer to fill with at most size bytes + * @param size maximum number of bytes + * + * @return the number of bytes actually read + */ +int SocketCopyingInputStream::Read(void* buffer, int size) { + int received = recv(socket_id, buffer, size, 0); + if (received < 0) THROW_SOCKET_ERROR("recv"); + return received; +} +} Modified: pkg/src/lookup.cpp =================================================================== --- pkg/src/lookup.cpp 2013-12-30 20:34:10 UTC (rev 637) +++ pkg/src/lookup.cpp 2013-12-30 20:38:38 UTC (rev 638) @@ -1,19 +1,18 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- +// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; +// -*- #include "rprotobuf.h" -#include "DescriptorPoolLookup.h" +#include "DescriptorPoolLookup.h" /* This uses the mechanism of the RObjectTables package see: http://www.omegahat.org/RObjectTables/ */ -namespace rprotobuf{ +namespace rprotobuf { /** * Returns the R_UnboundValue */ -SEXP R_getUnboundValue() { - return(R_UnboundValue); -} +SEXP R_getUnboundValue() { return (R_UnboundValue); } /** * @param name potential message type @@ -22,152 +21,151 @@ * * @return _TRUE_ if there is a message of the given type in the DescriptorPool */ -Rboolean rProtoBufTable_exists(const char * const name, Rboolean *canCache, R_ObjectTable *tb){ +Rboolean rProtoBufTable_exists(const char *const name, Rboolean *canCache, + R_ObjectTable *tb) { #ifdef LOOKUP_DEBUG - Rprintf( " >> rProtoBufTable_exists\n" ); + Rprintf(" >> rProtoBufTable_exists\n"); #endif - - if(tb->active == _FALSE_) - return( _FALSE_ ); - tb->active = _FALSE_; - Rboolean val = _FALSE_ ; - if( DescriptorPoolLookup::contains( name ) ){ - /* first check the cache */ - val = _TRUE_ ; - } else { - /* try the generated pool */ - const GPB::DescriptorPool* pool = GPB::DescriptorPool::generated_pool() ; - if( pool->FindMessageTypeByName( name ) || - pool->FindEnumTypeByName( name ) || - pool->FindServiceByName( name ) || - pool->FindMethodByName( name ) || - pool->FindExtensionByName( name )){ - DescriptorPoolLookup::add( name ) ; - val = _TRUE_ ; - } else { - /* try the runtime pool */ - pool = DescriptorPoolLookup::pool() ; - if( pool->FindMessageTypeByName( name ) || - pool->FindEnumTypeByName( name ) || - pool->FindServiceByName( name ) || - pool->FindMethodByName( name ) || - pool->FindExtensionByName( name )){ - DescriptorPoolLookup::add( name ) ; - val = _TRUE_ ; - } - } - } - tb->active = _TRUE_; - - return( val ); -} + if (tb->active == _FALSE_) return (_FALSE_); -SEXP findSomething( const GPB::DescriptorPool* pool, const char * const name){ - const GPB::Descriptor* desc = pool->FindMessageTypeByName( name ) ; - std::string name_string(name) ; - if( desc ){ - /* message */ - DescriptorPoolLookup::add( name_string ) ; - return S4_Descriptor( desc ) ; - } else { - const GPB::EnumDescriptor* enum_desc = pool->FindEnumTypeByName( name_string ) ; - if( enum_desc ){ - /* enum */ - DescriptorPoolLookup::add( name_string ) ; - return S4_EnumDescriptor( enum_desc ); + tb->active = _FALSE_; + Rboolean val = _FALSE_; + if (DescriptorPoolLookup::contains(name)) { + /* first check the cache */ + val = _TRUE_; + } else { + /* try the generated pool */ + const GPB::DescriptorPool *pool = GPB::DescriptorPool::generated_pool(); + if (pool->FindMessageTypeByName(name) || + pool->FindEnumTypeByName(name) || pool->FindServiceByName(name) || + pool->FindMethodByName(name) || pool->FindExtensionByName(name)) { + DescriptorPoolLookup::add(name); + val = _TRUE_; + } else { + /* try the runtime pool */ + pool = DescriptorPoolLookup::pool(); + if (pool->FindMessageTypeByName(name) || + pool->FindEnumTypeByName(name) || + pool->FindServiceByName(name) || pool->FindMethodByName(name) || + pool->FindExtensionByName(name)) { + DescriptorPoolLookup::add(name); + val = _TRUE_; + } + } + } + tb->active = _TRUE_; - } else{ - const GPB::FieldDescriptor* extension_desc = - pool->FindExtensionByName( name_string ) ; - if( extension_desc ){ - /* extension */ - DescriptorPoolLookup::add( name_string ) ; - return S4_FieldDescriptor( extension_desc ) ; - } else{ - const GPB::ServiceDescriptor* service_desc = pool->FindServiceByName( name_string ) ; - if( service_desc ){ - DescriptorPoolLookup::add( name_string ) ; - return S4_ServiceDescriptor( service_desc ) ; - } else { - const GPB::MethodDescriptor* method_desc = pool->FindMethodByName( name_string ); - if( method_desc ){ - DescriptorPoolLookup::add( name_string ) ; - return S4_MethodDescriptor( method_desc ); - } - } - } - } - } - return R_NilValue ; + return (val); } +SEXP findSomething(const GPB::DescriptorPool *pool, const char *const name) { + const GPB::Descriptor *desc = pool->FindMessageTypeByName(name); + std::string name_string(name); + if (desc) { + /* message */ + DescriptorPoolLookup::add(name_string); + return S4_Descriptor(desc); + } else { + const GPB::EnumDescriptor *enum_desc = + pool->FindEnumTypeByName(name_string); + if (enum_desc) { + /* enum */ + DescriptorPoolLookup::add(name_string); + return S4_EnumDescriptor(enum_desc); + } else { + const GPB::FieldDescriptor *extension_desc = + pool->FindExtensionByName(name_string); + if (extension_desc) { + /* extension */ + DescriptorPoolLookup::add(name_string); + return S4_FieldDescriptor(extension_desc); + } else { + const GPB::ServiceDescriptor *service_desc = + pool->FindServiceByName(name_string); + if (service_desc) { + DescriptorPoolLookup::add(name_string); + return S4_ServiceDescriptor(service_desc); + } else { + const GPB::MethodDescriptor *method_desc = + pool->FindMethodByName(name_string); + if (method_desc) { + DescriptorPoolLookup::add(name_string); + return S4_MethodDescriptor(method_desc); + } + } + } + } + } + return R_NilValue; +} + /** * Returns a new "Descriptor" if there is such a message type * in the descriptor pool. NULL otherwise * * @param name message type name (without package path) - * @param canCache + * @param canCache * @param tb lookup table */ -SEXP rProtoBufTable_get(const char * const name, Rboolean *canCache, R_ObjectTable *tb){ +SEXP rProtoBufTable_get(const char *const name, Rboolean *canCache, + R_ObjectTable *tb) { #ifdef LOOKUP_DEBUG - Rprintf( " >> rProtoBufTable_get\n" ); + Rprintf(" >> rProtoBufTable_get\n"); #endif - if(tb->active == _FALSE_) - return(R_UnboundValue); + if (tb->active == _FALSE_) return (R_UnboundValue); - tb->active = _FALSE_; - - SEXP res_generated ; - SEXP res_runtime ; - int np = 0 ; - - /* first try the generated pool */ - const GPB::DescriptorPool* pool = GPB::DescriptorPool::generated_pool() ; - res_generated = PROTECT( findSomething( pool, name ) ) ; - np++; - if( res_generated == R_NilValue ){ - /* try the runtime pool */ - pool = DescriptorPoolLookup::pool() ; - res_runtime = PROTECT( findSomething( pool, name ) ); - np++ ; - } - tb->active = _TRUE_; - SEXP res = PROTECT( (np==2) ? res_runtime : res_generated ) ; - UNPROTECT(np+1) ; - if( res != R_NilValue ) return res ; - return R_getUnboundValue() ; // -Wall + tb->active = _FALSE_; + + SEXP res_generated; + SEXP res_runtime; + int np = 0; + + /* first try the generated pool */ + const GPB::DescriptorPool *pool = GPB::DescriptorPool::generated_pool(); + res_generated = PROTECT(findSomething(pool, name)); + np++; + if (res_generated == R_NilValue) { + /* try the runtime pool */ + pool = DescriptorPoolLookup::pool(); + res_runtime = PROTECT(findSomething(pool, name)); + np++; + } + tb->active = _TRUE_; + SEXP res = PROTECT((np == 2) ? res_runtime : res_generated); + UNPROTECT(np + 1); + if (res != R_NilValue) return res; + return R_getUnboundValue(); // -Wall } /** * Does nothing. Not applicable */ -int rProtoBufTable_remove(const char * const name, R_ObjectTable *tb){ +int rProtoBufTable_remove(const char *const name, R_ObjectTable *tb) { #ifdef LOOKUP_DEBUG - Rprintf( " >> rProtoBufTable_remove( %s) \n", name ); + Rprintf(" >> rProtoBufTable_remove( %s) \n", name); #endif - Rf_error( "cannot remove from protobuf descriptor pool" ) ; - return(0); // make -Wall happy + Rf_error("cannot remove from protobuf descriptor pool"); + return (0); // make -Wall happy } /** - * Indicates if R can cache the variable name. + * Indicates if R can cache the variable name. * Currently allways return _FALSE_ * * @param name message type name * @param tb lookup table * @return allways _FALSE_ (for now) - */ -Rboolean rProtoBufTable_canCache(const char * const name, R_ObjectTable *tb){ + */ +Rboolean rProtoBufTable_canCache(const char *const name, R_ObjectTable *tb) { #ifdef LOOKUP_DEBUG - Rprintf( " >> rProtoBufTable_canCache\n" ); + Rprintf(" >> rProtoBufTable_canCache\n"); #endif - return( _FALSE_ ); + return (_FALSE_); } /** @@ -177,48 +175,48 @@ * NULL to indicate assign is not possible on this lookup table * without giving such a hard error. */ -SEXP rProtoBufTable_assign(const char * const name, SEXP value, R_ObjectTable *tb){ +SEXP rProtoBufTable_assign(const char *const name, SEXP value, + R_ObjectTable *tb) { #ifdef LOOKUP_DEBUG - Rprintf( " >> rProtoBufTable_assign( %s ) \n", name ); + Rprintf(" >> rProtoBufTable_assign( %s ) \n", name); #endif - return(R_NilValue); // make -Wall happy + return (R_NilValue); // make -Wall happy } /** - * Returns the list of classes known to be included in the - * packages. + * Returns the list of classes known to be included in the + * packages. * * @param tb lookup table */ SEXP rProtoBufTable_objects(R_ObjectTable *tb) { #ifdef LOOKUP_DEBUG - Rprintf( " >> rProtoBufTable_objects\n" ); + Rprintf(" >> rProtoBufTable_objects\n"); #endif - tb->active = _FALSE_; - SEXP objects = PROTECT( DescriptorPoolLookup::getElements() ) ; - tb->active = _TRUE_; - UNPROTECT(1); /* objects */ - - return( objects ); + tb->active = _FALSE_; + SEXP objects = PROTECT(DescriptorPoolLookup::getElements()); + tb->active = _TRUE_; + UNPROTECT(1); /* objects */ + + return (objects); } -SEXP newProtocolBufferLookup(SEXP possexp){ +SEXP newProtocolBufferLookup(SEXP possexp) { #ifdef LOOKUP_DEBUG - Rprintf( "\n" ); + Rprintf("\n"); #endif R_ObjectTable *tb; SEXP val, klass; - tb = (R_ObjectTable *) malloc(sizeof(R_ObjectTable)); - if(!tb) - Rf_error( "cannot allocate space for an internal R object table" ); - - tb->type = RPROTOBUF_LOOKUP ; /* FIXME: not sure what this should be */ + tb = (R_ObjectTable *)malloc(sizeof(R_ObjectTable)); + if (!tb) Rf_error("cannot allocate space for an internal R object table"); + + tb->type = RPROTOBUF_LOOKUP; /* FIXME: not sure what this should be */ tb->cachedNames = NULL; - - tb->privateData = (void*)0 ; + tb->privateData = (void *)0; + tb->exists = rProtoBufTable_exists; tb->get = rProtoBufTable_get; tb->remove = rProtoBufTable_remove; @@ -229,23 +227,22 @@ tb->onAttach = NULL; tb->onDetach = NULL; - PROTECT(val = R_MakeExternalPtr(tb, Rf_install("UserDefinedDatabase"), R_NilValue)); - PROTECT(klass = Rf_mkString( "UserDefinedDatabase" ) ); - Rf_setAttrib(val, R_ClassSymbol, klass) ; + PROTECT(val = R_MakeExternalPtr(tb, Rf_install("UserDefinedDatabase"), + R_NilValue)); + PROTECT(klass = Rf_mkString("UserDefinedDatabase")); + Rf_setAttrib(val, R_ClassSymbol, klass); UNPROTECT(2); /* val, klass */ - + #ifdef LOOKUP_DEBUG - Rprintf( "\n" ); + Rprintf("\n"); #endif Rcpp::Function fun("attach"); int pos = Rcpp::as(possexp); - fun(val, Rcpp::Named("pos")=pos, Rcpp::Named("name")="RProtoBuf:DescriptorPool"); + fun(val, Rcpp::Named("pos") = pos, + Rcpp::Named("name") = "RProtoBuf:DescriptorPool"); - return(val); + return (val); } - - -} // namespace rprotobuf - +} // namespace rprotobuf Modified: pkg/src/streams.cpp =================================================================== --- pkg/src/streams.cpp 2013-12-30 20:34:10 UTC (rev 637) +++ pkg/src/streams.cpp 2013-12-30 20:38:38 UTC (rev 638) @@ -6,246 +6,251 @@ /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ -namespace rprotobuf{ +namespace rprotobuf { - void ZeroCopyInputStreamWrapper_finalizer( SEXP xp){ - delete (ZeroCopyInputStreamWrapper*)XPP(xp) ; - } - void ZeroCopyOutputStreamWrapper_finalizer( SEXP xp){ - delete (ZeroCopyOutputStreamWrapper*)XPP(xp) ; - } +void ZeroCopyInputStreamWrapper_finalizer(SEXP xp) { + delete (ZeroCopyInputStreamWrapper*)XPP(xp); +} +void ZeroCopyOutputStreamWrapper_finalizer(SEXP xp) { + delete (ZeroCopyOutputStreamWrapper*)XPP(xp); +} - - // {{{ input streams - - // {{{ FileInputStream - SEXP FileInputStream_new( SEXP filename, SEXP block_size, SEXP close_on_delete){ - - NEW_S4_OBJECT("FileInputStream") ; - int fd = open( CHAR(STRING_ELT(filename, 0 )), O_RDONLY | O_BINARY) ; - - GPB::io::FileInputStream* stream = - new GPB::io::FileInputStream( fd, INTEGER(block_size)[0] ) ; - stream->SetCloseOnDelete( LOGICAL(close_on_delete)[0] ) ; - ZeroCopyInputStreamWrapper* wrapper = new ZeroCopyInputStreamWrapper(stream) ; - - SEXP ptr = PROTECT( - R_MakeExternalPtr( (void*)wrapper, R_NilValue, R_NilValue)); - R_RegisterCFinalizerEx( ptr, ZeroCopyInputStreamWrapper_finalizer , _FALSE_ ) ; - SET_SLOT( oo, Rf_install("pointer"), ptr ) ; - - UNPROTECT(2); /* oo, ptr */ - return oo ; - } - SEXP FileInputStream_GetErrno( SEXP xp ){ - GPB::io::FileInputStream* stream = GET_FIS(xp); - return Rf_ScalarInteger( stream->GetErrno() ) ; - } - SEXP FileInputStream_SetCloseOnDelete( SEXP xp, SEXP close ){ - GPB::io::FileInputStream* stream = GET_FIS(xp); - stream->SetCloseOnDelete( LOGICAL(close) ) ; - return R_NilValue ; - } - - SEXP FileInputStream_Close( SEXP xp ){ - GPB::io::FileInputStream* stream = GET_FIS(xp); - bool res = stream->Close() ; - return Rf_ScalarLogical( res ? _TRUE_ : _FALSE_ ) ; - } - // }}} - // {{{ ConnectionInputStream - SEXP ConnectionInputStream_new( SEXP con, SEXP was_open){ - NEW_S4_OBJECT( "ConnectionInputStream" ) ; - ConnectionInputStream* stream = - new ConnectionInputStream( con, (bool)LOGICAL(was_open)[0] ) ; - ZeroCopyInputStreamWrapper* wrapper = new ZeroCopyInputStreamWrapper(stream); - SEXP ptr = PROTECT( - R_MakeExternalPtr( (void*)wrapper, R_NilValue, con) ); - R_RegisterCFinalizerEx( ptr, ZeroCopyInputStreamWrapper_finalizer , _FALSE_ ) ; - SET_SLOT( oo, Rf_install("pointer"), ptr ) ; - - UNPROTECT(2); /* oo, ptr */ - return oo ; - } - // }}} - // }}} - - // {{{ output streams - // {{{ ZeroCopyOutputStream - SEXP ZeroCopyOutputStream_Next( SEXP xp, SEXP payload){ - GPB::io::ZeroCopyOutputStream* stream = GET_ZCOS(xp) ; - void* out ; - int s = LENGTH(payload) ; - bool res = stream->Next( &out, &s ); - if( !res ){ - Rf_error( "cannot write to stream" ) ; - } - memcpy( out, RAW(payload), s ) ; - return Rf_ScalarInteger(s) ; - } - - SEXP ZeroCopyOutputStream_ByteCount(SEXP xp){ - GPB::io::ZeroCopyOutputStream* stream = GET_ZCOS(xp); - return( Rf_ScalarReal((double)stream->ByteCount())) ; - } - - SEXP ZeroCopyOutputStream_BackUp(SEXP xp, SEXP count){ - GPB::io::ZeroCopyOutputStream* stream = GET_ZCOS(xp); - int s = GET_int(count, 0) ; - stream->BackUp( s ) ; - return R_NilValue ; - } - // }}} - // {{{ ArrayOutputStream - // }}} - // {{{ FileOutputStream - SEXP FileOutputStream_new( SEXP filename, SEXP block_size, SEXP close_on_delete){ - NEW_S4_OBJECT( "FileOutputStream" ) ; - int fd = open( CHAR(STRING_ELT(filename, 0 )), - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); - - GPB::io::FileOutputStream* stream = - new GPB::io::FileOutputStream( fd, INTEGER(block_size)[0] ) ; - stream->SetCloseOnDelete( LOGICAL(close_on_delete)[0] ) ; - ZeroCopyOutputStreamWrapper* wrapper = new ZeroCopyOutputStreamWrapper(stream) ; - - SEXP ptr = PROTECT( - R_MakeExternalPtr( (void*)wrapper, R_NilValue, R_NilValue)); - R_RegisterCFinalizerEx( ptr, ZeroCopyOutputStreamWrapper_finalizer , _FALSE_ ) ; - SET_SLOT( oo, Rf_install("pointer"), ptr ) ; - - UNPROTECT(2); /* oo, ptr */ - return oo ; - } - SEXP FileOutputStream_Flush( SEXP xp ){ - GPB::io::FileOutputStream* stream = GET_FOS(xp); - bool res = stream->Flush() ; - return Rf_ScalarLogical( res ? _TRUE_ : _FALSE_ ) ; - } - SEXP FileOutputStream_Close( SEXP xp ){ - GPB::io::FileOutputStream* stream = GET_FOS(xp); - bool res = stream->Close() ; - return Rf_ScalarLogical( res ? _TRUE_ : _FALSE_ ) ; - } - SEXP FileOutputStream_GetErrno( SEXP xp ){ - GPB::io::FileOutputStream* stream = GET_FOS(xp); - return Rf_ScalarInteger( stream->GetErrno() ) ; - } - SEXP FileOutputStream_SetCloseOnDelete( SEXP xp, SEXP close ){ - GPB::io::FileOutputStream* stream = GET_FOS(xp); - stream->SetCloseOnDelete( LOGICAL(close) ) ; - return R_NilValue ; - } - // }}} - // {{{ ConnectionOutputStream - SEXP ConnectionOutputStream_new( SEXP con, SEXP was_open){ - NEW_S4_OBJECT( "ConnectionOutputStream" ) ; - ConnectionOutputStream* stream = - new ConnectionOutputStream( con, (bool)LOGICAL(was_open)[0] ) ; - ZeroCopyOutputStreamWrapper* wrapper = new ZeroCopyOutputStreamWrapper(stream) ; - /* we keep the R connection protected as long as the - external pointer is kept out of GC */ - SEXP ptr = PROTECT( R_MakeExternalPtr( (void*)wrapper, R_NilValue, con) ); - R_RegisterCFinalizerEx( ptr, ZeroCopyOutputStreamWrapper_finalizer , _FALSE_ ) ; - SET_SLOT( oo, Rf_install("pointer"), ptr ) ; - - UNPROTECT(2); /* oo, ptr */ - return oo ; - } - // }}} - - // }}} - - // {{{ Read*** functions using CodedInputStream - SEXP ZeroCopyInputStream_ReadRaw( SEXP xp, SEXP size){ - GPB::io::CodedInputStream* coded_stream = GET_CIS(xp) ; - int s = INTEGER(size)[0] ; - SEXP payload = PROTECT( Rf_allocVector(RAWSXP, s) ) ; - if( !coded_stream->ReadRaw( RAW(payload), s ) ) Rf_error("error reading raw bytes") ; - UNPROTECT(1) ; /* payload */ - return payload; - } - - SEXP ZeroCopyInputStream_ReadString( SEXP xp, SEXP size){ - GPB::io::CodedInputStream* coded_stream = GET_CIS(xp) ; - int s = INTEGER(size)[0] ; - std::string buffer("") ; - if( !coded_stream->ReadString( &buffer, s ) ) Rf_error( "error reading string" ) ; - - return Rf_mkString( buffer.c_str() ) ; - } - - SEXP ZeroCopyInputStream_ReadVarint32( SEXP xp){ - GPB::io::CodedInputStream* coded_stream = GET_CIS(xp) ; - uint32 res = 0 ; - if( !coded_stream->ReadVarint32( &res ) ) Rf_error( "error reading varint32" ) ; - return Rf_ScalarInteger( res ) ; - } - - SEXP ZeroCopyInputStream_ReadLittleEndian32( SEXP xp){ - GPB::io::CodedInputStream* coded_stream = GET_CIS(xp) ; - uint32 res = 0 ; - if( !coded_stream->ReadVarint32( &res ) ) Rf_error( "error reading little endian int32" ) ; - return Rf_ScalarInteger( res ) ; - } - - SEXP ZeroCopyInputStream_ReadLittleEndian64( SEXP xp){ - GPB::io::CodedInputStream* coded_stream = GET_CIS(xp) ; - uint64 res = 0 ; - if( !coded_stream->ReadVarint64( &res ) ) Rf_error( "error reading little endian int32" ) ; - return Rf_ScalarReal( (double)res ) ; - } - - SEXP ZeroCopyInputStream_ReadVarint64( SEXP xp){ - GPB::io::CodedInputStream* coded_stream = GET_CIS(xp) ; - uint64 res = 0 ; - if( !coded_stream->ReadVarint64( &res ) ) Rf_error( "error reading varint64" ) ; - return Rf_ScalarReal( (double)res ) ; - } - // }}} - - // {{{ Write*** functions using CodedOuputStream - SEXP ZeroCopyOutputStream_WriteRaw( SEXP xp, SEXP payload){ - GPB::io::CodedOutputStream* stream = GET_COS(xp) ; - stream->WriteRaw( RAW(payload), LENGTH(payload) ) ; - return R_NilValue ; - } - SEXP ZeroCopyOutputStream_WriteString( SEXP xp, SEXP payload){ - if( LENGTH( payload ) > 1 ){ - Rf_warning( "only the first element is used" ) ; - } - if( LENGTH( payload ) == 0 ){ - Rf_error( "need at least one element" ) ; - } - GPB::io::CodedOutputStream* stream = GET_COS(xp) ; - stream->WriteString( CHAR(STRING_ELT(payload,0) ) ); - return R_NilValue ; - } - - SEXP ZeroCopyOutputStream_WriteLittleEndian32( SEXP xp, SEXP payload ){ - GPB::io::CodedOutputStream* stream = GET_COS(xp) ; - stream->WriteLittleEndian32( GET_int32(payload,0) ); - return R_NilValue ; - } - - SEXP ZeroCopyOutputStream_WriteLittleEndian64( SEXP xp, SEXP payload ){ - GPB::io::CodedOutputStream* stream = GET_COS(xp) ; - stream->WriteLittleEndian64( GET_int64(payload,0) ); - return R_NilValue ; - } - - SEXP ZeroCopyOutputStream_WriteVarint32( SEXP xp, SEXP payload ){ - GPB::io::CodedOutputStream* stream = GET_COS(xp) ; - stream->WriteVarint32( GET_int32(payload,0) ); - return R_NilValue ; - } - - SEXP ZeroCopyOutputStream_WriteVarint64( SEXP xp, SEXP payload ){ - GPB::io::CodedOutputStream* stream = GET_COS(xp) ; - stream->WriteVarint64( GET_int64(payload,0) ); - return R_NilValue ; - } - // }}} - -} // namespace rprotobuf +// {{{ input streams +// {{{ FileInputStream +SEXP FileInputStream_new(SEXP filename, SEXP block_size, SEXP close_on_delete) { + + NEW_S4_OBJECT("FileInputStream"); + int fd = open(CHAR(STRING_ELT(filename, 0)), O_RDONLY | O_BINARY); + + GPB::io::FileInputStream* stream = + new GPB::io::FileInputStream(fd, INTEGER(block_size)[0]); + stream->SetCloseOnDelete(LOGICAL(close_on_delete)[0]); + ZeroCopyInputStreamWrapper* wrapper = + new ZeroCopyInputStreamWrapper(stream); + + SEXP ptr = + PROTECT(R_MakeExternalPtr((void*)wrapper, R_NilValue, R_NilValue)); + R_RegisterCFinalizerEx(ptr, ZeroCopyInputStreamWrapper_finalizer, _FALSE_); + SET_SLOT(oo, Rf_install("pointer"), ptr); + + UNPROTECT(2); /* oo, ptr */ + return oo; +} +SEXP FileInputStream_GetErrno(SEXP xp) { + GPB::io::FileInputStream* stream = GET_FIS(xp); + return Rf_ScalarInteger(stream->GetErrno()); +} +SEXP FileInputStream_SetCloseOnDelete(SEXP xp, SEXP close) { + GPB::io::FileInputStream* stream = GET_FIS(xp); + stream->SetCloseOnDelete(LOGICAL(close)); + return R_NilValue; +} + +SEXP FileInputStream_Close(SEXP xp) { + GPB::io::FileInputStream* stream = GET_FIS(xp); + bool res = stream->Close(); + return Rf_ScalarLogical(res ? _TRUE_ : _FALSE_); +} +// }}} +// {{{ ConnectionInputStream +SEXP ConnectionInputStream_new(SEXP con, SEXP was_open) { + NEW_S4_OBJECT("ConnectionInputStream"); + ConnectionInputStream* stream = + new ConnectionInputStream(con, (bool)LOGICAL(was_open)[0]); + ZeroCopyInputStreamWrapper* wrapper = + new ZeroCopyInputStreamWrapper(stream); + SEXP ptr = PROTECT(R_MakeExternalPtr((void*)wrapper, R_NilValue, con)); + R_RegisterCFinalizerEx(ptr, ZeroCopyInputStreamWrapper_finalizer, _FALSE_); + SET_SLOT(oo, Rf_install("pointer"), ptr); + + UNPROTECT(2); /* oo, ptr */ + return oo; +} +// }}} +// }}} + +// {{{ output streams +// {{{ ZeroCopyOutputStream +SEXP ZeroCopyOutputStream_Next(SEXP xp, SEXP payload) { + GPB::io::ZeroCopyOutputStream* stream = GET_ZCOS(xp); + void* out; + int s = LENGTH(payload); + bool res = stream->Next(&out, &s); + if (!res) { + Rf_error("cannot write to stream"); + } + memcpy(out, RAW(payload), s); + return Rf_ScalarInteger(s); +} + +SEXP ZeroCopyOutputStream_ByteCount(SEXP xp) { + GPB::io::ZeroCopyOutputStream* stream = GET_ZCOS(xp); + return (Rf_ScalarReal((double)stream->ByteCount())); +} + +SEXP ZeroCopyOutputStream_BackUp(SEXP xp, SEXP count) { + GPB::io::ZeroCopyOutputStream* stream = GET_ZCOS(xp); + int s = GET_int(count, 0); + stream->BackUp(s); + return R_NilValue; +} +// }}} +// {{{ ArrayOutputStream +// }}} +// {{{ FileOutputStream +SEXP FileOutputStream_new(SEXP filename, SEXP block_size, + SEXP close_on_delete) { + NEW_S4_OBJECT("FileOutputStream"); + int fd = open(CHAR(STRING_ELT(filename, 0)), + O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); + + GPB::io::FileOutputStream* stream = + new GPB::io::FileOutputStream(fd, INTEGER(block_size)[0]); + stream->SetCloseOnDelete(LOGICAL(close_on_delete)[0]); + ZeroCopyOutputStreamWrapper* wrapper = + new ZeroCopyOutputStreamWrapper(stream); + + SEXP ptr = + PROTECT(R_MakeExternalPtr((void*)wrapper, R_NilValue, R_NilValue)); + R_RegisterCFinalizerEx(ptr, ZeroCopyOutputStreamWrapper_finalizer, _FALSE_); + SET_SLOT(oo, Rf_install("pointer"), ptr); + + UNPROTECT(2); /* oo, ptr */ + return oo; +} +SEXP FileOutputStream_Flush(SEXP xp) { + GPB::io::FileOutputStream* stream = GET_FOS(xp); + bool res = stream->Flush(); + return Rf_ScalarLogical(res ? _TRUE_ : _FALSE_); +} +SEXP FileOutputStream_Close(SEXP xp) { + GPB::io::FileOutputStream* stream = GET_FOS(xp); + bool res = stream->Close(); + return Rf_ScalarLogical(res ? _TRUE_ : _FALSE_); +} +SEXP FileOutputStream_GetErrno(SEXP xp) { + GPB::io::FileOutputStream* stream = GET_FOS(xp); + return Rf_ScalarInteger(stream->GetErrno()); +} +SEXP FileOutputStream_SetCloseOnDelete(SEXP xp, SEXP close) { + GPB::io::FileOutputStream* stream = GET_FOS(xp); + stream->SetCloseOnDelete(LOGICAL(close)); + return R_NilValue; +} +// }}} +// {{{ ConnectionOutputStream +SEXP ConnectionOutputStream_new(SEXP con, SEXP was_open) { + NEW_S4_OBJECT("ConnectionOutputStream"); + ConnectionOutputStream* stream = + new ConnectionOutputStream(con, (bool)LOGICAL(was_open)[0]); + ZeroCopyOutputStreamWrapper* wrapper = + new ZeroCopyOutputStreamWrapper(stream); + /* we keep the R connection protected as long as the + external pointer is kept out of GC */ + SEXP ptr = PROTECT(R_MakeExternalPtr((void*)wrapper, R_NilValue, con)); + R_RegisterCFinalizerEx(ptr, ZeroCopyOutputStreamWrapper_finalizer, _FALSE_); + SET_SLOT(oo, Rf_install("pointer"), ptr); + + UNPROTECT(2); /* oo, ptr */ + return oo; +} +// }}} + +// }}} + +// {{{ Read*** functions using CodedInputStream +SEXP ZeroCopyInputStream_ReadRaw(SEXP xp, SEXP size) { + GPB::io::CodedInputStream* coded_stream = GET_CIS(xp); + int s = INTEGER(size)[0]; + SEXP payload = PROTECT(Rf_allocVector(RAWSXP, s)); + if (!coded_stream->ReadRaw(RAW(payload), s)) + Rf_error("error reading raw bytes"); + UNPROTECT(1); /* payload */ + return payload; +} + +SEXP ZeroCopyInputStream_ReadString(SEXP xp, SEXP size) { + GPB::io::CodedInputStream* coded_stream = GET_CIS(xp); + int s = INTEGER(size)[0]; + std::string buffer(""); + if (!coded_stream->ReadString(&buffer, s)) Rf_error("error reading string"); + + return Rf_mkString(buffer.c_str()); +} + +SEXP ZeroCopyInputStream_ReadVarint32(SEXP xp) { + GPB::io::CodedInputStream* coded_stream = GET_CIS(xp); + uint32 res = 0; + if (!coded_stream->ReadVarint32(&res)) Rf_error("error reading varint32"); + return Rf_ScalarInteger(res); +} + +SEXP ZeroCopyInputStream_ReadLittleEndian32(SEXP xp) { + GPB::io::CodedInputStream* coded_stream = GET_CIS(xp); + uint32 res = 0; + if (!coded_stream->ReadVarint32(&res)) + Rf_error("error reading little endian int32"); + return Rf_ScalarInteger(res); +} + +SEXP ZeroCopyInputStream_ReadLittleEndian64(SEXP xp) { + GPB::io::CodedInputStream* coded_stream = GET_CIS(xp); + uint64 res = 0; + if (!coded_stream->ReadVarint64(&res)) + Rf_error("error reading little endian int32"); + return Rf_ScalarReal((double)res); +} + +SEXP ZeroCopyInputStream_ReadVarint64(SEXP xp) { + GPB::io::CodedInputStream* coded_stream = GET_CIS(xp); + uint64 res = 0; + if (!coded_stream->ReadVarint64(&res)) Rf_error("error reading varint64"); + return Rf_ScalarReal((double)res); +} +// }}} + +// {{{ Write*** functions using CodedOuputStream +SEXP ZeroCopyOutputStream_WriteRaw(SEXP xp, SEXP payload) { + GPB::io::CodedOutputStream* stream = GET_COS(xp); + stream->WriteRaw(RAW(payload), LENGTH(payload)); + return R_NilValue; +} +SEXP ZeroCopyOutputStream_WriteString(SEXP xp, SEXP payload) { + if (LENGTH(payload) > 1) { + Rf_warning("only the first element is used"); + } + if (LENGTH(payload) == 0) { + Rf_error("need at least one element"); + } + GPB::io::CodedOutputStream* stream = GET_COS(xp); + stream->WriteString(CHAR(STRING_ELT(payload, 0))); + return R_NilValue; +} + +SEXP ZeroCopyOutputStream_WriteLittleEndian32(SEXP xp, SEXP payload) { + GPB::io::CodedOutputStream* stream = GET_COS(xp); + stream->WriteLittleEndian32(GET_int32(payload, 0)); + return R_NilValue; +} + +SEXP ZeroCopyOutputStream_WriteLittleEndian64(SEXP xp, SEXP payload) { + GPB::io::CodedOutputStream* stream = GET_COS(xp); + stream->WriteLittleEndian64(GET_int64(payload, 0)); + return R_NilValue; +} + +SEXP ZeroCopyOutputStream_WriteVarint32(SEXP xp, SEXP payload) { + GPB::io::CodedOutputStream* stream = GET_COS(xp); + stream->WriteVarint32(GET_int32(payload, 0)); + return R_NilValue; +} + +SEXP ZeroCopyOutputStream_WriteVarint64(SEXP xp, SEXP payload) { + GPB::io::CodedOutputStream* stream = GET_COS(xp); + stream->WriteVarint64(GET_int64(payload, 0)); + return R_NilValue; +} +// }}} + +} // namespace rprotobuf From noreply at r-forge.r-project.org Mon Dec 30 21:42:32 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 21:42:32 +0100 (CET) Subject: [Rprotobuf-commits] r639 - pkg/src Message-ID: <20131230204233.0178A185F66@r-forge.r-project.org> Author: murray Date: 2013-12-30 21:42:32 +0100 (Mon, 30 Dec 2013) New Revision: 639 Modified: pkg/src/rprotobuf.cpp Log: Whitespace change only (clang-format) * Consistently wrap at 80 chars. * Consistently place '{' with case statement. * 4 char indents. * Remove unneeded whitespace at end of line, and unneeded blank lines. Modified: pkg/src/rprotobuf.cpp =================================================================== --- pkg/src/rprotobuf.cpp 2013-12-30 20:38:38 UTC (rev 638) +++ pkg/src/rprotobuf.cpp 2013-12-30 20:42:32 UTC (rev 639) @@ -1,54 +1,58 @@ #include "rprotobuf.h" -#include "DescriptorPoolLookup.h" +#include "DescriptorPoolLookup.h" #include "RcppMacros.h" -namespace rprotobuf{ +namespace rprotobuf { - GPB::Message* PROTOTYPE( const GPB::Descriptor* desc){ +GPB::Message* PROTOTYPE(const GPB::Descriptor* desc) { #ifdef RPB_DEBUG - Rprintf( "\n" ) ; - Rprintf( "desc = %d\n", desc ) ; + Rprintf("\n"); + Rprintf("desc = %d\n", desc); #endif - /* first try the runtime factory */ - GPB::Message* m = (GPB::Message*)((GPB::DynamicMessageFactory*)DescriptorPoolLookup::factory())->GetPrototype( desc )->New() ; - + /* first try the runtime factory */ + GPB::Message* m = (GPB::Message*)((GPB::DynamicMessageFactory*) + DescriptorPoolLookup::factory()) + ->GetPrototype(desc) + ->New(); + #ifdef RPB_DEBUG - Rprintf( "generated factory = %d\n", m ) ; -#endif - if( !m ){ - /* then the dynamic runtime factory */ - m = (GPB::Message*)GPB::MessageFactory::generated_factory()->GetPrototype( desc )->New() ; + Rprintf("generated factory = %d\n", m); +#endif + if (!m) { + /* then the dynamic runtime factory */ + m = (GPB::Message*)GPB::MessageFactory::generated_factory() + ->GetPrototype(desc) + ->New(); #ifdef RPB_DEBUG - Rprintf( "runtime factory = %d\n", m ) ; -#endif - } - return m ; - } - - - GPB::Message* CLONE(const GPB::Message* origin){ + Rprintf("runtime factory = %d\n", m); +#endif + } + return m; +} + +GPB::Message* CLONE(const GPB::Message* origin) { #ifdef RPB_DEBUG - Rprintf( "" ) ; -#endif - - const GPB::Descriptor* desc = origin->GetDescriptor() ; - GPB::Message* sheep = PROTOTYPE( desc ) ; - sheep->CopyFrom(*origin) ; + Rprintf(""); +#endif + const GPB::Descriptor* desc = origin->GetDescriptor(); + GPB::Message* sheep = PROTOTYPE(desc); + sheep->CopyFrom(*origin); + #ifdef RPB_DEBUG - Rprintf( "" ) ; -#endif - return sheep ; - } - + Rprintf(""); +#endif + return sheep; +} + /** * read a proto file and cache the message definitions it contains * * @param file proto file name */ -SEXP readProtoFiles( SEXP file, SEXP dirs ){ - DescriptorPoolLookup::importProtoFiles( file, dirs ) ; - return R_NilValue ; +SEXP readProtoFiles(SEXP file, SEXP dirs) { + DescriptorPoolLookup::importProtoFiles(file, dirs); + return R_NilValue; } /** @@ -56,35 +60,34 @@ * * @param type message type * - * @return an S4 object of class Descriptor, or NULL if the type + * @return an S4 object of class Descriptor, or NULL if the type * is unknown */ -SEXP getProtobufDescriptor( SEXP type ){ +SEXP getProtobufDescriptor(SEXP type) { #ifdef RPB_DEBUG -Rprintf( "\n type = " ) ; -Rf_PrintValue( type ) ; + Rprintf("\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::Descriptor* desc = pool->FindMessageTypeByName( typeName ) ; - if( !desc ){ - /* then try the "runtime" pool" */ - pool = DescriptorPoolLookup::pool() ; - desc = pool->FindMessageTypeByName( typeName ) ; - if( !desc ){ - /* unlucky */ - return R_NilValue ; - } - } - - return( S4_Descriptor( desc ) ) ; + + const char* typeName = CHAR(STRING_ELT(type, 0)); + + /* first try the generated pool */ + const GPB::DescriptorPool* pool = GPB::DescriptorPool::generated_pool(); + const GPB::Descriptor* desc = pool->FindMessageTypeByName(typeName); + if (!desc) { + /* then try the "runtime" pool" */ + pool = DescriptorPoolLookup::pool(); + desc = pool->FindMessageTypeByName(typeName); + if (!desc) { + /* unlucky */ + return R_NilValue; + } + } + + return (S4_Descriptor(desc)); } - /** * get the descriptor associated with an extension * @@ -93,28 +96,28 @@ * @return an S4 object of class FieldDescriptor, or NULL if the type * is unknown */ -SEXP getExtensionDescriptor( SEXP type ){ +SEXP getExtensionDescriptor(SEXP type) { #ifdef RPB_DEBUG -Rprintf( "\n type = " ) ; -Rf_PrintValue( type ) ; + Rprintf("\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 ) ) ; + + 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)); } /** @@ -122,33 +125,33 @@ * * @param descriptor a "Descriptor" R object */ -SEXP newProtoMessage( SEXP descriptor ){ - BEGIN_RCPP +SEXP newProtoMessage(SEXP descriptor) { + BEGIN_RCPP #ifdef RPB_DEBUG -Rprintf( "\n" ) ; - /* FIXME: the message type, we don't really need that*/ - SEXP type = GET_SLOT( descriptor, Rf_install("type") ) ; + Rprintf("\n"); + /* FIXME: the message type, we don't really need that*/ + SEXP type = GET_SLOT(descriptor, Rf_install("type")); #endif - - /* the pointer to the c++ descriptor object */ - GPB::Descriptor* desc = GET_DESCRIPTOR_POINTER_FROM_S4( descriptor ); - + + /* the pointer to the c++ descriptor object */ + GPB::Descriptor* desc = GET_DESCRIPTOR_POINTER_FROM_S4(descriptor); + #ifdef RPB_DEBUG -Rprintf( "desc = %d\n", desc ) ; -PRINT_DEBUG_INFO( "type", type ) ; + Rprintf("desc = %d\n", desc); + PRINT_DEBUG_INFO("type", type); #endif - - /* grab the Message from the factory */ - const GPB::Message* message = PROTOTYPE( desc ) ; - if( !message ){ - Rcpp_error("could not call factory->GetPrototype(desc)->New()"); - } + + /* grab the Message from the factory */ + const GPB::Message* message = PROTOTYPE(desc); + if (!message) { + Rcpp_error("could not call factory->GetPrototype(desc)->New()"); + } #ifdef RPB_DEBUG -Rprintf( "\n" ) ; + Rprintf("\n"); #endif - - return( S4_Message( message ) ) ; - END_RCPP + + return (S4_Message(message)); + END_RCPP } /** @@ -158,119 +161,120 @@ * @param pointer external pointer to a google::protobuf::Descriptor object * @param name name of the thing to extract */ -SEXP do_dollar_Descriptor( SEXP pointer, SEXP name ){ - - const char * what = CHAR( STRING_ELT( name, 0 ) ) ; - GPB::Descriptor * desc = (GPB::Descriptor*) EXTPTR_PTR(pointer) ; - - // trying fields first : - - if( desc->field_count() ){ - const GPB::FieldDescriptor* fd = desc->FindFieldByName(what) ; - if( fd ){ - return( S4_FieldDescriptor(fd ) ) ; - } - } - - // now trying nested types - if( desc->nested_type_count() ){ - const GPB::Descriptor* d = desc->FindNestedTypeByName(what) ; - if( d ){ - return( S4_Descriptor( d ) ) ; - } - } - - // now for enum types - if( desc->enum_type_count() ){ - const GPB::EnumDescriptor* ed = desc->FindEnumTypeByName(what) ; - if( ed ){ - return( S4_EnumDescriptor( ed ) ) ; - } - } - - - // TODO: extensions (later) - - // give up - // TODO: should this be unbound instead - return( R_NilValue ); +SEXP do_dollar_Descriptor(SEXP pointer, SEXP name) { + + const char* what = CHAR(STRING_ELT(name, 0)); + GPB::Descriptor* desc = (GPB::Descriptor*)EXTPTR_PTR(pointer); + + // trying fields first : + + if (desc->field_count()) { + const GPB::FieldDescriptor* fd = desc->FindFieldByName(what); + if (fd) { + return (S4_FieldDescriptor(fd)); + } + } + + // now trying nested types + if (desc->nested_type_count()) { + const GPB::Descriptor* d = desc->FindNestedTypeByName(what); + if (d) { + return (S4_Descriptor(d)); + } + } + + // now for enum types + if (desc->enum_type_count()) { + const GPB::EnumDescriptor* ed = desc->FindEnumTypeByName(what); + if (ed) { + return (S4_EnumDescriptor(ed)); + } + } + + // TODO: extensions (later) + + // give up + // TODO: should this be unbound instead + return (R_NilValue); } -/** +/** * - * @param m potentially a message + * @param m potentially a message * @param target the expected type * * @return TRUE if m is a a message of the given type - */ -Rboolean isMessage( SEXP m, const char* target ){ + */ +Rboolean isMessage(SEXP m, const char* target) { #ifdef RPB_DEBUG -Rprintf( "\n" ) ; + Rprintf("\n"); #endif - if( TYPEOF(m) != S4SXP || !Rf_inherits( m, "Message") ) return _FALSE_ ; - - GPB::Message* message = (GPB::Message*) EXTPTR_PTR( GET_SLOT( m, Rf_install("pointer") ) ); - - const char* type = message->GetDescriptor()->full_name().c_str() ; - if( strcmp( type, target) ){ - return _FALSE_ ; - } + if (TYPEOF(m) != S4SXP || !Rf_inherits(m, "Message")) return _FALSE_; - return _TRUE_ ; -} + GPB::Message* message = + (GPB::Message*)EXTPTR_PTR(GET_SLOT(m, Rf_install("pointer"))); + const char* type = message->GetDescriptor()->full_name().c_str(); + if (strcmp(type, target)) { + return _FALSE_; + } -GPB::FieldDescriptor* getFieldDescriptor(GPB::Message* message, SEXP name){ - GPB::FieldDescriptor* field_desc = (GPB::FieldDescriptor*)0; - BEGIN_RCPP - const GPB::Descriptor* desc = message->GetDescriptor() ; - std::string error_message = "could not get FieldDescriptor for field"; - switch( TYPEOF(name) ){ - case S4SXP: - { - if (Rf_inherits( name, "FieldDescriptor") ){ - field_desc = GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(name); - } else { - Rcpp::stop("S4 class is not a FieldDescriptor"); - } - break ; - } - case CHARSXP: - { - field_desc = (GPB::FieldDescriptor*)desc->FindFieldByName( CHAR(name) ) ; - error_message = error_message + " '" + CHAR(name) + "'"; - break ; - } - case STRSXP: - { - field_desc = (GPB::FieldDescriptor*)desc->FindFieldByName( CHAR( STRING_ELT(name, 0 ) ) ) ; - error_message = error_message + " '" + CHAR( STRING_ELT(name, 0 )) + "'"; - break ; - } - case REALSXP: - case INTSXP: - { - field_desc = (GPB::FieldDescriptor*)desc->FindFieldByNumber( Rcpp::as( name ) ) ; - break ; - } - } - if( !field_desc ){ - Rcpp::stop(error_message.c_str()); - } - return field_desc ; - VOID_END_RCPP - return field_desc ; + return _TRUE_; } -RPB_FUNCTION_VOID_1( check_libprotobuf_version, int minversion ){ - if( GOOGLE_PROTOBUF_VERSION < minversion ){ - throw std::range_error( "The protobuf library you are using is too old for this package, please upgrade" ) ; - } +GPB::FieldDescriptor* getFieldDescriptor(GPB::Message* message, SEXP name) { + GPB::FieldDescriptor* field_desc = (GPB::FieldDescriptor*)0; + BEGIN_RCPP + const GPB::Descriptor* desc = message->GetDescriptor(); + std::string error_message = "could not get FieldDescriptor for field"; + switch (TYPEOF(name)) { + case S4SXP: { + if (Rf_inherits(name, "FieldDescriptor")) { + field_desc = GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(name); + } else { + Rcpp::stop("S4 class is not a FieldDescriptor"); + } + break; + } + case CHARSXP: { + field_desc = + (GPB::FieldDescriptor*)desc->FindFieldByName(CHAR(name)); + error_message = error_message + " '" + CHAR(name) + "'"; + break; + } + case STRSXP: { + field_desc = (GPB::FieldDescriptor*)desc->FindFieldByName( + CHAR(STRING_ELT(name, 0))); + error_message = + error_message + " '" + CHAR(STRING_ELT(name, 0)) + "'"; + break; + } + case REALSXP: + case INTSXP: { + field_desc = (GPB::FieldDescriptor*)desc->FindFieldByNumber( + Rcpp::as(name)); + break; + } + } + if (!field_desc) { + Rcpp::stop(error_message.c_str()); + } + return field_desc; + VOID_END_RCPP + return field_desc; } -RPB_FUNCTION_0(int, get_protobuf_library_version){ - return GOOGLE_PROTOBUF_VERSION; +RPB_FUNCTION_VOID_1(check_libprotobuf_version, int minversion) { + if (GOOGLE_PROTOBUF_VERSION < minversion) { + throw std::range_error( + "The protobuf library you are using is too old for this package, " + "please upgrade"); + } } -} // namespace rprotobuf +RPB_FUNCTION_0(int, get_protobuf_library_version) { + return GOOGLE_PROTOBUF_VERSION; +} + +} // namespace rprotobuf From noreply at r-forge.r-project.org Mon Dec 30 21:49:18 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 21:49:18 +0100 (CET) Subject: [Rprotobuf-commits] r640 - pkg/src Message-ID: <20131230204918.96EFE186970@r-forge.r-project.org> Author: murray Date: 2013-12-30 21:49:17 +0100 (Mon, 30 Dec 2013) New Revision: 640 Modified: pkg/src/DescriptorPoolLookup.h pkg/src/connections.h pkg/src/fieldtypes.h Log: whitespace change only. clang-format. Modified: pkg/src/DescriptorPoolLookup.h =================================================================== --- pkg/src/DescriptorPoolLookup.h 2013-12-30 20:42:32 UTC (rev 639) +++ pkg/src/DescriptorPoolLookup.h 2013-12-30 20:49:17 UTC (rev 640) @@ -4,31 +4,30 @@ #include "RSourceTree.h" #include "RWarningErrorCollector.h" -namespace rprotobuf{ +namespace rprotobuf { - class DescriptorPoolLookup { - public: - static void add( const std::string& element) ; - - static bool contains( const std::string& element) ; - - static SEXP getElements() ; - - static void importProtoFiles( SEXP files, SEXP cwd ) ; - - static const GPB::DescriptorPool* pool() ; - - static const GPB::DynamicMessageFactory* factory() ; - - private: - - static std::set elements ; - static RWarningErrorCollector error_collector ; - static RSourceTree source_tree ; - static GPB::compiler::Importer importer ; - static GPB::DynamicMessageFactory message_factory ; -} ; +class DescriptorPoolLookup { + public: + static void add(const std::string& element); -} // namespace rprotobuf + static bool contains(const std::string& element); + static SEXP getElements(); + + static void importProtoFiles(SEXP files, SEXP cwd); + + static const GPB::DescriptorPool* pool(); + + static const GPB::DynamicMessageFactory* factory(); + + private: + static std::set elements; + static RWarningErrorCollector error_collector; + static RSourceTree source_tree; + static GPB::compiler::Importer importer; + static GPB::DynamicMessageFactory message_factory; +}; + +} // namespace rprotobuf + #endif Modified: pkg/src/connections.h =================================================================== --- pkg/src/connections.h 2013-12-30 20:42:32 UTC (rev 639) +++ pkg/src/connections.h 2013-12-30 20:49:17 UTC (rev 640) @@ -5,12 +5,11 @@ // struct Rconn { // char* class; // char mode[5]; -// Rboolean text, isopen, incomplete, canread, canwrite, canseek, blocking, isGzcon; +// Rboolean text, isopen, incomplete, canread, canwrite, canseek, blocking, +// isGzcon; // int (*fgetc)(struct Rconn *); // size_t (*read)(void *, size_t, size_t, struct Rconn *); // size_t (*write)(const void *, size_t, size_t, struct Rconn *); // }; - - #endif Modified: pkg/src/fieldtypes.h =================================================================== --- pkg/src/fieldtypes.h 2013-12-30 20:42:32 UTC (rev 639) +++ pkg/src/fieldtypes.h 2013-12-30 20:49:17 UTC (rev 640) @@ -1,39 +1,38 @@ #ifndef FIELD_TYPES_H #define FIELD_TYPES_H -using namespace google::protobuf ; +using namespace google::protobuf; -#define TYPE_DOUBLE FieldDescriptor::TYPE_DOUBLE -#define TYPE_FLOAT FieldDescriptor::TYPE_FLOAT -#define TYPE_INT64 FieldDescriptor::TYPE_INT64 -#define TYPE_UINT64 FieldDescriptor::TYPE_UINT64 -#define TYPE_INT32 FieldDescriptor::TYPE_INT32 -#define TYPE_FIXED64 FieldDescriptor::TYPE_FIXED64 -#define TYPE_FIXED32 FieldDescriptor::TYPE_FIXED32 -#define TYPE_BOOL FieldDescriptor::TYPE_BOOL -#define TYPE_STRING FieldDescriptor::TYPE_STRING -#define TYPE_GROUP FieldDescriptor::TYPE_GROUP -#define TYPE_MESSAGE FieldDescriptor::TYPE_MESSAGE -#define TYPE_BYTES FieldDescriptor::TYPE_BYTES -#define TYPE_UINT32 FieldDescriptor::TYPE_UINT32 -#define TYPE_ENUM FieldDescriptor::TYPE_ENUM +#define TYPE_DOUBLE FieldDescriptor::TYPE_DOUBLE +#define TYPE_FLOAT FieldDescriptor::TYPE_FLOAT +#define TYPE_INT64 FieldDescriptor::TYPE_INT64 +#define TYPE_UINT64 FieldDescriptor::TYPE_UINT64 +#define TYPE_INT32 FieldDescriptor::TYPE_INT32 +#define TYPE_FIXED64 FieldDescriptor::TYPE_FIXED64 +#define TYPE_FIXED32 FieldDescriptor::TYPE_FIXED32 +#define TYPE_BOOL FieldDescriptor::TYPE_BOOL +#define TYPE_STRING FieldDescriptor::TYPE_STRING +#define TYPE_GROUP FieldDescriptor::TYPE_GROUP +#define TYPE_MESSAGE FieldDescriptor::TYPE_MESSAGE +#define TYPE_BYTES FieldDescriptor::TYPE_BYTES +#define TYPE_UINT32 FieldDescriptor::TYPE_UINT32 +#define TYPE_ENUM FieldDescriptor::TYPE_ENUM #define TYPE_SFIXED32 FieldDescriptor::TYPE_SFIXED32 #define TYPE_SFIXED64 FieldDescriptor::TYPE_SFIXED64 -#define TYPE_SINT32 FieldDescriptor::TYPE_SINT32 -#define TYPE_SINT64 FieldDescriptor::TYPE_SINT64 -#define MAX_TYPE FieldDescriptor::MAX_TYPE +#define TYPE_SINT32 FieldDescriptor::TYPE_SINT32 +#define TYPE_SINT64 FieldDescriptor::TYPE_SINT64 +#define MAX_TYPE FieldDescriptor::MAX_TYPE -#define CPPTYPE_INT32 FieldDescriptor::CPPTYPE_INT32 -#define CPPTYPE_INT64 FieldDescriptor::CPPTYPE_INT64 -#define CPPTYPE_UINT32 FieldDescriptor::CPPTYPE_UINT32 -#define CPPTYPE_UINT64 FieldDescriptor::CPPTYPE_UINT64 -#define CPPTYPE_DOUBLE FieldDescriptor::CPPTYPE_DOUBLE -#define CPPTYPE_FLOAT FieldDescriptor::CPPTYPE_FLOAT -#define CPPTYPE_BOOL FieldDescriptor::CPPTYPE_BOOL -#define CPPTYPE_ENUM FieldDescriptor::CPPTYPE_ENUM -#define CPPTYPE_STRING FieldDescriptor::CPPTYPE_STRING +#define CPPTYPE_INT32 FieldDescriptor::CPPTYPE_INT32 +#define CPPTYPE_INT64 FieldDescriptor::CPPTYPE_INT64 +#define CPPTYPE_UINT32 FieldDescriptor::CPPTYPE_UINT32 +#define CPPTYPE_UINT64 FieldDescriptor::CPPTYPE_UINT64 +#define CPPTYPE_DOUBLE FieldDescriptor::CPPTYPE_DOUBLE +#define CPPTYPE_FLOAT FieldDescriptor::CPPTYPE_FLOAT +#define CPPTYPE_BOOL FieldDescriptor::CPPTYPE_BOOL +#define CPPTYPE_ENUM FieldDescriptor::CPPTYPE_ENUM +#define CPPTYPE_STRING FieldDescriptor::CPPTYPE_STRING #define CPPTYPE_MESSAGE FieldDescriptor::CPPTYPE_MESSAGE -#define MAX_CPPTYPE FieldDescriptor::MAX_CPPTYPE +#define MAX_CPPTYPE FieldDescriptor::MAX_CPPTYPE - #endif From noreply at r-forge.r-project.org Mon Dec 30 21:55:14 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 21:55:14 +0100 (CET) Subject: [Rprotobuf-commits] r641 - pkg/src Message-ID: <20131230205514.CC7991869C4@r-forge.r-project.org> Author: murray Date: 2013-12-30 21:55:14 +0100 (Mon, 30 Dec 2013) New Revision: 641 Modified: pkg/src/RWarningErrorCollector.h pkg/src/S4_classes.h pkg/src/SocketCopyingInputStream.h Log: whitespace change only -- clang-format * Don't indent from the namespace {} level. * Use consistent indentation. * Wrap at 80chars. Modified: pkg/src/RWarningErrorCollector.h =================================================================== --- pkg/src/RWarningErrorCollector.h 2013-12-30 20:49:17 UTC (rev 640) +++ pkg/src/RWarningErrorCollector.h 2013-12-30 20:55:14 UTC (rev 641) @@ -2,13 +2,11 @@ namespace rprotobuf { - class RWarningErrorCollector : public GPB::compiler::MultiFileErrorCollector { - public: - - // implements ErrorCollector --------------------------------------- - void AddError(const std::string& filename, int line, int column, - const std::string& message) ; - -} ; +class RWarningErrorCollector : public GPB::compiler::MultiFileErrorCollector { + public: + // implements ErrorCollector --------------------------------------- + void AddError(const std::string& filename, int line, int column, + const std::string& message); +}; -} // namespace rprotobuf +} // namespace rprotobuf Modified: pkg/src/S4_classes.h =================================================================== --- pkg/src/S4_classes.h 2013-12-30 20:49:17 UTC (rev 640) +++ pkg/src/S4_classes.h 2013-12-30 20:55:14 UTC (rev 641) @@ -24,210 +24,204 @@ namespace rprotobuf { - class S4_EnumValueDescriptor : public Rcpp::S4 { - public: - S4_EnumValueDescriptor( const GPB::EnumValueDescriptor* d) : S4("EnumValueDescriptor"){ - - if( d ){ - slot( "pointer" ) = Rcpp::XPtr( - const_cast(d), false) ; - slot( "name" ) = d->name() ; - slot( "full_name") = d->full_name() ; - } else{ - setSEXP( R_NilValue ); - } - } - - S4_EnumValueDescriptor( const S4_EnumValueDescriptor& other) : S4(){ - setSEXP( other.asSexp() ); - } - S4_EnumValueDescriptor& operator=( const S4_EnumValueDescriptor& other){ - setSEXP( other.asSexp() ); - return *this ; - } - - } ; - - - class S4_Descriptor : public Rcpp::S4 { - public: - S4_Descriptor( const GPB::Descriptor* d) : S4( "Descriptor" ){ - slot( "pointer" ) = Rcpp::XPtr( - const_cast(d), false) ; - if (!d) { - slot( "type" ) = Rcpp::StringVector(0) ; - } else { - slot( "type" ) = d->full_name() ; - } - } - - S4_Descriptor( const S4_Descriptor& other) : S4(){ - setSEXP( other.asSexp() ); - } - S4_Descriptor& operator=( const S4_Descriptor& other){ - setSEXP( other.asSexp() ); - return *this ; - } - } ; - - class S4_FileDescriptor : public Rcpp::S4 { - public: - S4_FileDescriptor( const GPB::FileDescriptor* d) : S4( "FileDescriptor" ){ - slot( "pointer" ) = Rcpp::XPtr( - const_cast(d), false) ; - if (!d) { - slot ( "package" ) = Rcpp::StringVector(0); - slot ( "filename" ) = Rcpp::StringVector(0); - } else { - slot ( "package" ) = d->package(); - slot ( "filename" ) = d->name(); - } - } - - S4_FileDescriptor( const S4_FileDescriptor& other) : S4(){ - setSEXP( other.asSexp() ); - } - S4_FileDescriptor& operator=( const S4_FileDescriptor& other){ - setSEXP( other.asSexp() ); - return *this ; - } - } ; - - - class S4_FieldDescriptor : public Rcpp::S4 { - public: - S4_FieldDescriptor( const GPB::FieldDescriptor* d) : S4( "FieldDescriptor" ){ - slot( "pointer" ) = Rcpp::XPtr( - const_cast(d), false) ; - slot( "name" ) = d->name() ; - slot( "full_name" ) = d->full_name() ; - slot( "type" ) = d->containing_type()->full_name() ; - } - - S4_FieldDescriptor( const S4_FieldDescriptor& other) : S4(){ - setSEXP( other.asSexp() ); - } - S4_FieldDescriptor& operator=( const S4_FieldDescriptor& other){ - setSEXP( other.asSexp() ); - return *this ; - } - } ; - +class S4_EnumValueDescriptor : public Rcpp::S4 { + public: + S4_EnumValueDescriptor(const GPB::EnumValueDescriptor* d) + : S4("EnumValueDescriptor") { - class S4_ServiceDescriptor : public Rcpp::S4 { - public: - S4_ServiceDescriptor( const GPB::ServiceDescriptor* d) : S4( "ServiceDescriptor" ){ - slot( "pointer" ) = Rcpp::XPtr( - const_cast(d), false) ; - } - - S4_ServiceDescriptor( const S4_ServiceDescriptor& other) : S4(){ - setSEXP( other.asSexp() ); - } - S4_ServiceDescriptor& operator=( const S4_ServiceDescriptor& other){ - setSEXP( other.asSexp() ); - return *this ; - } - } ; - - class S4_MethodDescriptor : public Rcpp::S4 { - public: - S4_MethodDescriptor( const GPB::MethodDescriptor* d) : S4( "MethodDescriptor" ){ - slot( "pointer" ) = Rcpp::XPtr( - const_cast(d), false) ; - } - - S4_MethodDescriptor( const S4_MethodDescriptor& other) : S4(){ - setSEXP( other.asSexp() ); - } - S4_MethodDescriptor& operator=( const S4_MethodDescriptor& other){ - setSEXP( other.asSexp() ); - return *this ; - } - } ; - - class S4_EnumDescriptor : public Rcpp::S4 { - public: - S4_EnumDescriptor( const GPB::EnumDescriptor* d) : S4( "EnumDescriptor" ){ - slot( "pointer" ) = Rcpp::XPtr( - const_cast(d), false) ; - slot( "type" ) = Rcpp::StringVector(0) ; - if (d) { - slot( "name" ) = d->name() ; - slot( "full_name") = d->full_name() ; - const GPB::Descriptor *type_desc = d->containing_type() ; - if( type_desc ){ - slot( "type" ) = type_desc->full_name() ; - } - } else { - slot( "name" ) = Rcpp::StringVector(0) ; - slot( "full_name") = Rcpp::StringVector(0) ; - } - } - - S4_EnumDescriptor( const S4_EnumDescriptor& other) : S4(){ - setSEXP( other.asSexp() ); - } - S4_EnumDescriptor& operator=( const S4_EnumDescriptor& other){ - setSEXP( other.asSexp() ); - return *this ; - } - } ; + if (d) { + slot("pointer") = Rcpp::XPtr( + const_cast(d), false); + slot("name") = d->name(); + slot("full_name") = d->full_name(); + } else { + setSEXP(R_NilValue); + } + } - class S4_Message : public Rcpp::S4 { - public: - S4_Message( const GPB::Message* d) : S4( "Message" ){ - slot( "pointer" ) = Rcpp::XPtr( - const_cast(d), true) ; - slot( "type" ) = d->GetDescriptor()->full_name() ; - } - S4_Message( const S4_Message& other) : S4(){ - setSEXP( other.asSexp() ); - } - S4_Message& operator=( const S4_Message& other){ - setSEXP( other.asSexp() ); - return *this ; - } - } ; + S4_EnumValueDescriptor(const S4_EnumValueDescriptor& other) : S4() { + setSEXP(other.asSexp()); + } + S4_EnumValueDescriptor& operator=(const S4_EnumValueDescriptor& other) { + setSEXP(other.asSexp()); + return *this; + } +}; - class S4_ArrayOutputStream : public Rcpp::S4 { - - public: - S4_ArrayOutputStream( int size, int block_size ) : S4( "ArrayOutputStream" ) { - - Rcpp::RawVector payload(size) ; - GPB::io::ArrayOutputStream* stream = - new GPB::io::ArrayOutputStream( payload.begin(), size, block_size ) ; - - Rcpp::XPtr wrapper( - new ZeroCopyOutputStreamWrapper(stream), true, R_NilValue, payload ) ; - slot( "pointer" ) = wrapper ; - } - - S4_ArrayOutputStream( const S4_ArrayOutputStream& other ){ - setSEXP( other.asSexp() ); - } - S4_ArrayOutputStream& operator=( const S4_ArrayOutputStream& other){ - setSEXP( other.asSexp() ); - return *this ; - } - - } ; - - class S4_ArrayInputStream : public Rcpp::S4 { - public: - S4_ArrayInputStream( Rcpp::RawVector payload, int block_size ) : S4( "ArrayInputStream" ){ - GPB::io::ArrayInputStream* stream = - new GPB::io::ArrayInputStream( payload.begin(), payload.size() , block_size ) ; - Rcpp::XPtr wrapper( - new ZeroCopyInputStreamWrapper(stream), true, R_NilValue, payload ) ; - slot("pointer") = wrapper ; - } - } ; - - - -} // namespace rprotobuf +class S4_Descriptor : public Rcpp::S4 { + public: + S4_Descriptor(const GPB::Descriptor* d) : S4("Descriptor") { + slot("pointer") = + Rcpp::XPtr(const_cast(d), false); + if (!d) { + slot("type") = Rcpp::StringVector(0); + } else { + slot("type") = d->full_name(); + } + } + S4_Descriptor(const S4_Descriptor& other) : S4() { + setSEXP(other.asSexp()); + } + S4_Descriptor& operator=(const S4_Descriptor& other) { + setSEXP(other.asSexp()); + return *this; + } +}; +class S4_FileDescriptor : public Rcpp::S4 { + public: + S4_FileDescriptor(const GPB::FileDescriptor* d) : S4("FileDescriptor") { + slot("pointer") = Rcpp::XPtr( + const_cast(d), false); + if (!d) { + slot("package") = Rcpp::StringVector(0); + slot("filename") = Rcpp::StringVector(0); + } else { + slot("package") = d->package(); + slot("filename") = d->name(); + } + } + + S4_FileDescriptor(const S4_FileDescriptor& other) : S4() { + setSEXP(other.asSexp()); + } + S4_FileDescriptor& operator=(const S4_FileDescriptor& other) { + setSEXP(other.asSexp()); + return *this; + } +}; + +class S4_FieldDescriptor : public Rcpp::S4 { + public: + S4_FieldDescriptor(const GPB::FieldDescriptor* d) : S4("FieldDescriptor") { + slot("pointer") = Rcpp::XPtr( + const_cast(d), false); + slot("name") = d->name(); + slot("full_name") = d->full_name(); + slot("type") = d->containing_type()->full_name(); + } + + S4_FieldDescriptor(const S4_FieldDescriptor& other) : S4() { + setSEXP(other.asSexp()); + } + S4_FieldDescriptor& operator=(const S4_FieldDescriptor& other) { + setSEXP(other.asSexp()); + return *this; + } +}; + +class S4_ServiceDescriptor : public Rcpp::S4 { + public: + S4_ServiceDescriptor(const GPB::ServiceDescriptor* d) + : S4("ServiceDescriptor") { + slot("pointer") = Rcpp::XPtr( + const_cast(d), false); + } + + S4_ServiceDescriptor(const S4_ServiceDescriptor& other) : S4() { + setSEXP(other.asSexp()); + } + S4_ServiceDescriptor& operator=(const S4_ServiceDescriptor& other) { + setSEXP(other.asSexp()); + return *this; + } +}; + +class S4_MethodDescriptor : public Rcpp::S4 { + public: + S4_MethodDescriptor(const GPB::MethodDescriptor* d) + : S4("MethodDescriptor") { + slot("pointer") = Rcpp::XPtr( + const_cast(d), false); + } + + S4_MethodDescriptor(const S4_MethodDescriptor& other) : S4() { + setSEXP(other.asSexp()); + } + S4_MethodDescriptor& operator=(const S4_MethodDescriptor& other) { + setSEXP(other.asSexp()); + return *this; + } +}; + +class S4_EnumDescriptor : public Rcpp::S4 { + public: + S4_EnumDescriptor(const GPB::EnumDescriptor* d) : S4("EnumDescriptor") { + slot("pointer") = Rcpp::XPtr( + const_cast(d), false); + slot("type") = Rcpp::StringVector(0); + if (d) { + slot("name") = d->name(); + slot("full_name") = d->full_name(); + const GPB::Descriptor* type_desc = d->containing_type(); + if (type_desc) { + slot("type") = type_desc->full_name(); + } + } else { + slot("name") = Rcpp::StringVector(0); + slot("full_name") = Rcpp::StringVector(0); + } + } + + S4_EnumDescriptor(const S4_EnumDescriptor& other) : S4() { + setSEXP(other.asSexp()); + } + S4_EnumDescriptor& operator=(const S4_EnumDescriptor& other) { + setSEXP(other.asSexp()); + return *this; + } +}; + +class S4_Message : public Rcpp::S4 { + public: + S4_Message(const GPB::Message* d) : S4("Message") { + slot("pointer") = + Rcpp::XPtr(const_cast(d), true); + slot("type") = d->GetDescriptor()->full_name(); + } + S4_Message(const S4_Message& other) : S4() { setSEXP(other.asSexp()); } + S4_Message& operator=(const S4_Message& other) { + setSEXP(other.asSexp()); + return *this; + } +}; + +class S4_ArrayOutputStream : public Rcpp::S4 { + + public: + S4_ArrayOutputStream(int size, int block_size) : S4("ArrayOutputStream") { + + Rcpp::RawVector payload(size); + GPB::io::ArrayOutputStream* stream = + new GPB::io::ArrayOutputStream(payload.begin(), size, block_size); + + Rcpp::XPtr wrapper( + new ZeroCopyOutputStreamWrapper(stream), true, R_NilValue, payload); + slot("pointer") = wrapper; + } + + S4_ArrayOutputStream(const S4_ArrayOutputStream& other) { + setSEXP(other.asSexp()); + } + S4_ArrayOutputStream& operator=(const S4_ArrayOutputStream& other) { + setSEXP(other.asSexp()); + return *this; + } +}; + +class S4_ArrayInputStream : public Rcpp::S4 { + public: + S4_ArrayInputStream(Rcpp::RawVector payload, int block_size) + : S4("ArrayInputStream") { + GPB::io::ArrayInputStream* stream = new GPB::io::ArrayInputStream( + payload.begin(), payload.size(), block_size); + Rcpp::XPtr wrapper( + new ZeroCopyInputStreamWrapper(stream), true, R_NilValue, payload); + slot("pointer") = wrapper; + } +}; + +} // namespace rprotobuf + #endif Modified: pkg/src/SocketCopyingInputStream.h =================================================================== --- pkg/src/SocketCopyingInputStream.h 2013-12-30 20:49:17 UTC (rev 640) +++ pkg/src/SocketCopyingInputStream.h 2013-12-30 20:55:14 UTC (rev 641) @@ -10,19 +10,18 @@ we need it for the TCP_NODELAY socket option */ #include -namespace rprotobuf{ +namespace rprotobuf { - class SocketCopyingInputStream : public GPB::io::CopyingInputStream { - public: - SocketCopyingInputStream( int socket_id ); - - int Read(void * buffer, int size) ; - - private: - int socket_id ; - -} ; +class SocketCopyingInputStream : public GPB::io::CopyingInputStream { + public: + SocketCopyingInputStream(int socket_id); -} // namespace rprotobuf + int Read(void* buffer, int size); + private: + int socket_id; +}; + +} // namespace rprotobuf + #endif From noreply at r-forge.r-project.org Mon Dec 30 21:57:35 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 21:57:35 +0100 (CET) Subject: [Rprotobuf-commits] r642 - pkg/src Message-ID: <20131230205735.76FF81869E1@r-forge.r-project.org> Author: murray Date: 2013-12-30 21:57:35 +0100 (Mon, 30 Dec 2013) New Revision: 642 Removed: pkg/src/connections.h Log: Remove connections.h. This file is not included anywhere. It just included a commented-out version of the Rconnection structure, which is likely obsolete anyway given that the connections API was finally made partially exposed with a recent release of R. Deleted: pkg/src/connections.h =================================================================== --- pkg/src/connections.h 2013-12-30 20:55:14 UTC (rev 641) +++ pkg/src/connections.h 2013-12-30 20:57:35 UTC (rev 642) @@ -1,15 +0,0 @@ -#ifndef RPROTOBUF_CONNECTIONS_H -#define RPROTOBUF_CONNECTIONS_H - -// typedef struct Rconn *Rconnection; -// struct Rconn { -// char* class; -// char mode[5]; -// Rboolean text, isopen, incomplete, canread, canwrite, canseek, blocking, -// isGzcon; -// int (*fgetc)(struct Rconn *); -// size_t (*read)(void *, size_t, size_t, struct Rconn *); -// size_t (*write)(const void *, size_t, size_t, struct Rconn *); -// }; - -#endif From noreply at r-forge.r-project.org Mon Dec 30 22:00:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 22:00:27 +0100 (CET) Subject: [Rprotobuf-commits] r643 - pkg/src Message-ID: <20131230210028.14312186AC0@r-forge.r-project.org> Author: murray Date: 2013-12-30 22:00:27 +0100 (Mon, 30 Dec 2013) New Revision: 643 Removed: pkg/src/ZeroCopyInputStreamWrapper.h pkg/src/ZeroCopyOutputStreamWrapper.h Modified: pkg/src/streams.cpp Log: Remove two empty header files. The class definitions here are in rprotobuf.h. Then remove the include lines from the only place that imported the empty headers. Deleted: pkg/src/ZeroCopyInputStreamWrapper.h =================================================================== --- pkg/src/ZeroCopyInputStreamWrapper.h 2013-12-30 20:57:35 UTC (rev 642) +++ pkg/src/ZeroCopyInputStreamWrapper.h 2013-12-30 21:00:27 UTC (rev 643) @@ -1,9 +0,0 @@ -#ifndef RPROTOBUF_ZeroCopyInputStreamWrapper_H -#define RPROTOBUF_ZeroCopyInputStreamWrapper_H - -namespace rprotobuf{ - - -} // namespace rprotobuf - -#endif Deleted: pkg/src/ZeroCopyOutputStreamWrapper.h =================================================================== --- pkg/src/ZeroCopyOutputStreamWrapper.h 2013-12-30 20:57:35 UTC (rev 642) +++ pkg/src/ZeroCopyOutputStreamWrapper.h 2013-12-30 21:00:27 UTC (rev 643) @@ -1,8 +0,0 @@ -#ifndef RPROTOBUF_ZeroCopyOutputStreamWrapper_H -#define RPROTOBUF_ZeroCopyOutputStreamWrapper_H - -namespace rprotobuf{ - -} // namespace rprotobuf - -#endif Modified: pkg/src/streams.cpp =================================================================== --- pkg/src/streams.cpp 2013-12-30 20:57:35 UTC (rev 642) +++ pkg/src/streams.cpp 2013-12-30 21:00:27 UTC (rev 643) @@ -1,8 +1,6 @@ #include "rprotobuf.h" #include "ConnectionInputStream.h" #include "ConnectionOutputStream.h" -#include "ZeroCopyInputStreamWrapper.h" -#include "ZeroCopyOutputStreamWrapper.h" /* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ From noreply at r-forge.r-project.org Mon Dec 30 22:02:17 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 22:02:17 +0100 (CET) Subject: [Rprotobuf-commits] r644 - pkg/src Message-ID: <20131230210217.EA2B4186AC9@r-forge.r-project.org> Author: murray Date: 2013-12-30 22:02:17 +0100 (Mon, 30 Dec 2013) New Revision: 644 Modified: pkg/src/ConnectionInputStream.h pkg/src/ConnectionOutputStream.h pkg/src/RSourceTree.h Log: Whitespace change only (no diff output at all with svn diff -x -w). from clang-format per STYLE file. Modified: pkg/src/ConnectionInputStream.h =================================================================== --- pkg/src/ConnectionInputStream.h 2013-12-30 21:00:27 UTC (rev 643) +++ pkg/src/ConnectionInputStream.h 2013-12-30 21:02:17 UTC (rev 644) @@ -1,18 +1,18 @@ #ifndef RPROTOBUF_ConnectionInputStream_H #define RPROTOBUF_ConnectionInputStream_H -namespace rprotobuf{ +namespace rprotobuf { - class ConnectionInputStream : public GPB::io::CopyingInputStreamAdaptor { - public: - ConnectionInputStream( SEXP con, bool was_open ) ; - ~ConnectionInputStream() ; - - private: - bool was_open ; - SEXP con ; -} ; +class ConnectionInputStream : public GPB::io::CopyingInputStreamAdaptor { + public: + ConnectionInputStream(SEXP con, bool was_open); + ~ConnectionInputStream(); -} // namespace rprotobuf + private: + bool was_open; + SEXP con; +}; +} // namespace rprotobuf + #endif Modified: pkg/src/ConnectionOutputStream.h =================================================================== --- pkg/src/ConnectionOutputStream.h 2013-12-30 21:00:27 UTC (rev 643) +++ pkg/src/ConnectionOutputStream.h 2013-12-30 21:02:17 UTC (rev 644) @@ -1,18 +1,18 @@ #ifndef RPROTOBUF_ConnectionOutputStream_H #define RPROTOBUF_ConnectionOutputStream_H -namespace rprotobuf{ +namespace rprotobuf { - class ConnectionOutputStream : public GPB::io::CopyingOutputStreamAdaptor { - public: - ConnectionOutputStream( SEXP con, bool was_open ) ; - ~ConnectionOutputStream() ; - - private: - bool was_open ; - SEXP con ; -} ; +class ConnectionOutputStream : public GPB::io::CopyingOutputStreamAdaptor { + public: + ConnectionOutputStream(SEXP con, bool was_open); + ~ConnectionOutputStream(); -} // namespace rprotobuf + private: + bool was_open; + SEXP con; +}; +} // namespace rprotobuf + #endif Modified: pkg/src/RSourceTree.h =================================================================== --- pkg/src/RSourceTree.h 2013-12-30 21:00:27 UTC (rev 643) +++ pkg/src/RSourceTree.h 2013-12-30 21:02:17 UTC (rev 644) @@ -1,20 +1,20 @@ #ifndef RPROTOBUF_RSourceTree_H #define RPROTOBUF_RSourceTree_H -namespace rprotobuf{ - class RSourceTree : public GPB::compiler::SourceTree { - public: - RSourceTree() ; - GPB::io::ZeroCopyInputStream * Open(const std::string & filename) ; - void addDirectory( const std::string& directory) ; - void addDirectories( SEXP dirs) ; - void removeDirectory( const std::string& directory ) ; - void removeDirectories( SEXP dirs ) ; - - private: - std::set directories ; -} ; +namespace rprotobuf { +class RSourceTree : public GPB::compiler::SourceTree { + public: + RSourceTree(); + GPB::io::ZeroCopyInputStream* Open(const std::string& filename); + void addDirectory(const std::string& directory); + void addDirectories(SEXP dirs); + void removeDirectory(const std::string& directory); + void removeDirectories(SEXP dirs); -} // namespace rprotobuf + private: + std::set directories; +}; +} // namespace rprotobuf + #endif From noreply at r-forge.r-project.org Mon Dec 30 22:04:25 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 22:04:25 +0100 (CET) Subject: [Rprotobuf-commits] r645 - pkg/src Message-ID: <20131230210425.957DE186AD3@r-forge.r-project.org> Author: murray Date: 2013-12-30 22:04:24 +0100 (Mon, 30 Dec 2013) New Revision: 645 Modified: pkg/src/ConnectionCopyingInputStream.h pkg/src/ConnectionCopyingOutputStream.h pkg/src/RconnectionCopyingInputStream.h Log: Whitespace change only (clang-format). * 'namespace{' -> 'namespace {' * No indentation from namespace level. * 4 space indentation level. No diff visible with svn diff -x -w Modified: pkg/src/ConnectionCopyingInputStream.h =================================================================== --- pkg/src/ConnectionCopyingInputStream.h 2013-12-30 21:02:17 UTC (rev 644) +++ pkg/src/ConnectionCopyingInputStream.h 2013-12-30 21:04:24 UTC (rev 645) @@ -1,26 +1,26 @@ #ifndef RPROTOBUF_ConnectionCopyingInputStream_H #define RPROTOBUF_ConnectionCopyingInputStream_H -namespace rprotobuf{ +namespace rprotobuf { - class ConnectionCopyingInputStream : public GPB::io::CopyingInputStream { - public: - ConnectionCopyingInputStream( SEXP con ); - int Read(void * buffer, int size) ; - - private: - /* - the actual connection object from R - it is protected by the external pointer that - wraps the ConnectionInputStream, which is the only - thing that uses this class, so we don't need to take - care of GC here - */ - SEXP con ; - - Rcpp::Function readBin ; -} ; +class ConnectionCopyingInputStream : public GPB::io::CopyingInputStream { + public: + ConnectionCopyingInputStream(SEXP con); + int Read(void* buffer, int size); -} // namespace rprotobuf + private: + /* + the actual connection object from R + it is protected by the external pointer that + wraps the ConnectionInputStream, which is the only + thing that uses this class, so we don't need to take + care of GC here + */ + SEXP con; + Rcpp::Function readBin; +}; + +} // namespace rprotobuf + #endif Modified: pkg/src/ConnectionCopyingOutputStream.h =================================================================== --- pkg/src/ConnectionCopyingOutputStream.h 2013-12-30 21:02:17 UTC (rev 644) +++ pkg/src/ConnectionCopyingOutputStream.h 2013-12-30 21:04:24 UTC (rev 645) @@ -1,26 +1,26 @@ #ifndef RPROTOBUF_ConnectionCopyingOutputStream_H #define RPROTOBUF_ConnectionCopyingOutputStream_H -namespace rprotobuf{ +namespace rprotobuf { - class ConnectionCopyingOutputStream : public GPB::io::CopyingOutputStream { - public: - ConnectionCopyingOutputStream( SEXP con ); - bool Write(const void * buffer, int size) ; - - private: - /* - the actual connection object from R - it is protected by the external pointer that - wraps the ConnectionInputStream, which is the only - thing that uses this class, so we don't need to take - care of GC here - */ - SEXP con ; - - Rcpp::Function writeBin ; -} ; +class ConnectionCopyingOutputStream : public GPB::io::CopyingOutputStream { + public: + ConnectionCopyingOutputStream(SEXP con); + bool Write(const void* buffer, int size); -} // namespace rprotobuf + private: + /* + the actual connection object from R + it is protected by the external pointer that + wraps the ConnectionInputStream, which is the only + thing that uses this class, so we don't need to take + care of GC here + */ + SEXP con; + Rcpp::Function writeBin; +}; + +} // namespace rprotobuf + #endif Modified: pkg/src/RconnectionCopyingInputStream.h =================================================================== --- pkg/src/RconnectionCopyingInputStream.h 2013-12-30 21:02:17 UTC (rev 644) +++ pkg/src/RconnectionCopyingInputStream.h 2013-12-30 21:04:24 UTC (rev 645) @@ -1,20 +1,20 @@ #ifndef RPROTOBUF_RconnectionCopyingInputStream_H #define RPROTOBUF_RconnectionCopyingInputStream_H -namespace rprotobuf{ +namespace rprotobuf { - class RconnectionCopyingInputStream : public GPB::io::CopyingInputStream { - public: - RconnectionCopyingInputStream( int id ); - - int Read(void * buffer, int size) ; - bool Failure() { return(failure); } - - private: - int connection_id ; - bool failure; -} ; +class RconnectionCopyingInputStream : public GPB::io::CopyingInputStream { + public: + RconnectionCopyingInputStream(int id); -} // namespace rprotobuf + int Read(void* buffer, int size); + bool Failure() { return (failure); } + private: + int connection_id; + bool failure; +}; + +} // namespace rprotobuf + #endif From noreply at r-forge.r-project.org Mon Dec 30 22:09:54 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 22:09:54 +0100 (CET) Subject: [Rprotobuf-commits] r646 - pkg/src Message-ID: <20131230210954.44005184985@r-forge.r-project.org> Author: murray Date: 2013-12-30 22:09:53 +0100 (Mon, 30 Dec 2013) New Revision: 646 Modified: pkg/src/rprotobuf.h Log: Whitespace change only (clang-format). * 80-char line wrap. * Consistent indentation rules. Modified: pkg/src/rprotobuf.h =================================================================== --- pkg/src/rprotobuf.h 2013-12-30 21:04:24 UTC (rev 645) +++ pkg/src/rprotobuf.h 2013-12-30 21:09:53 UTC (rev 646) @@ -2,8 +2,8 @@ // // rprotobuf.h: R/C++ interface class library // -// Copyright (C) 2009 - 2012 Dirk Eddelbuettel and Romain Francois -// Copyright (C) 2012 - 2013 Dirk Eddelbuettel, Romain Francois and Murray Stokely +// Copyright (C) 2009-2012 Dirk Eddelbuettel and Romain Francois +// Copyright (C) 2012-2013 Dirk Eddelbuettel, Romain Francois and Murray Stokely // // This file is part of RProtoBuf. // @@ -23,7 +23,7 @@ #ifndef RPROTOBUF_H #define RPROTOBUF_H -#include // g++-4.7 wants this +#include // g++-4.7 wants this /* should we check this is available */ #include /* FIXME: need to include some header file instead of this define */ @@ -51,200 +51,212 @@ RCPP_ENUM_TRAITS(GPB::FieldDescriptor::CppType) RCPP_ENUM_TRAITS(GPB::FieldDescriptor::Type) -//RCPP_TRAITS(GPB::int64,REALSXP) -//RCPP_TRAITS(GPB::uint64,REALSXP) +// RCPP_TRAITS(GPB::int64,REALSXP) +// RCPP_TRAITS(GPB::uint64,REALSXP) #include #include #include - /* uncomment for debugging */ // #define RPB_DEBUG #ifdef RPB_DEBUG -#define RPB_DEBUG_BEGIN(__WHAT__) Rprintf( "<" #__WHAT__ ">\n" ) ; -#define RPB_DEBUG_END(__WHAT__) Rprintf( "\n" ) ; -#else +#define RPB_DEBUG_BEGIN(__WHAT__) Rprintf("<" #__WHAT__ ">\n"); +#define RPB_DEBUG_END(__WHAT__) Rprintf("\n"); +#else #define RPB_DEBUG_BEGIN(__WHAT__) #define RPB_DEBUG_END(__WHAT__) #endif -#define FIN_DBG(ptr, CLAZZ) -// #define FIN_DBG(ptr, CLAZZ) Rprintf( "RProtoBuf finalizing %s (%p)\n", CLAZZ, ptr ) +#define FIN_DBG(ptr, CLAZZ) +// #define FIN_DBG(ptr, CLAZZ) Rprintf( "RProtoBuf finalizing %s (%p)\n", CLAZZ, +// ptr ) -#define PRINT_DEBUG_INFO(name,o) \ - Rprintf( " %s [%d] = ", name, TYPEOF(o) ) ; \ - Rf_PrintValue( o ) ; \ +#define PRINT_DEBUG_INFO(name, o) \ + Rprintf(" %s [%d] = ", name, TYPEOF(o)); \ + Rf_PrintValue(o); #define RPROTOBUF_LOOKUP 24 // #define LOOKUP_DEBUG -/* FIXME : quick hack because just using TRUE and FALSE did not work in lookup.cpp */ -#define _TRUE_ (Rboolean)TRUE -#define _FALSE_ (Rboolean)FALSE +/* FIXME : quick hack because just using TRUE and FALSE did not work in + * lookup.cpp */ +#define _TRUE_ (Rboolean) TRUE +#define _FALSE_ (Rboolean) FALSE -#define GET_MESSAGE_POINTER_FROM_XP(xp) (GPB::Message*) EXTPTR_PTR( xp ) -#define GET_MESSAGE_POINTER_FROM_S4(m) (GPB::Message*) EXTPTR_PTR( GET_SLOT( m, Rf_install("pointer") ) ) +#define GET_MESSAGE_POINTER_FROM_XP(xp) (GPB::Message*) EXTPTR_PTR(xp) +#define GET_MESSAGE_POINTER_FROM_S4(m) \ + (GPB::Message*) EXTPTR_PTR(GET_SLOT(m, Rf_install("pointer"))) -#define GET_DESCRIPTOR_POINTER_FROM_XP(xp) (GPB::Descriptor*) EXTPTR_PTR( xp ) -#define GET_DESCRIPTOR_POINTER_FROM_S4(m) (GPB::Descriptor*) EXTPTR_PTR( GET_SLOT( m, Rf_install("pointer") ) ) +#define GET_DESCRIPTOR_POINTER_FROM_XP(xp) (GPB::Descriptor*) EXTPTR_PTR(xp) +#define GET_DESCRIPTOR_POINTER_FROM_S4(m) \ + (GPB::Descriptor*) EXTPTR_PTR(GET_SLOT(m, Rf_install("pointer"))) -#define GET_FIELD_DESCRIPTOR_POINTER_FROM_XP(xp) (GPB::FieldDescriptor*) EXTPTR_PTR( xp ) -#define GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(m) (GPB::FieldDescriptor*) EXTPTR_PTR( GET_SLOT( m, Rf_install("pointer") ) ) +#define GET_FIELD_DESCRIPTOR_POINTER_FROM_XP(xp) \ + (GPB::FieldDescriptor*) EXTPTR_PTR(xp) +#define GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(m) \ + (GPB::FieldDescriptor*) EXTPTR_PTR(GET_SLOT(m, Rf_install("pointer"))) -#define GET_ENUM_VALUE_DESCRIPTOR_POINTER_FROM_XP(xp) (GPB::EnumValueDescriptor*) EXTPTR_PTR( xp ) -#define GET_ENUM_VALUE_DESCRIPTOR_POINTER_FROM_S4(m) (GPB::EnumValueDescriptor*) EXTPTR_PTR( GET_SLOT( m, Rf_install("pointer") ) ) +#define GET_ENUM_VALUE_DESCRIPTOR_POINTER_FROM_XP(xp) \ + (GPB::EnumValueDescriptor*) EXTPTR_PTR(xp) +#define GET_ENUM_VALUE_DESCRIPTOR_POINTER_FROM_S4(m) \ + (GPB::EnumValueDescriptor*) EXTPTR_PTR(GET_SLOT(m, Rf_install("pointer"))) -#define GET_METHOD(xp) (GPB::MethodDescriptor*) EXTPTR_PTR( xp ) +#define GET_METHOD(xp) (GPB::MethodDescriptor*) EXTPTR_PTR(xp) #define COPYSTRING(s) s -#define THROW_SOCKET_ERROR(message) Rf_error( "%s : %s", message, strerror(sockerrno) ) +#define THROW_SOCKET_ERROR(message) \ + Rf_error("%s : %s", message, strerror(sockerrno)) #define XPP EXTPTR_PTR -#define NEW_S4_OBJECT(CLAZZ) SEXP oo = PROTECT( NEW_OBJECT(MAKE_CLASS(CLAZZ)) ); \ +#define NEW_S4_OBJECT(CLAZZ) \ + SEXP oo = PROTECT(NEW_OBJECT(MAKE_CLASS(CLAZZ))); \ if (!Rf_inherits(oo, CLAZZ)) Rcpp::stop(CLAZZ); - -namespace rprotobuf{ -typedef GPB::int32 int32 ; -typedef GPB::uint32 uint32 ; -typedef GPB::int64 int64 ; -typedef GPB::uint64 uint64 ; - +namespace rprotobuf { + +typedef GPB::int32 int32; +typedef GPB::uint32 uint32; +typedef GPB::int64 int64; +typedef GPB::uint64 uint64; + /* in rprotobuf.cpp */ -GPB::Message* PROTOTYPE( const GPB::Descriptor*) ; -GPB::Message* CLONE(const GPB::Message*) ; -RcppExport SEXP do_dollar_Descriptor( SEXP, SEXP ) ; -RcppExport SEXP newProtoMessage( SEXP) ; -RcppExport SEXP getProtobufDescriptor( SEXP ) ; -RcppExport SEXP getExtensionDescriptor( SEXP ) ; -RcppExport SEXP readProtoFiles( SEXP, SEXP ); -RcppExport Rboolean isMessage( SEXP, const char* ) ; -RcppExport GPB::FieldDescriptor* getFieldDescriptor(GPB::Message*, SEXP) ; +GPB::Message* PROTOTYPE(const GPB::Descriptor*); +GPB::Message* CLONE(const GPB::Message*); +RcppExport SEXP do_dollar_Descriptor(SEXP, SEXP); +RcppExport SEXP newProtoMessage(SEXP); +RcppExport SEXP getProtobufDescriptor(SEXP); +RcppExport SEXP getExtensionDescriptor(SEXP); +RcppExport SEXP readProtoFiles(SEXP, SEXP); +RcppExport Rboolean isMessage(SEXP, const char*); +RcppExport GPB::FieldDescriptor* getFieldDescriptor(GPB::Message*, SEXP); /* in extractors.cpp */ -RcppExport SEXP getMessageField( SEXP, SEXP ); -RcppExport SEXP extractFieldAsSEXP( const Rcpp::XPtr& , const GPB::FieldDescriptor* ) ; +RcppExport SEXP getMessageField(SEXP, SEXP); +RcppExport SEXP extractFieldAsSEXP(const Rcpp::XPtr&, + const GPB::FieldDescriptor*); /* in lookup.cpp */ -RcppExport SEXP newProtocolBufferLookup(SEXP) ; +RcppExport SEXP newProtocolBufferLookup(SEXP); /* in mutators.cpp */ -RcppExport SEXP setMessageField( SEXP, SEXP, SEXP ) ; -int GET_int( SEXP, int ) ; -double GET_double( SEXP, int ) ; -float GET_float( SEXP, int ) ; -int32 GET_int32( SEXP, int) ; -int64 GET_int64( SEXP, int) ; -uint32 GET_uint32( SEXP, int) ; -uint64 GET_uint64( SEXP, int ) ; -bool GET_bool( SEXP, int) ; -std::string GET_stdstring( SEXP, int ) ; -std::string GET_bytes( SEXP, int ) ; -void CHECK_values_for_enum( const GPB::FieldDescriptor*, SEXP) ; -void CHECK_messages( const GPB::FieldDescriptor*, SEXP) ; +RcppExport SEXP setMessageField(SEXP, SEXP, SEXP); +int GET_int(SEXP, int); +double GET_double(SEXP, int); +float GET_float(SEXP, int); +int32 GET_int32(SEXP, int); +int64 GET_int64(SEXP, int); +uint32 GET_uint32(SEXP, int); +uint64 GET_uint64(SEXP, int); +bool GET_bool(SEXP, int); +std::string GET_stdstring(SEXP, int); +std::string GET_bytes(SEXP, int); +void CHECK_values_for_enum(const GPB::FieldDescriptor*, SEXP); +void CHECK_messages(const GPB::FieldDescriptor*, SEXP); /* in wrapper_ServiceDescriptor.cpp */ RcppExport SEXP ServiceDescriptor_length(SEXP); -RcppExport SEXP ServiceDescriptor_method_count(SEXP) ; -RcppExport SEXP ServiceDescriptor_getMethodByIndex(SEXP, SEXP) ; -RcppExport SEXP ServiceDescriptor_getMethodByName(SEXP, SEXP) ; +RcppExport SEXP ServiceDescriptor_method_count(SEXP); +RcppExport SEXP ServiceDescriptor_getMethodByIndex(SEXP, SEXP); +RcppExport SEXP ServiceDescriptor_getMethodByName(SEXP, SEXP); /* in streams.cpp */ -void ZeroCopyInputStreamWrapper_finalizer( SEXP ); -void ZeroCopyOutputStreamWrapper_finalizer( SEXP ); +void ZeroCopyInputStreamWrapper_finalizer(SEXP); +void ZeroCopyOutputStreamWrapper_finalizer(SEXP); -RcppExport SEXP ZeroCopyInputStream_Next(SEXP) ; -RcppExport SEXP ZeroCopyInputStream_BackUp(SEXP, SEXP) ; -RcppExport SEXP ZeroCopyInputStream_ByteCount(SEXP) ; -RcppExport SEXP ZeroCopyInputStream_Skip(SEXP, SEXP) ; -RcppExport SEXP ZeroCopyInputStream_ReadRaw( SEXP, SEXP) ; -RcppExport SEXP ZeroCopyInputStream_ReadString( SEXP, SEXP) ; -RcppExport SEXP ZeroCopyInputStream_ReadVarint32( SEXP ) ; -RcppExport SEXP ZeroCopyInputStream_ReadVarint64( SEXP ) ; -RcppExport SEXP ZeroCopyInputStream_ReadLittleEndian32( SEXP ) ; -RcppExport SEXP ZeroCopyInputStream_ReadLittleEndian64( SEXP ) ; +RcppExport SEXP ZeroCopyInputStream_Next(SEXP); +RcppExport SEXP ZeroCopyInputStream_BackUp(SEXP, SEXP); +RcppExport SEXP ZeroCopyInputStream_ByteCount(SEXP); +RcppExport SEXP ZeroCopyInputStream_Skip(SEXP, SEXP); +RcppExport SEXP ZeroCopyInputStream_ReadRaw(SEXP, SEXP); +RcppExport SEXP ZeroCopyInputStream_ReadString(SEXP, SEXP); +RcppExport SEXP ZeroCopyInputStream_ReadVarint32(SEXP); +RcppExport SEXP ZeroCopyInputStream_ReadVarint64(SEXP); +RcppExport SEXP ZeroCopyInputStream_ReadLittleEndian32(SEXP); +RcppExport SEXP ZeroCopyInputStream_ReadLittleEndian64(SEXP); -RcppExport SEXP ZeroCopyOutputStream_Next(SEXP, SEXP) ; -RcppExport SEXP ZeroCopyOutputStream_BackUp(SEXP, SEXP) ; -RcppExport SEXP ZeroCopyOutputStream_ByteCount(SEXP) ; -RcppExport SEXP ZeroCopyOutputStream_WriteRaw( SEXP, SEXP); -RcppExport SEXP ZeroCopyOutputStream_WriteString( SEXP, SEXP); -RcppExport SEXP ZeroCopyOutputStream_WriteLittleEndian32( SEXP, SEXP ); -RcppExport SEXP ZeroCopyOutputStream_WriteLittleEndian64( SEXP, SEXP ); -RcppExport SEXP ZeroCopyOutputStream_WriteVarint32( SEXP, SEXP ); -RcppExport SEXP ZeroCopyOutputStream_WriteVarint64( SEXP, SEXP ); +RcppExport SEXP ZeroCopyOutputStream_Next(SEXP, SEXP); +RcppExport SEXP ZeroCopyOutputStream_BackUp(SEXP, SEXP); +RcppExport SEXP ZeroCopyOutputStream_ByteCount(SEXP); +RcppExport SEXP ZeroCopyOutputStream_WriteRaw(SEXP, SEXP); +RcppExport SEXP ZeroCopyOutputStream_WriteString(SEXP, SEXP); +RcppExport SEXP ZeroCopyOutputStream_WriteLittleEndian32(SEXP, SEXP); +RcppExport SEXP ZeroCopyOutputStream_WriteLittleEndian64(SEXP, SEXP); +RcppExport SEXP ZeroCopyOutputStream_WriteVarint32(SEXP, SEXP); +RcppExport SEXP ZeroCopyOutputStream_WriteVarint64(SEXP, SEXP); +RcppExport SEXP FileOutputStream_new(SEXP, SEXP, SEXP); +RcppExport SEXP FileOutputStream_Close(SEXP); +RcppExport SEXP FileOutputStream_Flush(SEXP); +RcppExport SEXP FileOutputStream_GetErrno(SEXP); +RcppExport SEXP FileOutputStream_SetCloseOnDelete(SEXP, SEXP); -RcppExport SEXP FileOutputStream_new( SEXP, SEXP, SEXP) ; -RcppExport SEXP FileOutputStream_Close( SEXP) ; -RcppExport SEXP FileOutputStream_Flush( SEXP) ; -RcppExport SEXP FileOutputStream_GetErrno( SEXP) ; -RcppExport SEXP FileOutputStream_SetCloseOnDelete( SEXP, SEXP ) ; +RcppExport SEXP FileInputStream_new(SEXP, SEXP, SEXP); +RcppExport SEXP FileInputStream_Close(SEXP); +RcppExport SEXP FileInputStream_GetErrno(SEXP); +RcppExport SEXP FileInputStream_SetCloseOnDelete(SEXP, SEXP); -RcppExport SEXP FileInputStream_new( SEXP, SEXP, SEXP) ; -RcppExport SEXP FileInputStream_Close( SEXP) ; -RcppExport SEXP FileInputStream_GetErrno( SEXP) ; -RcppExport SEXP FileInputStream_SetCloseOnDelete( SEXP, SEXP ) ; +RcppExport SEXP ConnectionInputStream_new(SEXP, SEXP); -RcppExport SEXP ConnectionInputStream_new( SEXP , SEXP) ; +RcppExport SEXP ConnectionOutputStream_new(SEXP, SEXP); -RcppExport SEXP ConnectionOutputStream_new( SEXP , SEXP) ; +/** + * simple class that wraps together a ZeroCopyOutputStream + * and its associated CodedOutputStream. Since we don't expose + * CodedOutputStream at the R level, this allows to keep only one such + * object with each ZeroCopyOutputStream + */ +class ZeroCopyOutputStreamWrapper { + public: + ZeroCopyOutputStreamWrapper(GPB::io::ZeroCopyOutputStream* stream); + ~ZeroCopyOutputStreamWrapper(); - /** - * simple class that wraps together a ZeroCopyOutputStream - * and its associated CodedOutputStream. Since we don't expose - * CodedOutputStream at the R level, this allows to keep only one such - * object with each ZeroCopyOutputStream - */ - class ZeroCopyOutputStreamWrapper { - public: - ZeroCopyOutputStreamWrapper( GPB::io::ZeroCopyOutputStream* stream ); - ~ZeroCopyOutputStreamWrapper() ; - - GPB::io::ZeroCopyOutputStream* get_stream(); - GPB::io::CodedOutputStream* get_coded_stream() ; - - private: - GPB::io::ZeroCopyOutputStream* stream ; - GPB::io::CodedOutputStream* coded_stream ; -} ; + GPB::io::ZeroCopyOutputStream* get_stream(); + GPB::io::CodedOutputStream* get_coded_stream(); - /** - * simple class that wraps together a ZeroCopyInputStream - * and its associated CodedInputStream. Since we don't expose - * CodedInputStream at the R level, this allows to keep only one such - * object with each zero copy input stream - */ - class ZeroCopyInputStreamWrapper { - public: - ZeroCopyInputStreamWrapper( GPB::io::ZeroCopyInputStream* stream ); - ~ZeroCopyInputStreamWrapper() ; - - GPB::io::ZeroCopyInputStream* get_stream(); - GPB::io::CodedInputStream* get_coded_stream() ; - - private: - GPB::io::ZeroCopyInputStream* stream ; - GPB::io::CodedInputStream* coded_stream ; - } ; + private: + GPB::io::ZeroCopyOutputStream* stream; + GPB::io::CodedOutputStream* coded_stream; +}; +/** + * simple class that wraps together a ZeroCopyInputStream + * and its associated CodedInputStream. Since we don't expose + * CodedInputStream at the R level, this allows to keep only one such + * object with each zero copy input stream + */ +class ZeroCopyInputStreamWrapper { + public: + ZeroCopyInputStreamWrapper(GPB::io::ZeroCopyInputStream* stream); + ~ZeroCopyInputStreamWrapper(); -} // namespace rprotobuf + GPB::io::ZeroCopyInputStream* get_stream(); + GPB::io::CodedInputStream* get_coded_stream(); + private: + GPB::io::ZeroCopyInputStream* stream; + GPB::io::CodedInputStream* coded_stream; +}; + +} // namespace rprotobuf + #include "S4_classes.h" #include "RconnectionCopyingInputStream.h" -#define GET_ZCIS(xp) ( (ZeroCopyInputStreamWrapper*)XPP(xp) )->get_stream() -#define GET_CIS(xp) ( (ZeroCopyInputStreamWrapper*)XPP(xp) )->get_coded_stream() -#define GET_FIS(xp) (GPB::io::FileInputStream*)( (ZeroCopyInputStreamWrapper*)XPP(xp) )->get_stream() +#define GET_ZCIS(xp) ((ZeroCopyInputStreamWrapper*)XPP(xp))->get_stream() +#define GET_CIS(xp) ((ZeroCopyInputStreamWrapper*)XPP(xp))->get_coded_stream() +#define GET_FIS(xp) \ + (GPB::io::FileInputStream*)((ZeroCopyInputStreamWrapper*)XPP(xp)) \ + ->get_stream() -#define GET_ZCOS(xp) ( (ZeroCopyOutputStreamWrapper*)XPP(xp) )->get_stream() -#define GET_COS(xp) ( (ZeroCopyOutputStreamWrapper*)XPP(xp) )->get_coded_stream() -#define GET_FOS(xp) (GPB::io::FileOutputStream*)( (ZeroCopyOutputStreamWrapper*)XPP(xp) )->get_stream() +#define GET_ZCOS(xp) ((ZeroCopyOutputStreamWrapper*)XPP(xp))->get_stream() +#define GET_COS(xp) ((ZeroCopyOutputStreamWrapper*)XPP(xp))->get_coded_stream() +#define GET_FOS(xp) \ + (GPB::io::FileOutputStream*)((ZeroCopyOutputStreamWrapper*)XPP(xp)) \ + ->get_stream() #endif From noreply at r-forge.r-project.org Mon Dec 30 22:26:49 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 22:26:49 +0100 (CET) Subject: [Rprotobuf-commits] r647 - pkg/src Message-ID: <20131230212649.A3D12186A14@r-forge.r-project.org> Author: murray Date: 2013-12-30 22:26:49 +0100 (Mon, 30 Dec 2013) New Revision: 647 Added: pkg/src/.dir-locals.el Log: Add a directory-level config file to specify indentation preferences to Emacs rather than relying on inconsistent annotations in each individual file. See http://www.emacswiki.org/emacs/DirectoryVariables Added: pkg/src/.dir-locals.el =================================================================== --- pkg/src/.dir-locals.el (rev 0) +++ pkg/src/.dir-locals.el 2013-12-30 21:26:49 UTC (rev 647) @@ -0,0 +1,6 @@ +((nil . ((indent-tabs-mode . nil) + (tab-width . 4))) + (c-mode . ((c-indent-level . 4) + (c-basic-offset . 4))) + (c++-mode . ((c-indent-level . 4) + (c-basic-offset . 4)))) From noreply at r-forge.r-project.org Mon Dec 30 22:30:55 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 22:30:55 +0100 (CET) Subject: [Rprotobuf-commits] r648 - pkg/src Message-ID: <20131230213055.AB673186AB0@r-forge.r-project.org> Author: murray Date: 2013-12-30 22:30:55 +0100 (Mon, 30 Dec 2013) New Revision: 648 Modified: pkg/src/DescriptorPoolLookup.cpp pkg/src/Rcppsupport.h pkg/src/S4_classes.h pkg/src/lookup.cpp pkg/src/rprotobuf.h pkg/src/wrapper_EnumDescriptor.cpp pkg/src/wrapper_EnumValueDescriptor.cpp Log: Remove basic file level annotations of emacs style preferences that are now obviated by the directory level config. I'm leaving the ones that specify collapse/fold settings as I haven't verified we can handle that properly from the directory config, but I have verified the basic indentation settings work. Modified: pkg/src/DescriptorPoolLookup.cpp =================================================================== --- pkg/src/DescriptorPoolLookup.cpp 2013-12-30 21:26:49 UTC (rev 647) +++ pkg/src/DescriptorPoolLookup.cpp 2013-12-30 21:30:55 UTC (rev 648) @@ -1,5 +1,3 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- -// // DescriptorPoolLookup.cpp: R/C++ interface class library // // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois Modified: pkg/src/Rcppsupport.h =================================================================== --- pkg/src/Rcppsupport.h 2013-12-30 21:26:49 UTC (rev 647) +++ pkg/src/Rcppsupport.h 2013-12-30 21:30:55 UTC (rev 648) @@ -1,5 +1,3 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- -// // rprotobuf.h: support for using Rcpp // // Copyright (C) 2010 Dirk Eddelbuettel and Romain Francois Modified: pkg/src/S4_classes.h =================================================================== --- pkg/src/S4_classes.h 2013-12-30 21:26:49 UTC (rev 647) +++ pkg/src/S4_classes.h 2013-12-30 21:30:55 UTC (rev 648) @@ -1,5 +1,3 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- -// // S4_classes.h: R/C++ interface class library // // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois Modified: pkg/src/lookup.cpp =================================================================== --- pkg/src/lookup.cpp 2013-12-30 21:26:49 UTC (rev 647) +++ pkg/src/lookup.cpp 2013-12-30 21:30:55 UTC (rev 648) @@ -1,6 +1,3 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -// -*- - #include "rprotobuf.h" #include "DescriptorPoolLookup.h" Modified: pkg/src/rprotobuf.h =================================================================== --- pkg/src/rprotobuf.h 2013-12-30 21:26:49 UTC (rev 647) +++ pkg/src/rprotobuf.h 2013-12-30 21:30:55 UTC (rev 648) @@ -1,5 +1,3 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; indent-tabs-mode: nil; -*- -// // rprotobuf.h: R/C++ interface class library // // Copyright (C) 2009-2012 Dirk Eddelbuettel and Romain Francois Modified: pkg/src/wrapper_EnumDescriptor.cpp =================================================================== --- pkg/src/wrapper_EnumDescriptor.cpp 2013-12-30 21:26:49 UTC (rev 647) +++ pkg/src/wrapper_EnumDescriptor.cpp 2013-12-30 21:30:55 UTC (rev 648) @@ -1,5 +1,3 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- -// // wrapper_EnumDescriptor.cpp: R/C++ interface class library // // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois Modified: pkg/src/wrapper_EnumValueDescriptor.cpp =================================================================== --- pkg/src/wrapper_EnumValueDescriptor.cpp 2013-12-30 21:26:49 UTC (rev 647) +++ pkg/src/wrapper_EnumValueDescriptor.cpp 2013-12-30 21:30:55 UTC (rev 648) @@ -1,5 +1,3 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 8 -*- -// // wrapper_EnumValueDescriptor.h: R/C++ interface class library // // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois From noreply at r-forge.r-project.org Mon Dec 30 22:43:29 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 22:43:29 +0100 (CET) Subject: [Rprotobuf-commits] r649 - pkg/src Message-ID: <20131230214329.486A2185D9C@r-forge.r-project.org> Author: murray Date: 2013-12-30 22:43:28 +0100 (Mon, 30 Dec 2013) New Revision: 649 Modified: pkg/src/mutators.cpp Log: Fix the '{{{' and '}}}' placement after last refactor to allow this file to be used with Emacs folding mode, which someone seems to use/like, and seems pretty cool to me but I don't use it. Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-30 21:30:55 UTC (rev 648) +++ pkg/src/mutators.cpp 2013-12-30 21:43:28 UTC (rev 649) @@ -518,7 +518,6 @@ ; // nothing, just to satisfy -Wall } } - // }}} } /** @@ -729,7 +728,6 @@ } // }}} } - // }}} } /** @@ -751,7 +749,7 @@ // The number of elements already in the repeated field. int field_size = ref->FieldSize( *message, field_desc ) ; - /* {{{ in case of messages or enum, we have to check that all + /* in case of messages or enum, we have to check that all values are ok before doing anything, othewise this could leed to modify a few values and then fail which is not good */ CHECK_repeated_vals(field_desc, value, value_size); @@ -1217,7 +1215,6 @@ } // }}} } - // }}} } /** From noreply at r-forge.r-project.org Mon Dec 30 22:44:07 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 22:44:07 +0100 (CET) Subject: [Rprotobuf-commits] r650 - pkg/src Message-ID: <20131230214407.C5766185EFA@r-forge.r-project.org> Author: murray Date: 2013-12-30 22:44:07 +0100 (Mon, 30 Dec 2013) New Revision: 650 Modified: pkg/src/extractors.cpp pkg/src/wrapper_FieldDescriptor.cpp Log: Remove file-local emacs settings that are obviated by directory level settings, except for the folding settings that were set in these two files but these files have no '{{{' folds to worry about. Modified: pkg/src/extractors.cpp =================================================================== --- pkg/src/extractors.cpp 2013-12-30 21:43:28 UTC (rev 649) +++ pkg/src/extractors.cpp 2013-12-30 21:44:07 UTC (rev 650) @@ -1,6 +1,3 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*- -/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ -// // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois // // This file is part of RProtoBuf. Modified: pkg/src/wrapper_FieldDescriptor.cpp =================================================================== --- pkg/src/wrapper_FieldDescriptor.cpp 2013-12-30 21:43:28 UTC (rev 649) +++ pkg/src/wrapper_FieldDescriptor.cpp 2013-12-30 21:44:07 UTC (rev 650) @@ -1,6 +1,3 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*- -/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ -// // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois // // This file is part of RProtoBuf. From noreply at r-forge.r-project.org Mon Dec 30 22:49:05 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 22:49:05 +0100 (CET) Subject: [Rprotobuf-commits] r651 - pkg/src Message-ID: <20131230214905.427BF1868AA@r-forge.r-project.org> Author: murray Date: 2013-12-30 22:49:04 +0100 (Mon, 30 Dec 2013) New Revision: 651 Modified: pkg/src/.dir-locals.el Log: Add comments to the docuementation for directory level variables and also the FoldingMode. Also, turn on show-trailing-whitespace so that errant whitespace at end of line is highlighted so it can be seen/removed before checkin. Modified: pkg/src/.dir-locals.el =================================================================== --- pkg/src/.dir-locals.el 2013-12-30 21:44:07 UTC (rev 650) +++ pkg/src/.dir-locals.el 2013-12-30 21:49:04 UTC (rev 651) @@ -1,6 +1,14 @@ +; Emacs customization settings to apply to every file in this directory. +; See http://www.emacswiki.org/emacs/DirectoryVariables +; +; Note some of the files include '{{{' and '}}}' annotations to be used +; with Folding Mode: http://www.emacswiki.org/emacs/FoldingMode ((nil . ((indent-tabs-mode . nil) - (tab-width . 4))) + (tab-width . 4) + (show-trailing-whitespace . t))) (c-mode . ((c-indent-level . 4) - (c-basic-offset . 4))) + (c-basic-offset . 4) + (show-trailing-whitespace . t))) (c++-mode . ((c-indent-level . 4) - (c-basic-offset . 4)))) + (c-basic-offset . 4) + (show-trailing-whitespace . t)))) From noreply at r-forge.r-project.org Mon Dec 30 23:23:45 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 23:23:45 +0100 (CET) Subject: [Rprotobuf-commits] r652 - pkg/src Message-ID: <20131230222345.64BF3186985@r-forge.r-project.org> Author: murray Date: 2013-12-30 23:23:44 +0100 (Mon, 30 Dec 2013) New Revision: 652 Modified: pkg/src/ConnectionOutputStream.cpp pkg/src/DescriptorPoolLookup.cpp pkg/src/RSourceTree.cpp pkg/src/RWarningErrorCollector.cpp pkg/src/ZeroCopyInputStreamWrapper.cpp pkg/src/ZeroCopyOutputStreamWrapper.cpp pkg/src/extensions.cpp pkg/src/lookup.cpp pkg/src/rprotobuf.cpp pkg/src/streams.cpp pkg/src/wrapper_ArrayInputStream.cpp pkg/src/wrapper_ArrayOutputStream.cpp pkg/src/wrapper_Descriptor.cpp pkg/src/wrapper_EnumDescriptor.cpp pkg/src/wrapper_EnumValueDescriptor.cpp pkg/src/wrapper_FieldDescriptor.cpp pkg/src/wrapper_FileDescriptor.cpp pkg/src/wrapper_Message.cpp pkg/src/wrapper_MethodDescriptor.cpp pkg/src/wrapper_ServiceDescriptor.cpp pkg/src/wrapper_ZeroCopyInputStream.cpp Log: whitespace change only. Increase line-wrap limit to 100 characters. This is more readable for this code base as the large method names force too many conditionals and assignments onto far too many lines, and it more closely matches the previous style. There are still a fair number of lines greater than 100 characters that are wrapped. Modified: pkg/src/ConnectionOutputStream.cpp =================================================================== --- pkg/src/ConnectionOutputStream.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/ConnectionOutputStream.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -5,8 +5,7 @@ namespace rprotobuf { ConnectionOutputStream::ConnectionOutputStream(SEXP con, bool was_open) - : GPB::io::CopyingOutputStreamAdaptor( - new ConnectionCopyingOutputStream(con)), + : GPB::io::CopyingOutputStreamAdaptor(new ConnectionCopyingOutputStream(con)), was_open(was_open), con(con) { /* clean the wrapped stream on delete */ Modified: pkg/src/DescriptorPoolLookup.cpp =================================================================== --- pkg/src/DescriptorPoolLookup.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/DescriptorPoolLookup.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -22,9 +22,7 @@ namespace rprotobuf { -void DescriptorPoolLookup::add(const std::string& element) { - elements.insert(element); -} +void DescriptorPoolLookup::add(const std::string& element) { elements.insert(element); } bool DescriptorPoolLookup::contains(const std::string& element) { return elements.find(element) != elements.end(); @@ -35,20 +33,16 @@ std::set DescriptorPoolLookup::elements; RWarningErrorCollector DescriptorPoolLookup::error_collector; RSourceTree DescriptorPoolLookup::source_tree; -GPB::compiler::Importer DescriptorPoolLookup::importer(&source_tree, - &error_collector); -GPB::DynamicMessageFactory DescriptorPoolLookup::message_factory( - importer.pool()); +GPB::compiler::Importer DescriptorPoolLookup::importer(&source_tree, &error_collector); +GPB::DynamicMessageFactory DescriptorPoolLookup::message_factory(importer.pool()); void DescriptorPoolLookup::importProtoFiles(SEXP files, SEXP dirs) { source_tree.addDirectories(dirs); int n = LENGTH(files); for (int j = 0; j < n; j++) { - const GPB::FileDescriptor* file_desc = - importer.Import(CHAR(STRING_ELT(files, j))); + const GPB::FileDescriptor* file_desc = importer.Import(CHAR(STRING_ELT(files, j))); if (!file_desc) { - Rf_error("Could not load proto file '%s'\n", - CHAR(STRING_ELT(files, j))); + Rf_error("Could not load proto file '%s'\n", CHAR(STRING_ELT(files, j))); continue; } int ntypes = file_desc->message_type_count(); @@ -68,12 +62,8 @@ // source_tree.removeDirectories( dirs ) ; } -const GPB::DescriptorPool* DescriptorPoolLookup::pool() { - return importer.pool(); -} +const GPB::DescriptorPool* DescriptorPoolLookup::pool() { return importer.pool(); } -const GPB::DynamicMessageFactory* DescriptorPoolLookup::factory() { - return &message_factory; -} +const GPB::DynamicMessageFactory* DescriptorPoolLookup::factory() { return &message_factory; } } // namespace rprotobuf Modified: pkg/src/RSourceTree.cpp =================================================================== --- pkg/src/RSourceTree.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/RSourceTree.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -27,15 +27,12 @@ return NULL; } - GPB::io::FileInputStream* result = - new GPB::io::FileInputStream(file_descriptor); + GPB::io::FileInputStream* result = new GPB::io::FileInputStream(file_descriptor); result->SetCloseOnDelete(true); return result; } -void RSourceTree::addDirectory(const std::string& directory) { - directories.insert(directory); -} +void RSourceTree::addDirectory(const std::string& directory) { directories.insert(directory); } void RSourceTree::addDirectories(SEXP dirs) { int n = LENGTH(dirs); for (int i = 0; i < n; i++) { @@ -43,9 +40,7 @@ } } -void RSourceTree::removeDirectory(const std::string& directory) { - directories.erase(directory); -} +void RSourceTree::removeDirectory(const std::string& directory) { directories.erase(directory); } void RSourceTree::removeDirectories(SEXP dirs) { int n = LENGTH(dirs); for (int i = 0; i < n; i++) { Modified: pkg/src/RWarningErrorCollector.cpp =================================================================== --- pkg/src/RWarningErrorCollector.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/RWarningErrorCollector.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -3,11 +3,10 @@ namespace rprotobuf { -void RWarningErrorCollector::AddError(const std::string& filename, int line, - int column, const std::string& message) { +void RWarningErrorCollector::AddError(const std::string& filename, int line, int column, + const std::string& message) { - Rprintf("%s:%d:%d:%s\n", filename.c_str(), line + 1, column + 1, - message.c_str()); + Rprintf("%s:%d:%d:%s\n", filename.c_str(), line + 1, column + 1, message.c_str()); } } // namespace rprotobuf Modified: pkg/src/ZeroCopyInputStreamWrapper.cpp =================================================================== --- pkg/src/ZeroCopyInputStreamWrapper.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/ZeroCopyInputStreamWrapper.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -2,8 +2,7 @@ namespace rprotobuf { -ZeroCopyInputStreamWrapper::ZeroCopyInputStreamWrapper( - GPB::io::ZeroCopyInputStream* stream) +ZeroCopyInputStreamWrapper::ZeroCopyInputStreamWrapper(GPB::io::ZeroCopyInputStream* stream) : stream(stream) { coded_stream = new GPB::io::CodedInputStream(stream); } @@ -15,11 +14,7 @@ /* then the stream itself */ delete stream; } -GPB::io::ZeroCopyInputStream* ZeroCopyInputStreamWrapper::get_stream() { - return stream; -} -GPB::io::CodedInputStream* ZeroCopyInputStreamWrapper::get_coded_stream() { - return coded_stream; -} +GPB::io::ZeroCopyInputStream* ZeroCopyInputStreamWrapper::get_stream() { return stream; } +GPB::io::CodedInputStream* ZeroCopyInputStreamWrapper::get_coded_stream() { return coded_stream; } } // namespace rprotobuf Modified: pkg/src/ZeroCopyOutputStreamWrapper.cpp =================================================================== --- pkg/src/ZeroCopyOutputStreamWrapper.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/ZeroCopyOutputStreamWrapper.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -2,8 +2,7 @@ namespace rprotobuf { -ZeroCopyOutputStreamWrapper::ZeroCopyOutputStreamWrapper( - GPB::io::ZeroCopyOutputStream* stream) +ZeroCopyOutputStreamWrapper::ZeroCopyOutputStreamWrapper(GPB::io::ZeroCopyOutputStream* stream) : stream(stream) { coded_stream = new GPB::io::CodedOutputStream(stream); } @@ -15,11 +14,7 @@ /* then the stream itself */ delete stream; } -GPB::io::ZeroCopyOutputStream* ZeroCopyOutputStreamWrapper::get_stream() { - return stream; -} -GPB::io::CodedOutputStream* ZeroCopyOutputStreamWrapper::get_coded_stream() { - return coded_stream; -} +GPB::io::ZeroCopyOutputStream* ZeroCopyOutputStreamWrapper::get_stream() { return stream; } +GPB::io::CodedOutputStream* ZeroCopyOutputStreamWrapper::get_coded_stream() { return coded_stream; } } // namespace rprotobuf Modified: pkg/src/extensions.cpp =================================================================== --- pkg/src/extensions.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/extensions.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -29,8 +29,7 @@ /* grab the Message pointer */ Rcpp::XPtr message(pointer); const Reflection* ref = message->GetReflection(); - const GPB::FieldDescriptor* field_desc = - GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(sfielddesc); + const GPB::FieldDescriptor* field_desc = GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(sfielddesc); // extractFieldAsSEXP returns a default (e.g. 0) even when // field doesn't exist, but returning NULL probably makes more Modified: pkg/src/lookup.cpp =================================================================== --- pkg/src/lookup.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/lookup.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -18,8 +18,7 @@ * * @return _TRUE_ if there is a message of the given type in the DescriptorPool */ -Rboolean rProtoBufTable_exists(const char *const name, Rboolean *canCache, - R_ObjectTable *tb) { +Rboolean rProtoBufTable_exists(const char *const name, Rboolean *canCache, R_ObjectTable *tb) { #ifdef LOOKUP_DEBUG Rprintf(" >> rProtoBufTable_exists\n"); @@ -35,16 +34,15 @@ } else { /* try the generated pool */ const GPB::DescriptorPool *pool = GPB::DescriptorPool::generated_pool(); - if (pool->FindMessageTypeByName(name) || - pool->FindEnumTypeByName(name) || pool->FindServiceByName(name) || - pool->FindMethodByName(name) || pool->FindExtensionByName(name)) { + if (pool->FindMessageTypeByName(name) || pool->FindEnumTypeByName(name) || + pool->FindServiceByName(name) || pool->FindMethodByName(name) || + pool->FindExtensionByName(name)) { DescriptorPoolLookup::add(name); val = _TRUE_; } else { /* try the runtime pool */ pool = DescriptorPoolLookup::pool(); - if (pool->FindMessageTypeByName(name) || - pool->FindEnumTypeByName(name) || + if (pool->FindMessageTypeByName(name) || pool->FindEnumTypeByName(name) || pool->FindServiceByName(name) || pool->FindMethodByName(name) || pool->FindExtensionByName(name)) { DescriptorPoolLookup::add(name); @@ -65,29 +63,25 @@ DescriptorPoolLookup::add(name_string); return S4_Descriptor(desc); } else { - const GPB::EnumDescriptor *enum_desc = - pool->FindEnumTypeByName(name_string); + const GPB::EnumDescriptor *enum_desc = pool->FindEnumTypeByName(name_string); if (enum_desc) { /* enum */ DescriptorPoolLookup::add(name_string); return S4_EnumDescriptor(enum_desc); } else { - const GPB::FieldDescriptor *extension_desc = - pool->FindExtensionByName(name_string); + const GPB::FieldDescriptor *extension_desc = pool->FindExtensionByName(name_string); if (extension_desc) { /* extension */ DescriptorPoolLookup::add(name_string); return S4_FieldDescriptor(extension_desc); } else { - const GPB::ServiceDescriptor *service_desc = - pool->FindServiceByName(name_string); + const GPB::ServiceDescriptor *service_desc = pool->FindServiceByName(name_string); if (service_desc) { DescriptorPoolLookup::add(name_string); return S4_ServiceDescriptor(service_desc); } else { - const GPB::MethodDescriptor *method_desc = - pool->FindMethodByName(name_string); + const GPB::MethodDescriptor *method_desc = pool->FindMethodByName(name_string); if (method_desc) { DescriptorPoolLookup::add(name_string); return S4_MethodDescriptor(method_desc); @@ -107,8 +101,7 @@ * @param canCache * @param tb lookup table */ -SEXP rProtoBufTable_get(const char *const name, Rboolean *canCache, - R_ObjectTable *tb) { +SEXP rProtoBufTable_get(const char *const name, Rboolean *canCache, R_ObjectTable *tb) { #ifdef LOOKUP_DEBUG Rprintf(" >> rProtoBufTable_get\n"); @@ -172,8 +165,7 @@ * NULL to indicate assign is not possible on this lookup table * without giving such a hard error. */ -SEXP rProtoBufTable_assign(const char *const name, SEXP value, - R_ObjectTable *tb) { +SEXP rProtoBufTable_assign(const char *const name, SEXP value, R_ObjectTable *tb) { #ifdef LOOKUP_DEBUG Rprintf(" >> rProtoBufTable_assign( %s ) \n", name); #endif @@ -224,8 +216,7 @@ tb->onAttach = NULL; tb->onDetach = NULL; - PROTECT(val = R_MakeExternalPtr(tb, Rf_install("UserDefinedDatabase"), - R_NilValue)); + PROTECT(val = R_MakeExternalPtr(tb, Rf_install("UserDefinedDatabase"), R_NilValue)); PROTECT(klass = Rf_mkString("UserDefinedDatabase")); Rf_setAttrib(val, R_ClassSymbol, klass); UNPROTECT(2); /* val, klass */ @@ -236,8 +227,7 @@ Rcpp::Function fun("attach"); int pos = Rcpp::as(possexp); - fun(val, Rcpp::Named("pos") = pos, - Rcpp::Named("name") = "RProtoBuf:DescriptorPool"); + fun(val, Rcpp::Named("pos") = pos, Rcpp::Named("name") = "RProtoBuf:DescriptorPool"); return (val); } Modified: pkg/src/rprotobuf.cpp =================================================================== --- pkg/src/rprotobuf.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/rprotobuf.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -10,8 +10,7 @@ Rprintf("desc = %d\n", desc); #endif /* first try the runtime factory */ - GPB::Message* m = (GPB::Message*)((GPB::DynamicMessageFactory*) - DescriptorPoolLookup::factory()) + GPB::Message* m = (GPB::Message*)((GPB::DynamicMessageFactory*)DescriptorPoolLookup::factory()) ->GetPrototype(desc) ->New(); @@ -20,9 +19,7 @@ #endif if (!m) { /* then the dynamic runtime factory */ - m = (GPB::Message*)GPB::MessageFactory::generated_factory() - ->GetPrototype(desc) - ->New(); + m = (GPB::Message*)GPB::MessageFactory::generated_factory()->GetPrototype(desc)->New(); #ifdef RPB_DEBUG Rprintf("runtime factory = %d\n", m); #endif @@ -212,8 +209,7 @@ if (TYPEOF(m) != S4SXP || !Rf_inherits(m, "Message")) return _FALSE_; - GPB::Message* message = - (GPB::Message*)EXTPTR_PTR(GET_SLOT(m, Rf_install("pointer"))); + GPB::Message* message = (GPB::Message*)EXTPTR_PTR(GET_SLOT(m, Rf_install("pointer"))); const char* type = message->GetDescriptor()->full_name().c_str(); if (strcmp(type, target)) { @@ -238,22 +234,18 @@ break; } case CHARSXP: { - field_desc = - (GPB::FieldDescriptor*)desc->FindFieldByName(CHAR(name)); + field_desc = (GPB::FieldDescriptor*)desc->FindFieldByName(CHAR(name)); error_message = error_message + " '" + CHAR(name) + "'"; break; } case STRSXP: { - field_desc = (GPB::FieldDescriptor*)desc->FindFieldByName( - CHAR(STRING_ELT(name, 0))); - error_message = - error_message + " '" + CHAR(STRING_ELT(name, 0)) + "'"; + field_desc = (GPB::FieldDescriptor*)desc->FindFieldByName(CHAR(STRING_ELT(name, 0))); + error_message = error_message + " '" + CHAR(STRING_ELT(name, 0)) + "'"; break; } case REALSXP: case INTSXP: { - field_desc = (GPB::FieldDescriptor*)desc->FindFieldByNumber( - Rcpp::as(name)); + field_desc = (GPB::FieldDescriptor*)desc->FindFieldByNumber(Rcpp::as(name)); break; } } @@ -273,8 +265,6 @@ } } -RPB_FUNCTION_0(int, get_protobuf_library_version) { - return GOOGLE_PROTOBUF_VERSION; -} +RPB_FUNCTION_0(int, get_protobuf_library_version) { return GOOGLE_PROTOBUF_VERSION; } } // namespace rprotobuf Modified: pkg/src/streams.cpp =================================================================== --- pkg/src/streams.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/streams.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -6,9 +6,7 @@ namespace rprotobuf { -void ZeroCopyInputStreamWrapper_finalizer(SEXP xp) { - delete (ZeroCopyInputStreamWrapper*)XPP(xp); -} +void ZeroCopyInputStreamWrapper_finalizer(SEXP xp) { delete (ZeroCopyInputStreamWrapper*)XPP(xp); } void ZeroCopyOutputStreamWrapper_finalizer(SEXP xp) { delete (ZeroCopyOutputStreamWrapper*)XPP(xp); } @@ -21,14 +19,11 @@ NEW_S4_OBJECT("FileInputStream"); int fd = open(CHAR(STRING_ELT(filename, 0)), O_RDONLY | O_BINARY); - GPB::io::FileInputStream* stream = - new GPB::io::FileInputStream(fd, INTEGER(block_size)[0]); + GPB::io::FileInputStream* stream = new GPB::io::FileInputStream(fd, INTEGER(block_size)[0]); stream->SetCloseOnDelete(LOGICAL(close_on_delete)[0]); - ZeroCopyInputStreamWrapper* wrapper = - new ZeroCopyInputStreamWrapper(stream); + ZeroCopyInputStreamWrapper* wrapper = new ZeroCopyInputStreamWrapper(stream); - SEXP ptr = - PROTECT(R_MakeExternalPtr((void*)wrapper, R_NilValue, R_NilValue)); + SEXP ptr = PROTECT(R_MakeExternalPtr((void*)wrapper, R_NilValue, R_NilValue)); R_RegisterCFinalizerEx(ptr, ZeroCopyInputStreamWrapper_finalizer, _FALSE_); SET_SLOT(oo, Rf_install("pointer"), ptr); @@ -54,10 +49,8 @@ // {{{ ConnectionInputStream SEXP ConnectionInputStream_new(SEXP con, SEXP was_open) { NEW_S4_OBJECT("ConnectionInputStream"); - ConnectionInputStream* stream = - new ConnectionInputStream(con, (bool)LOGICAL(was_open)[0]); - ZeroCopyInputStreamWrapper* wrapper = - new ZeroCopyInputStreamWrapper(stream); + ConnectionInputStream* stream = new ConnectionInputStream(con, (bool)LOGICAL(was_open)[0]); + ZeroCopyInputStreamWrapper* wrapper = new ZeroCopyInputStreamWrapper(stream); SEXP ptr = PROTECT(R_MakeExternalPtr((void*)wrapper, R_NilValue, con)); R_RegisterCFinalizerEx(ptr, ZeroCopyInputStreamWrapper_finalizer, _FALSE_); SET_SLOT(oo, Rf_install("pointer"), ptr); @@ -97,20 +90,15 @@ // {{{ ArrayOutputStream // }}} // {{{ FileOutputStream -SEXP FileOutputStream_new(SEXP filename, SEXP block_size, - SEXP close_on_delete) { +SEXP FileOutputStream_new(SEXP filename, SEXP block_size, SEXP close_on_delete) { NEW_S4_OBJECT("FileOutputStream"); - int fd = open(CHAR(STRING_ELT(filename, 0)), - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); + int fd = open(CHAR(STRING_ELT(filename, 0)), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); - GPB::io::FileOutputStream* stream = - new GPB::io::FileOutputStream(fd, INTEGER(block_size)[0]); + GPB::io::FileOutputStream* stream = new GPB::io::FileOutputStream(fd, INTEGER(block_size)[0]); stream->SetCloseOnDelete(LOGICAL(close_on_delete)[0]); - ZeroCopyOutputStreamWrapper* wrapper = - new ZeroCopyOutputStreamWrapper(stream); + ZeroCopyOutputStreamWrapper* wrapper = new ZeroCopyOutputStreamWrapper(stream); - SEXP ptr = - PROTECT(R_MakeExternalPtr((void*)wrapper, R_NilValue, R_NilValue)); + SEXP ptr = PROTECT(R_MakeExternalPtr((void*)wrapper, R_NilValue, R_NilValue)); R_RegisterCFinalizerEx(ptr, ZeroCopyOutputStreamWrapper_finalizer, _FALSE_); SET_SLOT(oo, Rf_install("pointer"), ptr); @@ -140,10 +128,8 @@ // {{{ ConnectionOutputStream SEXP ConnectionOutputStream_new(SEXP con, SEXP was_open) { NEW_S4_OBJECT("ConnectionOutputStream"); - ConnectionOutputStream* stream = - new ConnectionOutputStream(con, (bool)LOGICAL(was_open)[0]); - ZeroCopyOutputStreamWrapper* wrapper = - new ZeroCopyOutputStreamWrapper(stream); + ConnectionOutputStream* stream = new ConnectionOutputStream(con, (bool)LOGICAL(was_open)[0]); + ZeroCopyOutputStreamWrapper* wrapper = new ZeroCopyOutputStreamWrapper(stream); /* we keep the R connection protected as long as the external pointer is kept out of GC */ SEXP ptr = PROTECT(R_MakeExternalPtr((void*)wrapper, R_NilValue, con)); @@ -162,8 +148,7 @@ GPB::io::CodedInputStream* coded_stream = GET_CIS(xp); int s = INTEGER(size)[0]; SEXP payload = PROTECT(Rf_allocVector(RAWSXP, s)); - if (!coded_stream->ReadRaw(RAW(payload), s)) - Rf_error("error reading raw bytes"); + if (!coded_stream->ReadRaw(RAW(payload), s)) Rf_error("error reading raw bytes"); UNPROTECT(1); /* payload */ return payload; } @@ -187,16 +172,14 @@ SEXP ZeroCopyInputStream_ReadLittleEndian32(SEXP xp) { GPB::io::CodedInputStream* coded_stream = GET_CIS(xp); uint32 res = 0; - if (!coded_stream->ReadVarint32(&res)) - Rf_error("error reading little endian int32"); + if (!coded_stream->ReadVarint32(&res)) Rf_error("error reading little endian int32"); return Rf_ScalarInteger(res); } SEXP ZeroCopyInputStream_ReadLittleEndian64(SEXP xp) { GPB::io::CodedInputStream* coded_stream = GET_CIS(xp); uint64 res = 0; - if (!coded_stream->ReadVarint64(&res)) - Rf_error("error reading little endian int32"); + if (!coded_stream->ReadVarint64(&res)) Rf_error("error reading little endian int32"); return Rf_ScalarReal((double)res); } Modified: pkg/src/wrapper_ArrayInputStream.cpp =================================================================== --- pkg/src/wrapper_ArrayInputStream.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/wrapper_ArrayInputStream.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -4,8 +4,8 @@ namespace rprotobuf { -RPB_FUNCTION_2(S4_ArrayInputStream, ArrayInputStream__new, - Rcpp::RawVector payload, int block_size) { +RPB_FUNCTION_2(S4_ArrayInputStream, ArrayInputStream__new, Rcpp::RawVector payload, + int block_size) { return S4_ArrayInputStream(payload, block_size); } } Modified: pkg/src/wrapper_ArrayOutputStream.cpp =================================================================== --- pkg/src/wrapper_ArrayOutputStream.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/wrapper_ArrayOutputStream.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -4,8 +4,7 @@ namespace rprotobuf { -RPB_FUNCTION_2(S4_ArrayOutputStream, ArrayOutputStream__new, int size, - int block_size) { +RPB_FUNCTION_2(S4_ArrayOutputStream, ArrayOutputStream__new, int size, int block_size) { return S4_ArrayOutputStream(size, block_size); } } Modified: pkg/src/wrapper_Descriptor.cpp =================================================================== --- pkg/src/wrapper_Descriptor.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/wrapper_Descriptor.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -11,8 +11,7 @@ RPB_XP_METHOD_0(METHOD(nested_type_count), GPB::Descriptor, nested_type_count) RPB_XP_METHOD_0(METHOD(enum_type_count), GPB::Descriptor, enum_type_count) -RPB_XP_METHOD_CAST_0(METHOD(containing_type), GPB::Descriptor, containing_type, - S4_Descriptor) +RPB_XP_METHOD_CAST_0(METHOD(containing_type), GPB::Descriptor, containing_type, S4_Descriptor) /** * returns the names of the members contained in the descriptor @@ -22,8 +21,7 @@ * * @return member names, as an R character vector (STRSXP) */ -RPB_FUNCTION_1(Rcpp::CharacterVector, METHOD(getMemberNames), - Rcpp::XPtr desc) { +RPB_FUNCTION_1(Rcpp::CharacterVector, METHOD(getMemberNames), Rcpp::XPtr desc) { int nfields = desc->field_count(); int ntypes = desc->nested_type_count(); @@ -84,33 +82,30 @@ return message; } -RPB_FUNCTION_2(S4_FieldDescriptor, METHOD(field), Rcpp::XPtr d, - int i) { +RPB_FUNCTION_2(S4_FieldDescriptor, METHOD(field), Rcpp::XPtr d, int i) { return d->field(i); } -RPB_FUNCTION_2(S4_FieldDescriptor, METHOD(FindFieldByNumber), - Rcpp::XPtr d, int num) { +RPB_FUNCTION_2(S4_FieldDescriptor, METHOD(FindFieldByNumber), Rcpp::XPtr d, + int num) { return d->FindFieldByNumber(num); } -RPB_FUNCTION_2(S4_FieldDescriptor, METHOD(FindFieldByName), - Rcpp::XPtr d, std::string nam) { +RPB_FUNCTION_2(S4_FieldDescriptor, METHOD(FindFieldByName), Rcpp::XPtr d, + std::string nam) { return d->FindFieldByName(nam); } -RPB_FUNCTION_2(S4_Descriptor, METHOD(nested_type), - Rcpp::XPtr d, int i) { +RPB_FUNCTION_2(S4_Descriptor, METHOD(nested_type), Rcpp::XPtr d, int i) { return d->nested_type(i); } -RPB_FUNCTION_2(S4_Descriptor, METHOD(FindNestedTypeByName), - Rcpp::XPtr d, std::string nam) { +RPB_FUNCTION_2(S4_Descriptor, METHOD(FindNestedTypeByName), Rcpp::XPtr d, + std::string nam) { return d->FindNestedTypeByName(nam); } -RPB_FUNCTION_2(S4_EnumDescriptor, METHOD(enum_type), - Rcpp::XPtr d, int i) { +RPB_FUNCTION_2(S4_EnumDescriptor, METHOD(enum_type), Rcpp::XPtr d, int i) { return d->enum_type(i); } @@ -120,26 +115,23 @@ // return d->FindEnumTypeByName( i ) ; // } -RPB_FUNCTION_1(S4_FileDescriptor, METHOD(fileDescriptor), - Rcpp::XPtr desc) { +RPB_FUNCTION_1(S4_FileDescriptor, METHOD(fileDescriptor), Rcpp::XPtr desc) { return S4_FileDescriptor(desc->file()); } -RPB_FUNCTION_2(std::string, METHOD(name), Rcpp::XPtr d, - bool full) { +RPB_FUNCTION_2(std::string, METHOD(name), Rcpp::XPtr d, bool full) { return full ? d->full_name() : d->name(); } -RPB_FUNCTION_2(S4_Message, METHOD(readMessageFromFile), - Rcpp::XPtr desc, std::string filename) { +RPB_FUNCTION_2(S4_Message, METHOD(readMessageFromFile), Rcpp::XPtr desc, + std::string filename) { /* open the file to read in binary mode */ int file = open(filename.c_str(), O_RDONLY | O_BINARY); /* 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()"); + throw std::range_error("could not call factory->GetPrototype(desc)->New()"); } /* read the message from the file */ @@ -148,8 +140,8 @@ return (S4_Message(message)); } -RPB_FUNCTION_2(S4_Message, METHOD(readMessageFromConnection), - Rcpp::XPtr desc, int conn_id) { +RPB_FUNCTION_2(S4_Message, METHOD(readMessageFromConnection), Rcpp::XPtr desc, + int conn_id) { RconnectionCopyingInputStream wrapper(conn_id); GPB::io::CopyingInputStreamAdaptor stream(&wrapper); GPB::io::CodedInputStream coded_stream(&stream); @@ -157,8 +149,7 @@ /* 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()"); + throw std::range_error("could not call factory->GetPrototype(desc)->New()"); } message->ParsePartialFromCodedStream(&coded_stream); @@ -166,42 +157,39 @@ return res; } -RPB_FUNCTION_2(S4_Message, METHOD(readMessageFromRawVector), - Rcpp::XPtr desc, Rcpp::RawVector raw) { +RPB_FUNCTION_2(S4_Message, METHOD(readMessageFromRawVector), Rcpp::XPtr desc, + Rcpp::RawVector raw) { GPB::io::ArrayInputStream ais((void*)raw.begin(), raw.size()); GPB::io::CodedInputStream stream(&ais); GPB::Message* message = PROTOTYPE(desc); if (!message) { - throw std::range_error( - "could not call factory->GetPrototype(desc)->New()"); + throw std::range_error("could not call factory->GetPrototype(desc)->New()"); } message->MergePartialFromCodedStream(&stream); return (S4_Message(message)); } -RPB_FUNCTION_2(S4_Message, METHOD(readASCIIFromString), - Rcpp::XPtr desc, std::string input) { +RPB_FUNCTION_2(S4_Message, METHOD(readASCIIFromString), Rcpp::XPtr desc, + std::string input) { GPB::Message* message = PROTOTYPE(desc); if (GPB::TextFormat::ParseFromString(input, message)) { return (S4_Message(message)); } else { - throw std::range_error( - "Could not parse ASCII protocol buffer from text string."); + throw std::range_error("Could not parse ASCII protocol buffer from text string."); } } -RPB_FUNCTION_2(S4_Message, METHOD(readASCIIFromConnection), - Rcpp::XPtr desc, int conn_id) { +RPB_FUNCTION_2(S4_Message, METHOD(readASCIIFromConnection), Rcpp::XPtr 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()"); + throw std::range_error("could not call factory->GetPrototype(desc)->New()"); } if (!GPB::TextFormat::Parse(&stream, message)) { throw std::range_error("Could not parse ASCII protocol buffer."); Modified: pkg/src/wrapper_EnumDescriptor.cpp =================================================================== --- pkg/src/wrapper_EnumDescriptor.cpp 2013-12-30 21:49:04 UTC (rev 651) +++ pkg/src/wrapper_EnumDescriptor.cpp 2013-12-30 22:23:44 UTC (rev 652) @@ -29,13 +29,12 @@ RPB_XP_METHOD_0(METHOD(length), GPB::EnumDescriptor, value_count) RPB_XP_METHOD_0(METHOD(value_count), GPB::EnumDescriptor, value_count) -RPB_FUNCTION_1(S4_Descriptor, METHOD(containing_type), - Rcpp::XPtr d) { +RPB_FUNCTION_1(S4_Descriptor, METHOD(containing_type), Rcpp::XPtr d) { return S4_Descriptor(d->containing_type()); } -RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByIndex), - Rcpp::XPtr d, int index) { +RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByIndex), Rcpp::XPtr d, + int index) { if ((index >= 0) && (index < d->value_count())) { return S4_EnumValueDescriptor(d->value(index)); } else { @@ -43,17 +42,16 @@ } } -RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByNumber), - Rcpp::XPtr d, int i) { +RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByNumber), Rcpp::XPtr d, + int i) { return S4_EnumValueDescriptor(d->FindValueByNumber(i)); } -RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByName), - Rcpp::XPtr d, std::string name) { +RPB_FUNCTION_2(S4_EnumValueDescriptor, METHOD(getValueByName), Rcpp::XPtr d, + std::string name) { return S4_EnumValueDescriptor(d->FindValueByName(name)); } -RPB_FUNCTION_1(S4_Message, METHOD(as_Message), - Rcpp::XPtr d) { +RPB_FUNCTION_1(S4_Message, METHOD(as_Message), Rcpp::XPtr d) { GPB::EnumDescriptorProto* message = new GPB::EnumDescriptorProto(); d->CopyTo(message); return S4_Message(message); @@ -67,8 +65,7 @@ * * @param the value associated with the name */ -RPB_FUNCTION_2(int, get_value_of_enum, Rcpp::XPtr d, - std::string name) { +RPB_FUNCTION_2(int, get_value_of_enum, Rcpp::XPtr d, std::string name) { const GPB::EnumValueDescriptor* evd = d->FindValueByName(name); if (!evd) { @@ -85,8 +82,7 @@ * @param name the name of the enum * @return logical */ -RPB_FUNCTION_2(bool, has_enum_name, Rcpp::XPtr d, - std::string name) { +RPB_FUNCTION_2(bool, has_enum_name, Rcpp::XPtr d, std::string name) { const GPB::EnumValueDescriptor* evd = d->FindValueByName(name); return (evd != NULL); } @@ -95,8 +91,7 @@ * @param xp external pointer to a Descriptor * @return the descriptor as an R list */ -RPB_FUNCTION_1(Rcpp::IntegerVector, METHOD(as_list), - Rcpp::XPtr d) { +RPB_FUNCTION_1(Rcpp::IntegerVector, METHOD(as_list), Rcpp::XPtr d) { int n = d->value_count(); Rcpp::IntegerVector values(n); @@ -111,8 +106,7 @@ return values; } -RPB_FUNCTION_1(Rcpp::CharacterVector, METHOD(getConstantNames), - Rcpp::XPtr d) { +RPB_FUNCTION_1(Rcpp::CharacterVector, METHOD(getConstantNames), Rcpp::XPtr d) { int n = d->value_count(); Rcpp::CharacterVector res(n); for (int i = 0; i < n; i++) { @@ -121,13 +115,11 @@ return res; } -RPB_FUNCTION_1(S4_FileDescriptor, METHOD(fileDescriptor), - Rcpp::XPtr desc) { +RPB_FUNCTION_1(S4_FileDescriptor, METHOD(fileDescriptor), Rcpp::XPtr desc) { return S4_FileDescriptor(desc->file()); } -RPB_FUNCTION_2(std::string, METHOD(name), Rcpp::XPtr d, - bool full) { +RPB_FUNCTION_2(std::string, METHOD(name), Rcpp::XPtr d, bool full) { return full ? d->full_name() : d->name(); } [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rprotobuf -r 652 From noreply at r-forge.r-project.org Mon Dec 30 23:28:10 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 23:28:10 +0100 (CET) Subject: [Rprotobuf-commits] r653 - pkg/src Message-ID: <20131230222810.D918D186A1B@r-forge.r-project.org> Author: murray Date: 2013-12-30 23:28:10 +0100 (Mon, 30 Dec 2013) New Revision: 653 Modified: pkg/src/RWarningErrorCollector.h pkg/src/S4_classes.h pkg/src/rprotobuf.h Log: Increase to 100-char column limit to avoid line-breaking too many long lines. Modified: pkg/src/RWarningErrorCollector.h =================================================================== --- pkg/src/RWarningErrorCollector.h 2013-12-30 22:23:44 UTC (rev 652) +++ pkg/src/RWarningErrorCollector.h 2013-12-30 22:28:10 UTC (rev 653) @@ -5,8 +5,7 @@ class RWarningErrorCollector : public GPB::compiler::MultiFileErrorCollector { public: // implements ErrorCollector --------------------------------------- - void AddError(const std::string& filename, int line, int column, - const std::string& message); + void AddError(const std::string& filename, int line, int column, const std::string& message); }; } // namespace rprotobuf Modified: pkg/src/S4_classes.h =================================================================== --- pkg/src/S4_classes.h 2013-12-30 22:23:44 UTC (rev 652) +++ pkg/src/S4_classes.h 2013-12-30 22:28:10 UTC (rev 653) @@ -24,8 +24,7 @@ class S4_EnumValueDescriptor : public Rcpp::S4 { public: - S4_EnumValueDescriptor(const GPB::EnumValueDescriptor* d) - : S4("EnumValueDescriptor") { + S4_EnumValueDescriptor(const GPB::EnumValueDescriptor* d) : S4("EnumValueDescriptor") { if (d) { slot("pointer") = Rcpp::XPtr( @@ -37,9 +36,7 @@ } } - S4_EnumValueDescriptor(const S4_EnumValueDescriptor& other) : S4() { - setSEXP(other.asSexp()); - } + S4_EnumValueDescriptor(const S4_EnumValueDescriptor& other) : S4() { setSEXP(other.asSexp()); } S4_EnumValueDescriptor& operator=(const S4_EnumValueDescriptor& other) { setSEXP(other.asSexp()); return *this; @@ -49,8 +46,7 @@ class S4_Descriptor : public Rcpp::S4 { public: S4_Descriptor(const GPB::Descriptor* d) : S4("Descriptor") { - slot("pointer") = - Rcpp::XPtr(const_cast(d), false); + slot("pointer") = Rcpp::XPtr(const_cast(d), false); if (!d) { slot("type") = Rcpp::StringVector(0); } else { @@ -58,9 +54,7 @@ } } - S4_Descriptor(const S4_Descriptor& other) : S4() { - setSEXP(other.asSexp()); - } + S4_Descriptor(const S4_Descriptor& other) : S4() { setSEXP(other.asSexp()); } S4_Descriptor& operator=(const S4_Descriptor& other) { setSEXP(other.asSexp()); return *this; @@ -70,8 +64,8 @@ class S4_FileDescriptor : public Rcpp::S4 { public: S4_FileDescriptor(const GPB::FileDescriptor* d) : S4("FileDescriptor") { - slot("pointer") = Rcpp::XPtr( - const_cast(d), false); + slot("pointer") = + Rcpp::XPtr(const_cast(d), false); if (!d) { slot("package") = Rcpp::StringVector(0); slot("filename") = Rcpp::StringVector(0); @@ -81,9 +75,7 @@ } } - S4_FileDescriptor(const S4_FileDescriptor& other) : S4() { - setSEXP(other.asSexp()); - } + S4_FileDescriptor(const S4_FileDescriptor& other) : S4() { setSEXP(other.asSexp()); } S4_FileDescriptor& operator=(const S4_FileDescriptor& other) { setSEXP(other.asSexp()); return *this; @@ -93,16 +85,14 @@ class S4_FieldDescriptor : public Rcpp::S4 { public: S4_FieldDescriptor(const GPB::FieldDescriptor* d) : S4("FieldDescriptor") { - slot("pointer") = Rcpp::XPtr( - const_cast(d), false); + slot("pointer") = + Rcpp::XPtr(const_cast(d), false); slot("name") = d->name(); slot("full_name") = d->full_name(); slot("type") = d->containing_type()->full_name(); } - S4_FieldDescriptor(const S4_FieldDescriptor& other) : S4() { - setSEXP(other.asSexp()); - } + S4_FieldDescriptor(const S4_FieldDescriptor& other) : S4() { setSEXP(other.asSexp()); } S4_FieldDescriptor& operator=(const S4_FieldDescriptor& other) { setSEXP(other.asSexp()); return *this; @@ -111,15 +101,12 @@ class S4_ServiceDescriptor : public Rcpp::S4 { public: - S4_ServiceDescriptor(const GPB::ServiceDescriptor* d) - : S4("ServiceDescriptor") { - slot("pointer") = Rcpp::XPtr( - const_cast(d), false); + S4_ServiceDescriptor(const GPB::ServiceDescriptor* d) : S4("ServiceDescriptor") { + slot("pointer") = + Rcpp::XPtr(const_cast(d), false); } - S4_ServiceDescriptor(const S4_ServiceDescriptor& other) : S4() { - setSEXP(other.asSexp()); - } + S4_ServiceDescriptor(const S4_ServiceDescriptor& other) : S4() { setSEXP(other.asSexp()); } S4_ServiceDescriptor& operator=(const S4_ServiceDescriptor& other) { setSEXP(other.asSexp()); return *this; @@ -128,15 +115,12 @@ class S4_MethodDescriptor : public Rcpp::S4 { public: - S4_MethodDescriptor(const GPB::MethodDescriptor* d) - : S4("MethodDescriptor") { - slot("pointer") = Rcpp::XPtr( - const_cast(d), false); + S4_MethodDescriptor(const GPB::MethodDescriptor* d) : S4("MethodDescriptor") { + slot("pointer") = + Rcpp::XPtr(const_cast(d), false); } - S4_MethodDescriptor(const S4_MethodDescriptor& other) : S4() { - setSEXP(other.asSexp()); - } + S4_MethodDescriptor(const S4_MethodDescriptor& other) : S4() { setSEXP(other.asSexp()); } S4_MethodDescriptor& operator=(const S4_MethodDescriptor& other) { setSEXP(other.asSexp()); return *this; @@ -146,8 +130,8 @@ class S4_EnumDescriptor : public Rcpp::S4 { public: S4_EnumDescriptor(const GPB::EnumDescriptor* d) : S4("EnumDescriptor") { - slot("pointer") = Rcpp::XPtr( - const_cast(d), false); + slot("pointer") = + Rcpp::XPtr(const_cast(d), false); slot("type") = Rcpp::StringVector(0); if (d) { slot("name") = d->name(); @@ -162,9 +146,7 @@ } } - S4_EnumDescriptor(const S4_EnumDescriptor& other) : S4() { - setSEXP(other.asSexp()); - } + S4_EnumDescriptor(const S4_EnumDescriptor& other) : S4() { setSEXP(other.asSexp()); } S4_EnumDescriptor& operator=(const S4_EnumDescriptor& other) { setSEXP(other.asSexp()); return *this; @@ -174,8 +156,7 @@ class S4_Message : public Rcpp::S4 { public: S4_Message(const GPB::Message* d) : S4("Message") { - slot("pointer") = - Rcpp::XPtr(const_cast(d), true); + slot("pointer") = Rcpp::XPtr(const_cast(d), true); slot("type") = d->GetDescriptor()->full_name(); } S4_Message(const S4_Message& other) : S4() { setSEXP(other.asSexp()); } @@ -194,14 +175,12 @@ GPB::io::ArrayOutputStream* stream = new GPB::io::ArrayOutputStream(payload.begin(), size, block_size); - Rcpp::XPtr wrapper( - new ZeroCopyOutputStreamWrapper(stream), true, R_NilValue, payload); + Rcpp::XPtr wrapper(new ZeroCopyOutputStreamWrapper(stream), + true, R_NilValue, payload); slot("pointer") = wrapper; } - S4_ArrayOutputStream(const S4_ArrayOutputStream& other) { - setSEXP(other.asSexp()); - } + S4_ArrayOutputStream(const S4_ArrayOutputStream& other) { setSEXP(other.asSexp()); } S4_ArrayOutputStream& operator=(const S4_ArrayOutputStream& other) { setSEXP(other.asSexp()); return *this; @@ -210,10 +189,9 @@ class S4_ArrayInputStream : public Rcpp::S4 { public: - S4_ArrayInputStream(Rcpp::RawVector payload, int block_size) - : S4("ArrayInputStream") { - GPB::io::ArrayInputStream* stream = new GPB::io::ArrayInputStream( - payload.begin(), payload.size(), block_size); + S4_ArrayInputStream(Rcpp::RawVector payload, int block_size) : S4("ArrayInputStream") { + GPB::io::ArrayInputStream* stream = + new GPB::io::ArrayInputStream(payload.begin(), payload.size(), block_size); Rcpp::XPtr wrapper( new ZeroCopyInputStreamWrapper(stream), true, R_NilValue, payload); slot("pointer") = wrapper; Modified: pkg/src/rprotobuf.h =================================================================== --- pkg/src/rprotobuf.h 2013-12-30 22:23:44 UTC (rev 652) +++ pkg/src/rprotobuf.h 2013-12-30 22:28:10 UTC (rev 653) @@ -93,21 +93,18 @@ #define GET_DESCRIPTOR_POINTER_FROM_S4(m) \ (GPB::Descriptor*) EXTPTR_PTR(GET_SLOT(m, Rf_install("pointer"))) -#define GET_FIELD_DESCRIPTOR_POINTER_FROM_XP(xp) \ - (GPB::FieldDescriptor*) EXTPTR_PTR(xp) +#define GET_FIELD_DESCRIPTOR_POINTER_FROM_XP(xp) (GPB::FieldDescriptor*) EXTPTR_PTR(xp) #define GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(m) \ (GPB::FieldDescriptor*) EXTPTR_PTR(GET_SLOT(m, Rf_install("pointer"))) -#define GET_ENUM_VALUE_DESCRIPTOR_POINTER_FROM_XP(xp) \ - (GPB::EnumValueDescriptor*) EXTPTR_PTR(xp) +#define GET_ENUM_VALUE_DESCRIPTOR_POINTER_FROM_XP(xp) (GPB::EnumValueDescriptor*) EXTPTR_PTR(xp) #define GET_ENUM_VALUE_DESCRIPTOR_POINTER_FROM_S4(m) \ (GPB::EnumValueDescriptor*) EXTPTR_PTR(GET_SLOT(m, Rf_install("pointer"))) #define GET_METHOD(xp) (GPB::MethodDescriptor*) EXTPTR_PTR(xp) #define COPYSTRING(s) s -#define THROW_SOCKET_ERROR(message) \ - Rf_error("%s : %s", message, strerror(sockerrno)) +#define THROW_SOCKET_ERROR(message) Rf_error("%s : %s", message, strerror(sockerrno)) #define XPP EXTPTR_PTR @@ -135,8 +132,7 @@ /* in extractors.cpp */ RcppExport SEXP getMessageField(SEXP, SEXP); -RcppExport SEXP extractFieldAsSEXP(const Rcpp::XPtr&, - const GPB::FieldDescriptor*); +RcppExport SEXP extractFieldAsSEXP(const Rcpp::XPtr&, const GPB::FieldDescriptor*); /* in lookup.cpp */ RcppExport SEXP newProtocolBufferLookup(SEXP); @@ -247,14 +243,11 @@ #define GET_ZCIS(xp) ((ZeroCopyInputStreamWrapper*)XPP(xp))->get_stream() #define GET_CIS(xp) ((ZeroCopyInputStreamWrapper*)XPP(xp))->get_coded_stream() -#define GET_FIS(xp) \ - (GPB::io::FileInputStream*)((ZeroCopyInputStreamWrapper*)XPP(xp)) \ - ->get_stream() +#define GET_FIS(xp) (GPB::io::FileInputStream*)((ZeroCopyInputStreamWrapper*)XPP(xp))->get_stream() #define GET_ZCOS(xp) ((ZeroCopyOutputStreamWrapper*)XPP(xp))->get_stream() #define GET_COS(xp) ((ZeroCopyOutputStreamWrapper*)XPP(xp))->get_coded_stream() -#define GET_FOS(xp) \ - (GPB::io::FileOutputStream*)((ZeroCopyOutputStreamWrapper*)XPP(xp)) \ - ->get_stream() +#define GET_FOS(xp) \ + (GPB::io::FileOutputStream*)((ZeroCopyOutputStreamWrapper*)XPP(xp))->get_stream() #endif From noreply at r-forge.r-project.org Mon Dec 30 23:32:30 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 23:32:30 +0100 (CET) Subject: [Rprotobuf-commits] r654 - pkg/src Message-ID: <20131230223231.08FF1186A85@r-forge.r-project.org> Author: murray Date: 2013-12-30 23:32:30 +0100 (Mon, 30 Dec 2013) New Revision: 654 Modified: pkg/src/streams.cpp Log: Remove one last emacs file-level configuration comment. If we add them back we'll add back uniform ones in some automated way. Modified: pkg/src/streams.cpp =================================================================== --- pkg/src/streams.cpp 2013-12-30 22:28:10 UTC (rev 653) +++ pkg/src/streams.cpp 2013-12-30 22:32:30 UTC (rev 654) @@ -2,8 +2,6 @@ #include "ConnectionInputStream.h" #include "ConnectionOutputStream.h" -/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ - namespace rprotobuf { void ZeroCopyInputStreamWrapper_finalizer(SEXP xp) { delete (ZeroCopyInputStreamWrapper*)XPP(xp); } From noreply at r-forge.r-project.org Mon Dec 30 23:40:05 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 23:40:05 +0100 (CET) Subject: [Rprotobuf-commits] r655 - / Message-ID: <20131230224005.3C95B18100D@r-forge.r-project.org> Author: murray Date: 2013-12-30 23:40:04 +0100 (Mon, 30 Dec 2013) New Revision: 655 Modified: STYLE Log: Update the style file to note the basics of the new conventiosn, update the clang-format command line, and explain why 5 specific files have been spared for now. Modified: STYLE =================================================================== --- STYLE 2013-12-30 22:32:30 UTC (rev 654) +++ STYLE 2013-12-30 22:40:04 UTC (rev 655) @@ -1,10 +1,34 @@ -The RProtoBuf code base is a mix of many coding styles regarding -indentation, spaces, braces, and more. +Notes on Coding Style (C++ only for now). -Murray proposes running the whole code base through +1. Conventions: spacing, column limit, etc. +2. clang-format +3. excluded files +4. Emacs FoldingMode annotations. - clang-format -style="{BasedOnStyle: google, IndentWidth: 4}" -i *.cpp +1. Conventions: spacing, column limit, etc. +------------------------------------------------------------------------------- + +In December 2013 a pass was made through the code base with +clang-format to enforce consistency among several competing styles +that were used in the code base. The new style requires: + +1) 4-space indents +2) 100-character column limit +3) no indentation for top level objects inside 'namespace {' +4) no space inside opening/closing parenthesis of argument lists '(arg1, arg2)' +5) space before open brackets. +6) open brackets on same line as if conditional or switch statement. + +These conventions can be changed, so long as the code base remains consistent. + +2. clang-format +------------------------------------------------------------------------------- + +These conventions can automatically be applied to files with: + + clang-format -style="{BasedOnStyle: google, IndentWidth: 4, ColumnLimit: 100}" -i *.cpp + There are a number of other parameters that can be set however, see the full output of clang-format -dump-config @@ -13,10 +37,28 @@ svn diff -x -w -This will still pull up all the changes where lines were broken at 80 +This will still pull up all the changes where lines were broken at 100 characters or braces changed lines, but will ignore most of the pure whitespace changes for reviewing purposes before submitting. -After the code base has been converted with clang-format, the emacs -metadata comments at the top of each file will need to be updated as -well. \ No newline at end of file +3. excluded files +------------------------------------------------------------------------------- + +We exclude sisocks.h from style issues as it is written separately by +Simon Urbanek. + +We exclude mutators.cpp and extractors.cpp temporarily as many other +changes were made to those files recently and we want to allow more +review before obfuscating the content changes with whitespace changes. + +We exclude Rcppsupport.h and RcppMacros.h because I don't like the +result. I want BEGIN_RCPP on its own line, for example. + +4. Emacs FoldingMode annotations. +------------------------------------------------------------------------------- + +Some of the files include '{{{' '}}}' annotations in comments that are +used to fold/unfold sections of code with Emacs folding mode (M-x +folding-mode). You can then right click to expand/hide these sections +to get a higher level view of the file or drill down into specific +sections of the code. From noreply at r-forge.r-project.org Mon Dec 30 23:53:11 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Mon, 30 Dec 2013 23:53:11 +0100 (CET) Subject: [Rprotobuf-commits] r656 - pkg/src Message-ID: <20131230225311.457E21868BE@r-forge.r-project.org> Author: murray Date: 2013-12-30 23:53:10 +0100 (Mon, 30 Dec 2013) New Revision: 656 Modified: pkg/src/Rcppsupport.h Log: whitespace change only. make this more consistent with the other files (manually, I don't like what clang-format did to one of the macros). Modified: pkg/src/Rcppsupport.h =================================================================== --- pkg/src/Rcppsupport.h 2013-12-30 22:40:04 UTC (rev 655) +++ pkg/src/Rcppsupport.h 2013-12-30 22:53:10 UTC (rev 656) @@ -22,13 +22,13 @@ #include "rprotobuf.h" -namespace rprotobuf{ +namespace rprotobuf { /* support for Rcpp::wrap protobuf repeated fields, this essentially uses the same macro trick as in protobuf, but reversed */ -struct enum_field{} ; -struct message_field{} ; +struct enum_field{}; +struct message_field{}; class Int64AsStringRepeatedFieldImporter { public: @@ -36,44 +36,44 @@ typedef string r_import_type; Int64AsStringRepeatedFieldImporter(const GPB::Reflection* ref_ , const GPB::Message& message_, - const GPB::FieldDescriptor* field_): - ref(ref_), message(message_), field(field_){} + const GPB::FieldDescriptor* field_) + : ref(ref_), message(message_), field(field_) {} inline int size() const { - return ref->FieldSize( message, field ) ; + return ref->FieldSize(message, field); } inline string get(int i) const { stringstream stream; - int64 val = ref->GetRepeatedInt64(message, field, i) ; + int64 val = ref->GetRepeatedInt64(message, field, i); stream << val; return stream.str(); } private: - const GPB::Reflection* ref ; - const GPB::Message& message ; - const GPB::FieldDescriptor* field ; + const GPB::Reflection* ref; + const GPB::Message& message; + const GPB::FieldDescriptor* field; }; class UInt64AsStringRepeatedFieldImporter { public: // Probably want to convert to strings here. typedef string r_import_type; - UInt64AsStringRepeatedFieldImporter(const GPB::Reflection* ref_ , + UInt64AsStringRepeatedFieldImporter(const GPB::Reflection* ref_, const GPB::Message& message_, - const GPB::FieldDescriptor* field_): - ref(ref_), message(message_), field(field_){} + const GPB::FieldDescriptor* field_) + : ref(ref_), message(message_), field(field_) {} inline int size() const { - return ref->FieldSize( message, field ) ; + return ref->FieldSize(message, field) ; } inline string get(int i) const { stringstream stream; - uint64 val = ref->GetRepeatedUInt64(message, field, i) ; + uint64 val = ref->GetRepeatedUInt64(message, field, i); stream << val; return stream.str(); } private: - const GPB::Reflection* ref ; - const GPB::Message& message ; - const GPB::FieldDescriptor* field ; + const GPB::Reflection* ref; + const GPB::Message& message; + const GPB::FieldDescriptor* field; }; // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 @@ -84,94 +84,94 @@ typedef double r_import_type; UInt32RepeatedFieldImporter(const GPB::Reflection* ref_ , const GPB::Message& message_, - const GPB::FieldDescriptor* field_): - ref(ref_), message(message_), field(field_){} + const GPB::FieldDescriptor* field_) + : ref(ref_), message(message_), field(field_) {} inline int size() const { - return ref->FieldSize( message, field ) ; + return ref->FieldSize(message, field); } inline double get(int i) const { return double(ref->GetRepeatedUInt32(message, field, i)); } private: - const GPB::Reflection* ref ; - const GPB::Message& message ; - const GPB::FieldDescriptor* field ; + const GPB::Reflection* ref; + const GPB::Message& message; + const GPB::FieldDescriptor* field; }; template class RepeatedFieldImporter{} ; #undef GENERATE__FIELD__IMPORTER__DECL -#define GENERATE__FIELD__IMPORTER__DECL(__TYPE__,__CAMEL__) \ -template<> class RepeatedFieldImporter<__TYPE__>{ \ -public: \ - typedef __TYPE__ r_import_type ; \ - RepeatedFieldImporter( \ - const GPB::Reflection* ref_ , \ - const GPB::Message& message_, \ - const GPB::FieldDescriptor* field_): \ - ref(ref_), message(message_), field(field_){} \ - inline int size() const { \ - return ref->FieldSize( message, field ) ; \ - } \ - inline __TYPE__ get(int i) const { \ - return ref->GetRepeated##__CAMEL__(message, field, i) ; \ - } \ -private: \ - const GPB::Reflection* ref ; \ - const GPB::Message& message ; \ - const GPB::FieldDescriptor* field ; \ -} ; \ +#define GENERATE__FIELD__IMPORTER__DECL(__TYPE__, __CAMEL__) \ +template<> class RepeatedFieldImporter<__TYPE__> { \ +public: \ + typedef __TYPE__ r_import_type; \ + RepeatedFieldImporter( \ + const GPB::Reflection* ref_, \ + const GPB::Message& message_, \ + const GPB::FieldDescriptor* field_): \ + ref(ref_), message(message_), field(field_) {} \ + inline int size() const { \ + return ref->FieldSize( message, field ); \ + } \ + inline __TYPE__ get(int i) const { \ + return ref->GetRepeated##__CAMEL__(message, field, i); \ + } \ +private: \ + const GPB::Reflection* ref; \ + const GPB::Message& message; \ + const GPB::FieldDescriptor* field; \ +}; -GENERATE__FIELD__IMPORTER__DECL(GPB::int32 ,Int32) -GENERATE__FIELD__IMPORTER__DECL(GPB::uint32,UInt32) -GENERATE__FIELD__IMPORTER__DECL(GPB::int64,Int64) -GENERATE__FIELD__IMPORTER__DECL(GPB::uint64,UInt64) -GENERATE__FIELD__IMPORTER__DECL(float,Float) -GENERATE__FIELD__IMPORTER__DECL(double,Double) -GENERATE__FIELD__IMPORTER__DECL(bool,Bool) -GENERATE__FIELD__IMPORTER__DECL(std::string,String) +GENERATE__FIELD__IMPORTER__DECL(GPB::int32, Int32) +GENERATE__FIELD__IMPORTER__DECL(GPB::uint32, UInt32) +GENERATE__FIELD__IMPORTER__DECL(GPB::int64, Int64) +GENERATE__FIELD__IMPORTER__DECL(GPB::uint64, UInt64) +GENERATE__FIELD__IMPORTER__DECL(float, Float) +GENERATE__FIELD__IMPORTER__DECL(double, Double) +GENERATE__FIELD__IMPORTER__DECL(bool, Bool) +GENERATE__FIELD__IMPORTER__DECL(std::string, String) #undef GENERATE__FIELD__IMPORTER__DECL template<> class RepeatedFieldImporter{ public: typedef int r_import_type ; - RepeatedFieldImporter( - const GPB::Reflection* ref_ , - const GPB::Message& message_, - const GPB::FieldDescriptor* field_): - ref(ref_), message(message_), field(field_){} ; + RepeatedFieldImporter( + const GPB::Reflection* ref_, + const GPB::Message& message_, + const GPB::FieldDescriptor* field_): + ref(ref_), message(message_), field(field_) {}; inline int size() const { - return ref->FieldSize( message, field ) ; + return ref->FieldSize( message, field ); } inline int get(int i) const { - return ref->GetRepeatedEnum(message, field, i)->number() ; + return ref->GetRepeatedEnum(message, field, i)->number(); } private: - const GPB::Reflection* ref ; - const GPB::Message& message ; - const GPB::FieldDescriptor* field ; + const GPB::Reflection* ref; + const GPB::Message& message; + const GPB::FieldDescriptor* field; } ; template<> class RepeatedFieldImporter{ public: typedef message_field r_import_type ; - RepeatedFieldImporter( - const GPB::Reflection* ref_ , - const GPB::Message& message_, - const GPB::FieldDescriptor* field_): - ref(ref_), message(message_), field(field_){} ; + RepeatedFieldImporter( + const GPB::Reflection* ref_ , + const GPB::Message& message_, + const GPB::FieldDescriptor* field_): + ref(ref_), message(message_), field(field_) {}; inline int size() const { - return ref->FieldSize( message, field ) ; + return ref->FieldSize( message, field ); } inline SEXP wrap(int i) const { - return S4_Message( CLONE( &ref->GetRepeatedMessage( message, field, i ) ) ) ; + return S4_Message(CLONE(&ref->GetRepeatedMessage(message, field, i))); } private: - const GPB::Reflection* ref ; - const GPB::Message& message ; - const GPB::FieldDescriptor* field ; -} ; + const GPB::Reflection* ref; + const GPB::Message& message; + const GPB::FieldDescriptor* field; +}; } // namespace rprotobuf From noreply at r-forge.r-project.org Tue Dec 31 00:00:20 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 00:00:20 +0100 (CET) Subject: [Rprotobuf-commits] r657 - pkg Message-ID: <20131230230020.BDC461869D4@r-forge.r-project.org> Author: murray Date: 2013-12-31 00:00:19 +0100 (Tue, 31 Dec 2013) New Revision: 657 Modified: pkg/TODO Log: Update to reflect changes today. Modified: pkg/TODO =================================================================== --- pkg/TODO 2013-12-30 22:53:10 UTC (rev 656) +++ pkg/TODO 2013-12-30 23:00:19 UTC (rev 657) @@ -10,7 +10,7 @@ o Add more packages that depend on or enhance RProtoBuf. o Improve exception handling to prevent cases where an Rcpp exception - crashes the interactive R instance. + crashes the interactive R instance. o Investigate Rcpp Modules support for some classes. Murray is not personally super enthusiastic about this one, as I think it may @@ -33,8 +33,10 @@ o finalizers [murray: what is needed here?] -o Clean up formatting / whitespace (its awful, run it all through - clang-format?) +o Clean up formatting / whitespace of R code. The C++ code is now + kept consistent through clang-format and a new emacs directory level + config in pkg/src, and the style guide notes in the STYLE file on + R-Forge. o Thoroughly audit extensions support and other deeply nested types support to ensure everything is implemented as expected. From noreply at r-forge.r-project.org Tue Dec 31 00:07:12 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 00:07:12 +0100 (CET) Subject: [Rprotobuf-commits] r658 - pkg/inst Message-ID: <20131230230712.5D309186AC1@r-forge.r-project.org> Author: murray Date: 2013-12-31 00:07:10 +0100 (Tue, 31 Dec 2013) New Revision: 658 Modified: pkg/inst/NEWS.Rd Log: Document more of the recent updates since the last release. Modified: pkg/inst/NEWS.Rd =================================================================== --- pkg/inst/NEWS.Rd 2013-12-30 23:00:19 UTC (rev 657) +++ pkg/inst/NEWS.Rd 2013-12-30 23:07:10 UTC (rev 658) @@ -10,7 +10,7 @@ Descriptor, EnumValueDescriptor, and FileDescriptor classes. \item Add missing export for \code{.DollarNames} EnumValueDescriptor to allow completion on that class. - \item Add more than 10 additional pages to the main Intro vignette + \item Add more than 15 additional pages to the main Intro vignette documenting better all of the S4 classes implemented by RProtoBuf, updating the type mapping tables to take into account 64-bit support, and documenting advanced features such as Extensions. @@ -32,6 +32,24 @@ instance. \item Update the project TODO file. \item Add better documentation and tests for all of the above. + \item Corrected the handling of uint32 and fixed32 types in protocol + buffers to ensure that they work with numbers as large as 2^32 - 1, + which is larger than an integer can hold in R since R does not have an + unsigned integer class. These values are stored as doubles internally + now to avoid losing precision. + \item Added unit tests to verify behavior of RProtoBuf with extreme + values for uint32 types. + \item Removed old exception handling code and instead rely on the + more modern Rcpp::stop method maintained in Rcpp. + \item Add better error messages when setting a repeated field of + messages to inform the user which element index was of the wrong type + and what the expected type was. + \item (internal) Added const qualifiers in more places throughout + the C++ code for type safety. + \item (internal) Standardize coding conventions of the C++ files and run them + through clang-format for consistency. A STYLE file has been submitted + to R-Forge with details about the coding standards and how they are + enforced with Emacs and clang-format. } } From noreply at r-forge.r-project.org Tue Dec 31 02:38:54 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 02:38:54 +0100 (CET) Subject: [Rprotobuf-commits] r659 - pkg/src Message-ID: <20131231013854.48C16186ACB@r-forge.r-project.org> Author: murray Date: 2013-12-31 02:38:53 +0100 (Tue, 31 Dec 2013) New Revision: 659 Modified: pkg/src/extractors.cpp pkg/src/mutators.cpp Log: clang-format the last 2 major C++ files now that the content changes here have been reviewed, integrated, and tested against my private branch. Modified: pkg/src/extractors.cpp =================================================================== --- pkg/src/extractors.cpp 2013-12-30 23:07:10 UTC (rev 658) +++ pkg/src/extractors.cpp 2013-12-31 01:38:53 UTC (rev 659) @@ -19,9 +19,9 @@ #include "fieldtypes.h" #include "Rcppsupport.h" -namespace rprotobuf{ +namespace rprotobuf { -const char * kIntStringOptionName = "RProtoBuf.int64AsString"; +const char* kIntStringOptionName = "RProtoBuf.int64AsString"; bool UseStringsForInt64() { static const SEXP option_name = Rf_install(kIntStringOptionName); return (Rf_asLogical(Rf_GetOption1(option_name))); @@ -30,22 +30,22 @@ // Rcpp::wrap silently coerces 64-bit integers to numerics // which drop precision for values between 2^53 - 2^64. // So, if an option is set, we return as a character string. -template +template SEXP Int64AsSEXP(ValueType value) { - BEGIN_RCPP - if (UseStringsForInt64()) { - std::stringstream ss; - if ((ss << value).fail()) { - // This should not happen, its a bug in the code. - string message = string("Error converting int64 to string, unset ") + - kIntStringOptionName + " option."; - Rcpp::stop(message.c_str()); - } - return Rcpp::CharacterVector(ss.str()); - } else { - return Rcpp::wrap(value); - } - END_RCPP + BEGIN_RCPP + if (UseStringsForInt64()) { + std::stringstream ss; + if ((ss << value).fail()) { + // This should not happen, its a bug in the code. + string message = string("Error converting int64 to string, unset ") + + kIntStringOptionName + " option."; + Rcpp::stop(message.c_str()); + } + return Rcpp::CharacterVector(ss.str()); + } else { + return Rcpp::wrap(value); + } + END_RCPP } /** @@ -54,148 +54,141 @@ * @param pointer external pointer to a message * @param name name of the field * - * @return the field called "name" of the message if the + * @return the field called "name" of the message if the * message has the field, otherwise an error is generated */ -SEXP getMessageField( SEXP pointer, SEXP name ){ - +SEXP getMessageField(SEXP pointer, SEXP name) { + #ifdef RPB_DEBUG -Rprintf( "\n" ) ; + Rprintf("\n"); -PRINT_DEBUG_INFO( "pointer", pointer ) ; -PRINT_DEBUG_INFO( "name", name ) ; + PRINT_DEBUG_INFO("pointer", pointer); + PRINT_DEBUG_INFO("name", name); #endif - /* grab the Message pointer */ - Rcpp::XPtr message(pointer) ; + /* grab the Message pointer */ + Rcpp::XPtr message(pointer); - GPB::FieldDescriptor* field_desc = getFieldDescriptor( message, name ) ; - + GPB::FieldDescriptor* field_desc = getFieldDescriptor(message, name); + #ifdef RPB_DEBUG -Rprintf( "\n" ) ; + Rprintf("\n"); #endif - return( extractFieldAsSEXP(message, field_desc) ) ; - + return (extractFieldAsSEXP(message, field_desc)); } -SEXP extractFieldAsSEXP( const Rcpp::XPtr& message, - const GPB::FieldDescriptor* fieldDesc ){ - BEGIN_RCPP - const Reflection * ref = message->GetReflection() ; - - if( fieldDesc->is_repeated() ){ - - switch( GPB::FieldDescriptor::TypeToCppType(fieldDesc->type()) ){ +SEXP extractFieldAsSEXP(const Rcpp::XPtr& message, + const GPB::FieldDescriptor* fieldDesc) { + BEGIN_RCPP + const Reflection* ref = message->GetReflection(); + if (fieldDesc->is_repeated()) { + + switch (GPB::FieldDescriptor::TypeToCppType(fieldDesc->type())) { + #undef HANDLE_REPEATED_FIELD -#define HANDLE_REPEATED_FIELD(TYPE,DATATYPE) \ - case TYPE : \ - return Rcpp::wrap( RepeatedFieldImporter(ref, *message, fieldDesc) ) ; \ +#define HANDLE_REPEATED_FIELD(TYPE, DATATYPE) \ + case TYPE: \ + return Rcpp::wrap(RepeatedFieldImporter(ref, *message, fieldDesc)); - HANDLE_REPEATED_FIELD(CPPTYPE_INT32, GPB::int32) ; - HANDLE_REPEATED_FIELD(CPPTYPE_DOUBLE, double) ; - HANDLE_REPEATED_FIELD(CPPTYPE_FLOAT, float) ; - HANDLE_REPEATED_FIELD(CPPTYPE_BOOL, bool) ; - HANDLE_REPEATED_FIELD(CPPTYPE_ENUM, enum_field ) ; - HANDLE_REPEATED_FIELD(CPPTYPE_MESSAGE, message_field ) ; - // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 - // See https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 - case CPPTYPE_UINT32: - return Rcpp::wrap( - UInt32RepeatedFieldImporter(ref, *message, - fieldDesc)); + HANDLE_REPEATED_FIELD(CPPTYPE_INT32, GPB::int32); + HANDLE_REPEATED_FIELD(CPPTYPE_DOUBLE, double); + HANDLE_REPEATED_FIELD(CPPTYPE_FLOAT, float); + HANDLE_REPEATED_FIELD(CPPTYPE_BOOL, bool); + HANDLE_REPEATED_FIELD(CPPTYPE_ENUM, enum_field); + HANDLE_REPEATED_FIELD(CPPTYPE_MESSAGE, message_field); + // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 + // See + // https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 + case CPPTYPE_UINT32: + return Rcpp::wrap(UInt32RepeatedFieldImporter(ref, *message, fieldDesc)); #ifdef RCPP_HAS_LONG_LONG_TYPES // We can't handle these the same way, because Rcpp::wrap silently // casts int64s to doubles which may cause us to lose precision. case CPPTYPE_INT64: if (UseStringsForInt64()) { - return Rcpp::wrap( - Int64AsStringRepeatedFieldImporter(ref, *message, - fieldDesc)); + return Rcpp::wrap(Int64AsStringRepeatedFieldImporter(ref, *message, fieldDesc)); } else { - return Rcpp::wrap( - RepeatedFieldImporter(ref, *message, fieldDesc)); + return Rcpp::wrap(RepeatedFieldImporter(ref, *message, fieldDesc)); } case CPPTYPE_UINT64: if (UseStringsForInt64()) { return Rcpp::wrap( - UInt64AsStringRepeatedFieldImporter(ref, *message, - fieldDesc)); + UInt64AsStringRepeatedFieldImporter(ref, *message, fieldDesc)); } else { - return Rcpp::wrap( - RepeatedFieldImporter(ref, *message, fieldDesc)); + return Rcpp::wrap(RepeatedFieldImporter(ref, *message, fieldDesc)); } #endif #undef HANDLE_REPEATED_FIELD - case CPPTYPE_STRING: - if (fieldDesc->type() == TYPE_STRING) { - return Rcpp::wrap( RepeatedFieldImporter(ref, *message, fieldDesc) ) ; - } else if (fieldDesc->type() == TYPE_BYTES) { - int field_size = ref->FieldSize( *message, fieldDesc ) ; - Rcpp::List res(field_size); - for (int i=0; iGetRepeatedString(*message, fieldDesc, i); - res[i] = Rcpp::wrap(std::vector(s.begin(), s.end())); - } - return res; - } else { - Rcpp::stop("unknown field type with CPP_TYPE STRING"); - } - - default: - Rcpp::stop("Unsupported type"); - } - + case CPPTYPE_STRING: + if (fieldDesc->type() == TYPE_STRING) { + return Rcpp::wrap(RepeatedFieldImporter(ref, *message, fieldDesc)); + } else if (fieldDesc->type() == TYPE_BYTES) { + int field_size = ref->FieldSize(*message, fieldDesc); + Rcpp::List res(field_size); + for (int i = 0; i < field_size; i++) { + std::string s = ref->GetRepeatedString(*message, fieldDesc, i); + res[i] = Rcpp::wrap(std::vector(s.begin(), s.end())); + } + return res; + } else { + Rcpp::stop("unknown field type with CPP_TYPE STRING"); + } + + default: + Rcpp::stop("Unsupported type"); + } + } else { - switch( GPB::FieldDescriptor::TypeToCppType(fieldDesc->type()) ){ + switch (GPB::FieldDescriptor::TypeToCppType(fieldDesc->type())) { #undef HANDLE_SINGLE_FIELD -#define HANDLE_SINGLE_FIELD(CPPTYPE,SUFFIX) \ - case CPPTYPE: \ - return Rcpp::wrap( ref->Get##SUFFIX(*message, fieldDesc ) ) ; +#define HANDLE_SINGLE_FIELD(CPPTYPE, SUFFIX) \ + case CPPTYPE: \ + return Rcpp::wrap(ref->Get##SUFFIX(*message, fieldDesc)); - HANDLE_SINGLE_FIELD( CPPTYPE_INT32, Int32 ); - HANDLE_SINGLE_FIELD( CPPTYPE_DOUBLE, Double ); - HANDLE_SINGLE_FIELD( CPPTYPE_FLOAT, Float ); - HANDLE_SINGLE_FIELD( CPPTYPE_BOOL, Bool ); - // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 - // See https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 - case CPPTYPE_UINT32: - return Rcpp::wrap( double(ref->GetUInt32(*message, fieldDesc))); + HANDLE_SINGLE_FIELD(CPPTYPE_INT32, Int32); + HANDLE_SINGLE_FIELD(CPPTYPE_DOUBLE, Double); + HANDLE_SINGLE_FIELD(CPPTYPE_FLOAT, Float); + HANDLE_SINGLE_FIELD(CPPTYPE_BOOL, Bool); + // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 + // See + // https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 + case CPPTYPE_UINT32: + return Rcpp::wrap(double(ref->GetUInt32(*message, fieldDesc))); #ifdef RCPP_HAS_LONG_LONG_TYPES - // Handle these types separately since Rcpp::wrap doesn't - // do the right thing. - case CPPTYPE_INT64: - return Int64AsSEXP(ref->GetInt64(*message, fieldDesc)); - case CPPTYPE_UINT64: - return Int64AsSEXP(ref->GetUInt64(*message, fieldDesc)); + // Handle these types separately since Rcpp::wrap doesn't + // do the right thing. + case CPPTYPE_INT64: + return Int64AsSEXP(ref->GetInt64(*message, fieldDesc)); + case CPPTYPE_UINT64: + return Int64AsSEXP(ref->GetUInt64(*message, fieldDesc)); #endif #undef HANDLE_SINGLE_FIELD - case CPPTYPE_STRING: - if (fieldDesc->type() == TYPE_STRING) { - return Rcpp::wrap( ref->GetString(*message, fieldDesc) ); - } else if (fieldDesc->type() == TYPE_BYTES) { - std::string s = ref->GetString(*message, fieldDesc); - return Rcpp::wrap(std::vector(s.begin(), s.end())); - } else { - Rcpp::stop("unknown field type with CPP_TYPE STRING"); - } - case CPPTYPE_ENUM : - return Rcpp::wrap( ref->GetEnum( *message, fieldDesc )->number() ) ; - - case CPPTYPE_MESSAGE: - return S4_Message( CLONE( &ref->GetMessage( *message, fieldDesc ) ) ) ; - break ; + case CPPTYPE_STRING: + if (fieldDesc->type() == TYPE_STRING) { + return Rcpp::wrap(ref->GetString(*message, fieldDesc)); + } else if (fieldDesc->type() == TYPE_BYTES) { + std::string s = ref->GetString(*message, fieldDesc); + return Rcpp::wrap(std::vector(s.begin(), s.end())); + } else { + Rcpp::stop("unknown field type with CPP_TYPE STRING"); + } + case CPPTYPE_ENUM: + return Rcpp::wrap(ref->GetEnum(*message, fieldDesc)->number()); - default: - Rcpp::stop("Unsupported type"); - } + case CPPTYPE_MESSAGE: + return S4_Message(CLONE(&ref->GetMessage(*message, fieldDesc))); + break; + default: + Rcpp::stop("Unsupported type"); + } } - END_RCPP + END_RCPP } -} // namespace rprotobuf +} // namespace rprotobuf Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-30 23:07:10 UTC (rev 658) +++ pkg/src/mutators.cpp 2013-12-31 01:38:53 UTC (rev 659) @@ -18,11 +18,11 @@ // You should have received a copy of the GNU General Public License // along with RProtoBuf. If not, see . -#include "rprotobuf.h" -#include "fieldtypes.h" +#include "rprotobuf.h" +#include "fieldtypes.h" #include "RcppMacros.h" -namespace rprotobuf{ +namespace rprotobuf { // {{{ GETDOUBLE /** @@ -34,327 +34,329 @@ * @throws Rcpp::exception if x[index] cannot be converted to double */ /* FIXME: should we convert the NA's */ -double GET_double( SEXP x, int index ){ - switch( TYPEOF(x) ){ - case INTSXP: - return( (double)INTEGER(x)[index] ) ; - case REALSXP: - return( REAL(x)[index] ) ; - case LGLSXP: - return( (double)LOGICAL(x)[index] ); - case RAWSXP: - return( (double)RAW(x)[index] ) ; - default: - Rcpp::stop("cannot cast SEXP to double"); - } - return 0.0 ; // -Wall +double GET_double(SEXP x, int index) { + switch (TYPEOF(x)) { + case INTSXP: + return ((double)INTEGER(x)[index]); + case REALSXP: + return (REAL(x)[index]); + case LGLSXP: + return ((double)LOGICAL(x)[index]); + case RAWSXP: + return ((double)RAW(x)[index]); + default: + Rcpp::stop("cannot cast SEXP to double"); + } + return 0.0; // -Wall } // }}} -float GET_float( SEXP x, int index ){ - switch( TYPEOF(x) ){ - case INTSXP: - return( (float)INTEGER(x)[index] ) ; - case REALSXP: - return( (float)REAL(x)[index] ) ; - case LGLSXP: - return( (float)LOGICAL(x)[index] ); - case RAWSXP: - return( (float)RAW(x)[index] ) ; - default: - Rcpp::stop("cannot cast SEXP to double"); - } - return (float)0.0 ; // -Wall +float GET_float(SEXP x, int index) { + switch (TYPEOF(x)) { + case INTSXP: + return ((float)INTEGER(x)[index]); + case REALSXP: + return ((float)REAL(x)[index]); + case LGLSXP: + return ((float)LOGICAL(x)[index]); + case RAWSXP: + return ((float)RAW(x)[index]); + default: + Rcpp::stop("cannot cast SEXP to double"); + } + return (float)0.0; // -Wall } -int GET_int( SEXP x, int index ){ - switch( TYPEOF(x) ){ - case INTSXP: - return( INTEGER(x)[index] ); - case REALSXP: - return( (int)REAL(x)[index] ); - case LGLSXP: - return( (int)LOGICAL(x)[index] ); - case RAWSXP: - return( (int)RAW(x)[index] ) ; - default: - Rcpp::stop( "cannot cast SEXP to int" ); - } - return 0 ; // -Wall, should not happen since we only call this when we know it works +int GET_int(SEXP x, int index) { + switch (TYPEOF(x)) { + case INTSXP: + return (INTEGER(x)[index]); + case REALSXP: + return ((int)REAL(x)[index]); + case LGLSXP: + return ((int)LOGICAL(x)[index]); + case RAWSXP: + return ((int)RAW(x)[index]); + default: + Rcpp::stop("cannot cast SEXP to int"); + } + return 0; // -Wall, should not happen since we only call this when we know it works } -template -ValueType Int64FromString(const string &value) { - std::stringstream ss(value); - ValueType ret; - if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { - string message = "Provided character value '" + value + - "' cannot be cast to 64-bit integer."; - Rcpp::stop(message.c_str()); - } - return ret; +template +ValueType Int64FromString(const string& value) { + std::stringstream ss(value); + ValueType ret; + if ((ss >> ret).fail() || !(ss >> std::ws).eof()) { + string message = + "Provided character value '" + value + "' cannot be cast to 64-bit integer."; + Rcpp::stop(message.c_str()); + } + return ret; } -template -ValueType Int32FromString(const string &value) { - std::stringstream ss(value); - ValueType ret; - if ((ss >> ret).fail() || !(ss>>std::ws).eof()) { - string message = "Provided character value '" + value + - "' cannot be cast to 32-bit integer."; - Rcpp::stop(message.c_str()); - } - return ret; +template +ValueType Int32FromString(const string& value) { + std::stringstream ss(value); + ValueType ret; + if ((ss >> ret).fail() || !(ss >> std::ws).eof()) { + string message = + "Provided character value '" + value + "' cannot be cast to 32-bit integer."; + Rcpp::stop(message.c_str()); + } + return ret; } -int32 GET_int32( SEXP x, int index ){ - switch( TYPEOF(x) ){ - case INTSXP: - return( (int32)INTEGER(x)[index] ); - case REALSXP: - return( (int32)REAL(x)[index] ); - case LGLSXP: - return( (int32)LOGICAL(x)[index] ); - case RAWSXP: - return( (int32)RAW(x)[index] ) ; - case STRSXP: - return Int32FromString(CHAR(STRING_ELT(x, index))); - default: - Rcpp::stop( "cannot cast SEXP to int32"); - } - return (int32)0 ; // -Wall, should not happen since we only call this when we know it works +int32 GET_int32(SEXP x, int index) { + switch (TYPEOF(x)) { + case INTSXP: + return ((int32)INTEGER(x)[index]); + case REALSXP: + return ((int32)REAL(x)[index]); + case LGLSXP: + return ((int32)LOGICAL(x)[index]); + case RAWSXP: + return ((int32)RAW(x)[index]); + case STRSXP: + return Int32FromString(CHAR(STRING_ELT(x, index))); + default: + Rcpp::stop("cannot cast SEXP to int32"); + } + return (int32)0; // -Wall, should not happen since we only call this when we know it works } -int64 GET_int64( SEXP x, int index ){ - switch( TYPEOF(x) ){ - case INTSXP: - return( (int64)INTEGER(x)[index] ); - case REALSXP: - return( (int64)REAL(x)[index] ); - case LGLSXP: - return( (int64)LOGICAL(x)[index] ); - case RAWSXP: - return( (int64)RAW(x)[index] ) ; - case STRSXP: +int64 GET_int64(SEXP x, int index) { + switch (TYPEOF(x)) { + case INTSXP: + return ((int64)INTEGER(x)[index]); + case REALSXP: + return ((int64)REAL(x)[index]); + case LGLSXP: + return ((int64)LOGICAL(x)[index]); + case RAWSXP: + return ((int64)RAW(x)[index]); + case STRSXP: return Int64FromString(CHAR(STRING_ELT(x, index))); - default: - Rcpp::stop("cannot cast SEXP to int64"); - } - return (int64)0 ; // -Wall, should not happen since we only call this when we know it works + default: + Rcpp::stop("cannot cast SEXP to int64"); + } + return (int64)0; // -Wall, should not happen since we only call this when we know it works } -uint32 GET_uint32( SEXP x, int index ){ - switch( TYPEOF(x) ){ - case INTSXP: - return( (uint32)INTEGER(x)[index] ); - case REALSXP: - return( (uint32)REAL(x)[index] ); - case LGLSXP: - return( (uint32)LOGICAL(x)[index] ); - case RAWSXP: - return( (uint32)RAW(x)[index] ) ; - case STRSXP: +uint32 GET_uint32(SEXP x, int index) { + switch (TYPEOF(x)) { + case INTSXP: + return ((uint32)INTEGER(x)[index]); + case REALSXP: + return ((uint32)REAL(x)[index]); + case LGLSXP: + return ((uint32)LOGICAL(x)[index]); + case RAWSXP: + return ((uint32)RAW(x)[index]); + case STRSXP: return Int32FromString(CHAR(STRING_ELT(x, index))); - default: - Rcpp::stop("cannot cast SEXP to uint32"); - } - return (uint32)0 ; // -Wall, should not happen since we only call this when we know it works + default: + Rcpp::stop("cannot cast SEXP to uint32"); + } + return (uint32)0; // -Wall, should not happen since we only call this when we know it works } -uint64 GET_uint64( SEXP x, int index ){ - switch( TYPEOF(x) ){ - case INTSXP: - return( (uint64)INTEGER(x)[index] ); - case REALSXP: - return( (uint64)REAL(x)[index] ); - case LGLSXP: - return( (uint64)LOGICAL(x)[index] ); - case RAWSXP: - return( (uint64)RAW(x)[index] ) ; - case STRSXP: +uint64 GET_uint64(SEXP x, int index) { + switch (TYPEOF(x)) { + case INTSXP: + return ((uint64)INTEGER(x)[index]); + case REALSXP: + return ((uint64)REAL(x)[index]); + case LGLSXP: + return ((uint64)LOGICAL(x)[index]); + case RAWSXP: + return ((uint64)RAW(x)[index]); + case STRSXP: return Int64FromString(CHAR(STRING_ELT(x, index))); - default: - Rcpp::stop("cannot cast SEXP to uint64"); - } - return (uint64)0 ; // -Wall, should not happen since we only call this when we know it works + default: + Rcpp::stop("cannot cast SEXP to uint64"); + } + return (uint64)0; // -Wall, should not happen since we only call this when we know it works } -bool GET_bool( SEXP x, int index ){ - switch( TYPEOF(x) ){ - case INTSXP: +bool GET_bool(SEXP x, int index) { + switch (TYPEOF(x)) { + case INTSXP: if (INTEGER(x)[index] == R_NaInt) { - Rcpp::stop("NA boolean values can not be stored in " - "bool protocol buffer fields"); + Rcpp::stop( + "NA boolean values can not be stored in " + "bool protocol buffer fields"); } - return( (bool)INTEGER(x)[index] ); - case REALSXP: + return ((bool)INTEGER(x)[index]); + case REALSXP: if (REAL(x)[index] == R_NaReal) { - Rcpp::stop("NA boolean values can not be stored in " - "bool protocol buffer fields"); + Rcpp::stop( + "NA boolean values can not be stored in " + "bool protocol buffer fields"); } - return( (bool)REAL(x)[index] ); - case LGLSXP: + return ((bool)REAL(x)[index]); + case LGLSXP: if (LOGICAL(x)[index] == NA_LOGICAL) { - Rcpp::stop("NA boolean values can not be stored in " - "bool protocol buffer fields"); + Rcpp::stop( + "NA boolean values can not be stored in " + "bool protocol buffer fields"); } - return( (bool)LOGICAL(x)[index] ); - case RAWSXP: - return( (bool)RAW(x)[index] ) ; - default: - Rcpp::stop("cannot cast SEXP to bool"); - } - return (bool)0 ; // -Wall, should not happen since we only call this when we know it works + return ((bool)LOGICAL(x)[index]); + case RAWSXP: + return ((bool)RAW(x)[index]); + default: + Rcpp::stop("cannot cast SEXP to bool"); + } + return (bool)0; // -Wall, should not happen since we only call this when we know it works } -std::string GET_stdstring( SEXP x, int index ){ - if( TYPEOF(x) == STRSXP){ - return( CHAR(STRING_ELT(x, index)) ); - } - return "" ; // -Wall, should not happen since we only call this when we know it works +std::string GET_stdstring(SEXP x, int index) { + if (TYPEOF(x) == STRSXP) { + return (CHAR(STRING_ELT(x, index))); + } + return ""; // -Wall, should not happen since we only call this when we know it works } -std::string GET_bytes( SEXP x, int index ){ - switch( TYPEOF(x)) { - case RAWSXP: - if (index == 0) { - return(std::string((const char *) RAW(x), (size_t) LENGTH(x))); - } else { - Rcpp::stop("cannot cast SEXP to bytes"); - } - case VECSXP: - if (TYPEOF(VECTOR_ELT(x, index)) == RAWSXP) { - return(std::string((const char *) RAW(VECTOR_ELT(x, index)), (size_t) LENGTH(VECTOR_ELT(x, index)))); - } else { - Rcpp::stop("cannot cast SEXP to bytes"); - } - default: - Rcpp::stop("cannot cast SEXP to bytes"); - } - return "" ; // -Wall, should not happen since we only call this when we know it works +std::string GET_bytes(SEXP x, int index) { + switch (TYPEOF(x)) { + case RAWSXP: + if (index == 0) { + return (std::string((const char*)RAW(x), (size_t)LENGTH(x))); + } else { + Rcpp::stop("cannot cast SEXP to bytes"); + } + case VECSXP: + if (TYPEOF(VECTOR_ELT(x, index)) == RAWSXP) { + return (std::string((const char*)RAW(VECTOR_ELT(x, index)), + (size_t)LENGTH(VECTOR_ELT(x, index)))); + } else { + Rcpp::stop("cannot cast SEXP to bytes"); + } + default: + Rcpp::stop("cannot cast SEXP to bytes"); + } + return ""; // -Wall, should not happen since we only call this when we know it works } /** * indicates if this is a list of messages - * + * * @param x a list (VECSXP) * @return TRUE if all objects are instances of Message class */ -Rboolean allAreMessages( SEXP x) { - - if( TYPEOF(x) != VECSXP ) return _FALSE_ ; - - int n = LENGTH(x) ; - SEXP current ; - for( int i=0; ienum_type() ; - // N.B. n undefined if TYPEOF(value) not a vector, but we catch that below. - int n = LENGTH(value) ; - - switch( TYPEOF( value ) ){ - // {{{ numbers - case INTSXP: - case REALSXP: - case LGLSXP: - case RAWSXP: - { - int nenums = enum_desc->value_count() ; - std::vector possibles( nenums ) ; - for( int i=0; i< nenums; i++){ - possibles[i] = enum_desc->value(i)->number(); - } - - /* loop around the numbers to see if they are in the possibles */ - for( int i=0; ivalue_count() ; - std::vector possibles( nenums ) ; - for( int i=0; i< nenums; i++){ - possibles[i] = enum_desc->value(i)->name() ; - } - - /* loop around the numbers to see if they are in the possibles */ - for( int i=0; ienum_type(); + // N.B. n undefined if TYPEOF(value) not a vector, but we catch that below. + int n = LENGTH(value); + + switch (TYPEOF(value)) { + // {{{ numbers + case INTSXP: + case REALSXP: + case LGLSXP: + case RAWSXP: { + int nenums = enum_desc->value_count(); + std::vector possibles(nenums); + for (int i = 0; i < nenums; i++) { + possibles[i] = enum_desc->value(i)->number(); + } + + /* loop around the numbers to see if they are in the possibles */ + for (int i = 0; i < n; i++) { + int val = GET_int(value, i); + int ok = 0; + for (int j = 0; j < nenums; j++) { + if (val == possibles[j]) { + ok = 1; + break; + } + } + if (!ok) { + Rcpp::stop("wrong value for enum"); + } + } + + break; + } + // }}} + + // {{{ STRSXP + case STRSXP: { + int nenums = enum_desc->value_count(); + std::vector possibles(nenums); + for (int i = 0; i < nenums; i++) { + possibles[i] = enum_desc->value(i)->name(); + } + + /* loop around the numbers to see if they are in the possibles */ + for (int i = 0; i < n; i++) { + const char* val = CHAR(STRING_ELT(value, i)); + int ok = 0; + /* FIXME: there is probably something more efficient */ + for (int j = 0; j < nenums; j++) { + if (!possibles[j].compare(val)) { + ok = 1; + break; + } + } + if (!ok) { + Rcpp::stop("wrong value for enum"); + } + } + break; + } + // }}} + + default: + Rcpp::stop("impossible to convert to a enum"); } - VOID_END_RCPP + VOID_END_RCPP } /** @@ -362,28 +364,28 @@ * * @throws Rcpp::exception on error (uncaught) */ -void CHECK_messages( const GPB::FieldDescriptor* field_desc, SEXP values ){ - if( TYPEOF( values ) != VECSXP ){ - Rcpp::stop("expecting a list of messages"); - } - - const char* target = field_desc->message_type()->full_name().c_str() ; - int n = LENGTH(values) ; - for( int i=0; imessage_type()->full_name().c_str(); + int n = LENGTH(values); + for (int i = 0; i < n; i++) { + if (!isMessage(VECTOR_ELT(values, i), target)) { + // TODO(mstokely): When we have C++11 CXX11, use + // std::to_string(i) + // {{{ + std::string s; + std::stringstream out; + out << i; + s = out.str(); + // }}} + string message = "List element " + s + " is not a message " + + "of the appropriate type ('" + target + "')"; + Rcpp::stop(message.c_str()); + } + } } /** @@ -391,133 +393,121 @@ * otherwise this could lead to modifying a few values then failing in * an inconsistent state. */ -void CHECK_repeated_vals(const GPB::FieldDescriptor* field_desc, - SEXP value, int value_size) { - switch( field_desc->type() ){ - case TYPE_MESSAGE: - case TYPE_GROUP: - { - switch( TYPEOF( value ) ){ - case VECSXP : - { +void CHECK_repeated_vals(const GPB::FieldDescriptor* field_desc, SEXP value, int value_size) { + switch (field_desc->type()) { + case TYPE_MESSAGE: + case TYPE_GROUP: { + switch (TYPEOF(value)) { + case VECSXP: { - /* check that it is a list of Messages of the - appropriate type */ - CHECK_messages(field_desc, value); - break ; - } - case S4SXP: - { [TRUNCATED] To get the complete diff run: svnlook diff /svnroot/rprotobuf -r 659 From noreply at r-forge.r-project.org Tue Dec 31 03:41:57 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 03:41:57 +0100 (CET) Subject: [Rprotobuf-commits] r660 - / pkg pkg/R pkg/man pkg/src Message-ID: <20131231024158.8D1A3186827@r-forge.r-project.org> Author: murray Date: 2013-12-31 03:41:53 +0100 (Tue, 31 Dec 2013) New Revision: 660 Modified: STYLE pkg/ChangeLog pkg/R/size.R pkg/man/size.Rd pkg/src/wrapper_Message.cpp Log: Fix size<- by using the correct C++ function name, and add documentation and examples of using this function. Replace two calls to Rf_error with Rcpp_error so that we unwind the call stack to deallocate objects before jumping to R's error handing routines. Modified: STYLE =================================================================== --- STYLE 2013-12-31 01:38:53 UTC (rev 659) +++ STYLE 2013-12-31 02:41:53 UTC (rev 660) @@ -47,10 +47,6 @@ We exclude sisocks.h from style issues as it is written separately by Simon Urbanek. -We exclude mutators.cpp and extractors.cpp temporarily as many other -changes were made to those files recently and we want to allow more -review before obfuscating the content changes with whitespace changes. - We exclude Rcppsupport.h and RcppMacros.h because I don't like the result. I want BEGIN_RCPP on its own line, for example. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-31 01:38:53 UTC (rev 659) +++ pkg/ChangeLog 2013-12-31 02:41:53 UTC (rev 660) @@ -5,7 +5,17 @@ optional protobuf fields. * src/extractors.cpp (rprotobuf): Correct handling of uint32 for repeated fields. - + * src/wrapper_Message.cpp (rprotobuf): Remove Rf_error in favor of + Rcpp_error so that we throw an exception and unwind the stack to + deallocate objects before jumping to R' serror. + * R/size.R: Correct an incorrect method name that prevented size<- + from working. + * man/size.Rd: Document the behavior of size<- + * (C++): Ran all the C++ files and most of the headers through + clang-format as described in the STYLE file on R-Forge. + Basically, we now use 4-char indents and 100-char limit for line + wrap. + 2013-12-28 Murray Stokely * src/extractors.cpp (rprotobuf): Correct handling of uint32 for Modified: pkg/R/size.R =================================================================== --- pkg/R/size.R 2013-12-31 01:38:53 UTC (rev 659) +++ pkg/R/size.R 2013-12-31 02:41:53 UTC (rev 660) @@ -31,7 +31,7 @@ value <- as.integer( value )[1] if( is.character( field ) || is.numeric( field ) ){ - .Call( "set_field_size", object at pointer, field, value, PACKAGE = "RProtoBuf" ) + .Call( "Message__set_field_size", object at pointer, field, value, PACKAGE = "RProtoBuf" ) } else{ stop( "field should be a character or a number" ) } Modified: pkg/man/size.Rd =================================================================== --- pkg/man/size.Rd 2013-12-31 01:38:53 UTC (rev 659) +++ pkg/man/size.Rd 2013-12-31 02:41:53 UTC (rev 660) @@ -11,6 +11,12 @@ For non repeated fields, the size is 1 if the message has the field, 0 otherwise. For repeated fields, the size is the number of objects in the array. + +For repeated fields, the size can also be assigned to in order to shrink +or grow the vector. Numeric types are given a default value of 0 when +the new size is greater than the existing size. Character types are +given a default value of "". Growing a repeated field in this way is +not supported for message, group, and enum types. } \section{Methods}{ \describe{ @@ -26,5 +32,12 @@ test$add("repeated_int32", 1:10) test$size("repeated_int32") +test$repeated_int32 + +size(test, "repeated_int32") <- 5 +test$repeated_int32 + +size(test, "repeated_int32") <- 15 +test$repeated_int32 } \keyword{methods} Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-12-31 01:38:53 UTC (rev 659) +++ pkg/src/wrapper_Message.cpp 2013-12-31 02:41:53 UTC (rev 660) @@ -335,16 +335,12 @@ case TYPE_MESSAGE: case TYPE_GROUP: { /* fill with the prototype for that message type */ - Rf_error( - "growing repeated messages not implemented yet, " - "patches welcome"); + Rcpp_error("growing repeated messages not implemented, patches welcome"); break; } case TYPE_ENUM: { /* fill with the prototype for that message type */ - Rf_error( - "growing repeated enum not implemented yet, " - "patches welcome"); + Rcpp_error("growing repeated enums not implemented yet, patches welcome"); break; } } /* switch */ From noreply at r-forge.r-project.org Tue Dec 31 03:45:32 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 03:45:32 +0100 (CET) Subject: [Rprotobuf-commits] r661 - pkg/src Message-ID: <20131231024532.EEDDA1859B6@r-forge.r-project.org> Author: murray Date: 2013-12-31 03:45:32 +0100 (Tue, 31 Dec 2013) New Revision: 661 Modified: pkg/src/wrapper_Message.cpp Log: Replace three more Rf_error calls with Rcpp_error Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-12-31 02:41:53 UTC (rev 660) +++ pkg/src/wrapper_Message.cpp 2013-12-31 02:45:32 UTC (rev 661) @@ -399,12 +399,12 @@ case TYPE_MESSAGE: case TYPE_GROUP: { /* fill with the prototype for that message type */ - Rf_error("not implemented yet, patches welcome"); + Rcpp_error("not implemented yet, patches welcome"); break; } case TYPE_ENUM: { /* fill with the prototype for that message type */ - Rf_error("not implemented yet, patches welcome"); + Rcpp_error("not implemented yet, patches welcome"); break; } } @@ -934,7 +934,7 @@ Rcpp::IntegerVector index) { GPB::FieldDescriptor* field_desc = getFieldDescriptor(message, field); if (!field_desc->is_repeated()) { - Rf_error("fetch can only be used on repeated fields"); + Rcpp_error("fetch can only be used on repeated fields"); } int n = index.size(); From noreply at r-forge.r-project.org Tue Dec 31 04:05:29 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 04:05:29 +0100 (CET) Subject: [Rprotobuf-commits] r662 - in pkg: . src Message-ID: <20131231030530.A54D8186B93@r-forge.r-project.org> Author: murray Date: 2013-12-31 04:05:26 +0100 (Tue, 31 Dec 2013) New Revision: 662 Modified: pkg/ChangeLog pkg/src/DescriptorPoolLookup.cpp pkg/src/rprotobuf.cpp Log: Rf_error -> Rcpp::error and wrap a function in the needed BEGIN_RCPP / END_RCPP boilerplate. This update is tested by an existing unit test that does checkException("/invalid/file"). Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-31 02:45:32 UTC (rev 661) +++ pkg/ChangeLog 2013-12-31 03:05:26 UTC (rev 662) @@ -7,7 +7,8 @@ repeated fields. * src/wrapper_Message.cpp (rprotobuf): Remove Rf_error in favor of Rcpp_error so that we throw an exception and unwind the stack to - deallocate objects before jumping to R' serror. + deallocate objects before jumping to R's error. + * src/DescriptorPoolLookup.cpp (rprotobuf): Idem. * R/size.R: Correct an incorrect method name that prevented size<- from working. * man/size.Rd: Document the behavior of size<- Modified: pkg/src/DescriptorPoolLookup.cpp =================================================================== --- pkg/src/DescriptorPoolLookup.cpp 2013-12-31 02:45:32 UTC (rev 661) +++ pkg/src/DescriptorPoolLookup.cpp 2013-12-31 03:05:26 UTC (rev 662) @@ -36,13 +36,21 @@ GPB::compiler::Importer DescriptorPoolLookup::importer(&source_tree, &error_collector); GPB::DynamicMessageFactory DescriptorPoolLookup::message_factory(importer.pool()); +/** + * Add descriptors from a proto file to the descriptor pool. + * + * @param files A character vector of .proto files to import. + * @param dirs A character vector of directories to import from. + * @throws Rcpp::exception if a file can't be loaded (uncaught). + */ void DescriptorPoolLookup::importProtoFiles(SEXP files, SEXP dirs) { source_tree.addDirectories(dirs); int n = LENGTH(files); for (int j = 0; j < n; j++) { const GPB::FileDescriptor* file_desc = importer.Import(CHAR(STRING_ELT(files, j))); if (!file_desc) { - Rf_error("Could not load proto file '%s'\n", CHAR(STRING_ELT(files, j))); + string message = "Could not load proto file '" + CHAR(STRING_ELT(files, j)) + "'\n"; + Rcpp_error(message.c_str()); continue; } int ntypes = file_desc->message_type_count(); Modified: pkg/src/rprotobuf.cpp =================================================================== --- pkg/src/rprotobuf.cpp 2013-12-31 02:45:32 UTC (rev 661) +++ pkg/src/rprotobuf.cpp 2013-12-31 03:05:26 UTC (rev 662) @@ -48,8 +48,10 @@ * @param file proto file name */ SEXP readProtoFiles(SEXP file, SEXP dirs) { + BEGIN_RCPP DescriptorPoolLookup::importProtoFiles(file, dirs); return R_NilValue; + END_RCPP } /** From noreply at r-forge.r-project.org Tue Dec 31 04:45:15 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 04:45:15 +0100 (CET) Subject: [Rprotobuf-commits] r663 - pkg/src Message-ID: <20131231034515.716C718598C@r-forge.r-project.org> Author: murray Date: 2013-12-31 04:45:14 +0100 (Tue, 31 Dec 2013) New Revision: 663 Modified: pkg/src/DescriptorPoolLookup.cpp Log: Compile fix string/char * issue. Modified: pkg/src/DescriptorPoolLookup.cpp =================================================================== --- pkg/src/DescriptorPoolLookup.cpp 2013-12-31 03:05:26 UTC (rev 662) +++ pkg/src/DescriptorPoolLookup.cpp 2013-12-31 03:45:14 UTC (rev 663) @@ -49,7 +49,8 @@ for (int j = 0; j < n; j++) { const GPB::FileDescriptor* file_desc = importer.Import(CHAR(STRING_ELT(files, j))); if (!file_desc) { - string message = "Could not load proto file '" + CHAR(STRING_ELT(files, j)) + "'\n"; + string message = string("Could not load proto file '") + CHAR(STRING_ELT(files, j)) + + "'\n"; Rcpp_error(message.c_str()); continue; } From noreply at r-forge.r-project.org Tue Dec 31 05:05:45 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 05:05:45 +0100 (CET) Subject: [Rprotobuf-commits] r664 - pkg/src Message-ID: <20131231040545.46CEC186B98@r-forge.r-project.org> Author: edd Date: 2013-12-31 05:05:37 +0100 (Tue, 31 Dec 2013) New Revision: 664 Modified: pkg/src/DescriptorPoolLookup.cpp Log: use explicit std::string not just string Modified: pkg/src/DescriptorPoolLookup.cpp =================================================================== --- pkg/src/DescriptorPoolLookup.cpp 2013-12-31 03:45:14 UTC (rev 663) +++ pkg/src/DescriptorPoolLookup.cpp 2013-12-31 04:05:37 UTC (rev 664) @@ -49,7 +49,7 @@ for (int j = 0; j < n; j++) { const GPB::FileDescriptor* file_desc = importer.Import(CHAR(STRING_ELT(files, j))); if (!file_desc) { - string message = string("Could not load proto file '") + CHAR(STRING_ELT(files, j)) + + std::string message = std::string("Could not load proto file '") + CHAR(STRING_ELT(files, j)) + "'\n"; Rcpp_error(message.c_str()); continue; From noreply at r-forge.r-project.org Tue Dec 31 05:24:26 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 05:24:26 +0100 (CET) Subject: [Rprotobuf-commits] r665 - pkg/src Message-ID: <20131231042426.9C1011869E6@r-forge.r-project.org> Author: murray Date: 2013-12-31 05:24:24 +0100 (Tue, 31 Dec 2013) New Revision: 665 Modified: pkg/src/mutators.cpp pkg/src/wrapper_Message.cpp Log: Manual clean up pass. 1. Concatenate some strings so that error messages are created on one line that fits in less than 100 chars rather than using 3 separate lines. 2. Standardize on default:\nRcpp::stop(...) instead of default: { Rcpp::stop(...) } 3. Capitalize and add punctuation to many comments. 4. Remove a few more extra blank lines. 5. Adjust spacing of emacs '{{{' '}}}' fold-block comments. 6. Remove an extraneous BEGIN_RCPP / END_RCPP From one function because the throw in that function should unwind up one level to the calling function which includes that block. Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-31 04:05:37 UTC (rev 664) +++ pkg/src/mutators.cpp 2013-12-31 04:24:24 UTC (rev 665) @@ -1,6 +1,3 @@ -// -*- mode: C++; c-indent-level: 4; c-basic-offset: 4; tab-width: 4 -*- -/* :tabSize=4:indentSize=4:noTabs=false:folding=explicit:collapseFolds=1: */ -// // Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois // // This file is part of RProtoBuf. @@ -183,23 +180,17 @@ switch (TYPEOF(x)) { case INTSXP: if (INTEGER(x)[index] == R_NaInt) { - Rcpp::stop( - "NA boolean values can not be stored in " - "bool protocol buffer fields"); + Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields"); } return ((bool)INTEGER(x)[index]); case REALSXP: if (REAL(x)[index] == R_NaReal) { - Rcpp::stop( - "NA boolean values can not be stored in " - "bool protocol buffer fields"); + Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields"); } return ((bool)REAL(x)[index]); case LGLSXP: if (LOGICAL(x)[index] == NA_LOGICAL) { - Rcpp::stop( - "NA boolean values can not be stored in " - "bool protocol buffer fields"); + Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields"); } return ((bool)LOGICAL(x)[index]); case RAWSXP: @@ -414,7 +405,8 @@ } break; } - default: { Rcpp::stop("impossible to convert to a message"); } + default: + Rcpp::stop("impossible to convert to a message"); } break; } @@ -541,17 +533,11 @@ case CPPTYPE_BOOL: { // TODO(mstokely): Rcpp should handle this! if ((TYPEOF(value) == LGLSXP) && (LOGICAL(value)[0] == NA_LOGICAL)) { - Rcpp::stop( - "NA boolean values can not be stored in " - "bool protocol buffer fields"); + Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields"); } else if ((TYPEOF(value) == INTSXP) && (INTEGER(value)[0] == R_NaInt)) { - Rcpp::stop( - "NA boolean values can not be stored in " - "bool protocol buffer fields"); + Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields"); } else if ((TYPEOF(value) == REALSXP) && (REAL(value)[0] == R_NaReal)) { - Rcpp::stop( - "NA boolean values can not be stored in " - "bool protocol buffer fields"); + Rcpp::stop("NA boolean values can not be stored in bool protocol buffer fields"); } ref->SetBool(message, field_desc, Rcpp::as(value)); break; @@ -630,7 +616,8 @@ ref->SetString(message, field_desc, __mess->SerializeAsString()); break; } - default: { Rcpp::stop("Cannot convert to string"); } + default: + Rcpp::stop("Cannot convert to string"); } break; } @@ -682,10 +669,12 @@ } break; } - default: { Rcpp::stop("cannot set enum value"); } + default: + Rcpp::stop("cannot set enum value"); } + break; } - // }}} + // }}} } } @@ -748,7 +737,8 @@ break; } - default: { Rcpp::stop("Cannot convert to int32"); } + default: + Rcpp::stop("Cannot convert to int32"); } break; } @@ -1119,12 +1109,11 @@ } // }}} - // {{{ default - default: { Rcpp::stop("cannot set enum value"); } - // }}} + default: + Rcpp::stop("cannot set enum value"); } } - // }}} + // }}} } } @@ -1139,7 +1128,7 @@ */ SEXP setMessageField(SEXP pointer, SEXP name, SEXP value) { BEGIN_RCPP -// {{{ grab data + // {{{ grab data #ifdef RPB_DEBUG Rprintf("\n"); Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-12-31 04:05:37 UTC (rev 664) +++ pkg/src/wrapper_Message.cpp 2013-12-31 04:24:24 UTC (rev 665) @@ -59,7 +59,7 @@ #define METHOD(__NAME__) RCPP_PP_CAT(Message__, __NAME__) /** - * clone a message + * Clone a message * * @param xp external pointer to a message * @return a new message, clone of the input message @@ -120,7 +120,7 @@ } /** - * serialize a message to a file + * Serialize a message to a file * * @param xp external pointer to a GPB::Message* * @param filename file name where to serialize @@ -139,8 +139,7 @@ } /** - * create a raw vector that contains the content of the serialized - * message + * Create a raw vector that contains the content of the serialized message * * @param xp xternal pointer to the message */ @@ -171,6 +170,8 @@ } /** + * Return a named list representation of the fields set in a message. + * * @param xp external pointer to a Message * @return the message as an R list */ @@ -192,8 +193,7 @@ } /** - * The number of fields the message has. A field counts in these two situations - *: + * The number of fields the message has. A field counts in these two situations: * - it is repeated and the array size is greater than 0 * - it is not repeated and the message has it * @@ -204,7 +204,6 @@ const GPB::Reflection* ref = message->GetReflection(); int nfields = desc->field_count(); - int res = 0; for (int i = 0; i < nfields; i++) { @@ -241,7 +240,7 @@ } /** - * Get the message descriptor of a Message + * Get the message descriptor of a Message. * * @param xp (GPB::Message*) external pointer * @return the descriptor, as a Descriptor R S4 object @@ -254,7 +253,6 @@ RPB_XP_METHOD_0(METHOD(bytesize), GPB::Message, ByteSize) RPB_FUNCTION_2(int, METHOD(field_size), Rcpp::XPtr message, SEXP field) { - const GPB::FieldDescriptor* field_desc = getFieldDescriptor(message, field); int res = 0; @@ -272,7 +270,6 @@ RPB_FUNCTION_VOID_3(METHOD(set_field_size), Rcpp::XPtr message, SEXP field, int target) { - const GPB::FieldDescriptor* field_desc = getFieldDescriptor(message, field); const GPB::Reflection* ref = message->GetReflection(); @@ -291,7 +288,6 @@ } else {/* current < target */ while (current != target) { - switch (field_desc->type()) { case TYPE_INT32: case TYPE_SINT32: @@ -414,7 +410,7 @@ } /** - * returns the field names of the message + * Returns the field names of the message. * * @param xp external pointer to a Message * @@ -432,7 +428,6 @@ } bool identical_messages_(GPB::Message* m1, GPB::Message* m2, double tol) { - BEGIN_RCPP const GPB::Descriptor* d1 = m1->GetDescriptor(); const GPB::Descriptor* d2 = m2->GetDescriptor(); @@ -619,7 +614,6 @@ } } } - VOID_END_RCPP /* finally */ return true; } @@ -647,7 +641,7 @@ } /** - * creates a new message by merging two messages of the same type + * Creates a new message by merging two messages of the same type. * * @param xp1 external pointer to a GPB::Message* * @param xp2 external pointer to a GPB::Message* @@ -663,7 +657,7 @@ } /** - * Add values to a repeated field + * Add values to a repeated field. * * @param xp (GPB::Message*) external pointer * @param field field tag number or name @@ -710,7 +704,8 @@ } break; } - default: { Rcpp::stop("Cannot convert to int32"); } + default: + Rcpp::stop("Cannot convert to int32"); } break; } @@ -907,9 +902,8 @@ } // }}} - // {{{ default - default: { Rcpp::stop("cannot set enum value"); } - // }}} + default: + Rcpp::stop("cannot set enum value"); } } break; } @@ -924,7 +918,7 @@ } /** - * fetch a subset of the values of a field + * Fetch a subset of the values of a field. * * @param (GPB::Message*) external pointer * @param field name or tag number of the field @@ -939,7 +933,6 @@ int n = index.size(); switch (field_desc->type()) { - case TYPE_INT32: case TYPE_SINT32: case TYPE_SFIXED32: @@ -1014,7 +1007,6 @@ */ RPB_FUNCTION_VOID_4(METHOD(set_field_values), Rcpp::XPtr message, SEXP field, Rcpp::IntegerVector index, SEXP values) { - const GPB::FieldDescriptor* field_desc = getFieldDescriptor(message, field); if (!field_desc->is_repeated()) { throw std::range_error("set can only be used on repeated fields"); @@ -1025,7 +1017,6 @@ /* we know here that LENGTH(index) == LENGTH(values) */ int n = index.size(); switch (field_desc->type()) { - case TYPE_INT32: case TYPE_SINT32: case TYPE_SFIXED32: { @@ -1104,7 +1095,6 @@ ref->SetRepeatedEnum(message, field_desc, i, enum_desc->FindValueByNumber(val)); } - break; } case STRSXP: { @@ -1115,7 +1105,6 @@ const GPB::EnumValueDescriptor* evd = enum_desc->FindValueByName(val); ref->SetRepeatedEnum(message, field_desc, i, evd); } - break; } default: @@ -1129,7 +1118,6 @@ for (int i = 0; i < n; i++) { GPB::Message* mess = GET_MESSAGE_POINTER_FROM_S4(vals[i]); ref->MutableRepeatedMessage(message, field_desc, i)->CopyFrom(*mess); - ; } break; } From noreply at r-forge.r-project.org Tue Dec 31 08:08:54 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 08:08:54 +0100 (CET) Subject: [Rprotobuf-commits] r666 - pkg Message-ID: <20131231070854.8845A186BAB@r-forge.r-project.org> Author: murray Date: 2013-12-31 08:08:54 +0100 (Tue, 31 Dec 2013) New Revision: 666 Modified: pkg/.Rbuildignore Log: Ignore the new src/.dir-locals.el file. Modified: pkg/.Rbuildignore =================================================================== --- pkg/.Rbuildignore 2013-12-31 04:24:24 UTC (rev 665) +++ pkg/.Rbuildignore 2013-12-31 07:08:54 UTC (rev 666) @@ -1,3 +1,4 @@ m4 configure.in vignettes/Sweave.sty +src/.dir-locals.el From noreply at r-forge.r-project.org Tue Dec 31 08:10:18 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 08:10:18 +0100 (CET) Subject: [Rprotobuf-commits] r667 - pkg/src Message-ID: <20131231071018.87E761813C8@r-forge.r-project.org> Author: murray Date: 2013-12-31 08:10:18 +0100 (Tue, 31 Dec 2013) New Revision: 667 Modified: pkg/src/wrapper_Message.cpp Log: Fix errant brace in previous commit. Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-12-31 07:08:54 UTC (rev 666) +++ pkg/src/wrapper_Message.cpp 2013-12-31 07:10:18 UTC (rev 667) @@ -903,7 +903,7 @@ // }}} default: - Rcpp::stop("cannot set enum value"); } + Rcpp::stop("cannot set enum value"); } break; } @@ -1127,4 +1127,5 @@ } #undef METHOD + } From noreply at r-forge.r-project.org Tue Dec 31 09:04:55 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 09:04:55 +0100 (CET) Subject: [Rprotobuf-commits] r668 - pkg/src Message-ID: <20131231080456.052CA186C45@r-forge.r-project.org> Author: murray Date: 2013-12-31 09:04:55 +0100 (Tue, 31 Dec 2013) New Revision: 668 Modified: pkg/src/wrapper_EnumDescriptor.cpp pkg/src/wrapper_EnumValueDescriptor.cpp pkg/src/wrapper_FileDescriptor.cpp pkg/src/wrapper_Message.cpp Log: Clean up 4 warnings caught by -Wall -pedantic. Modified: pkg/src/wrapper_EnumDescriptor.cpp =================================================================== --- pkg/src/wrapper_EnumDescriptor.cpp 2013-12-31 07:10:18 UTC (rev 667) +++ pkg/src/wrapper_EnumDescriptor.cpp 2013-12-31 08:04:55 UTC (rev 668) @@ -25,7 +25,7 @@ #undef METHOD #define METHOD(__NAME__) RCPP_PP_CAT(EnumDescriptor__, __NAME__) -RPB_XP_METHOD_0(METHOD(as_character), GPB::EnumDescriptor, DebugString); +RPB_XP_METHOD_0(METHOD(as_character), GPB::EnumDescriptor, DebugString) RPB_XP_METHOD_0(METHOD(length), GPB::EnumDescriptor, value_count) RPB_XP_METHOD_0(METHOD(value_count), GPB::EnumDescriptor, value_count) Modified: pkg/src/wrapper_EnumValueDescriptor.cpp =================================================================== --- pkg/src/wrapper_EnumValueDescriptor.cpp 2013-12-31 07:10:18 UTC (rev 667) +++ pkg/src/wrapper_EnumValueDescriptor.cpp 2013-12-31 08:04:55 UTC (rev 668) @@ -25,7 +25,7 @@ #undef METHOD #define METHOD(__NAME__) RCPP_PP_CAT(EnumValueDescriptor__, __NAME__) -RPB_XP_METHOD_0(METHOD(as_character), GPB::EnumValueDescriptor, DebugString); +RPB_XP_METHOD_0(METHOD(as_character), GPB::EnumValueDescriptor, DebugString) RPB_FUNCTION_1(S4_Message, METHOD(as_Message), Rcpp::XPtr d) { GPB::EnumValueDescriptorProto* message = new GPB::EnumValueDescriptorProto(); Modified: pkg/src/wrapper_FileDescriptor.cpp =================================================================== --- pkg/src/wrapper_FileDescriptor.cpp 2013-12-31 07:10:18 UTC (rev 667) +++ pkg/src/wrapper_FileDescriptor.cpp 2013-12-31 08:04:55 UTC (rev 668) @@ -6,7 +6,7 @@ #undef METHOD #define METHOD(__NAME__) RCPP_PP_CAT(FileDescriptor__, __NAME__) -RPB_XP_METHOD_0(METHOD(as_character), GPB::FileDescriptor, DebugString); +RPB_XP_METHOD_0(METHOD(as_character), GPB::FileDescriptor, DebugString) RPB_FUNCTION_1(S4_Message, METHOD(as_Message), Rcpp::XPtr d) { GPB::FileDescriptorProto* message = new GPB::FileDescriptorProto(); Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-12-31 07:10:18 UTC (rev 667) +++ pkg/src/wrapper_Message.cpp 2013-12-31 08:04:55 UTC (rev 668) @@ -231,7 +231,7 @@ int nexts = 0; vector fields; ref->ListFields(*message, &fields); - for (int i = 0; i < fields.size(); i++) { + for (unsigned int i = 0; i < fields.size(); i++) { if (fields[i]->is_extension()) { nexts++; } From noreply at r-forge.r-project.org Tue Dec 31 12:00:06 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 12:00:06 +0100 (CET) Subject: [Rprotobuf-commits] r669 - pkg/src Message-ID: <20131231110006.337A9185E5B@r-forge.r-project.org> Author: murray Date: 2013-12-31 12:00:05 +0100 (Tue, 31 Dec 2013) New Revision: 669 Modified: pkg/src/extractors.cpp pkg/src/mutators.cpp Log: Remove some unreachable/dead code tokens found by Flexelint. Also Flexelint highglights how this code doesn't currently work with long vectors due to the use of ints for indexing elements instead of longs. Add some comments. Modified: pkg/src/extractors.cpp =================================================================== --- pkg/src/extractors.cpp 2013-12-31 08:04:55 UTC (rev 668) +++ pkg/src/extractors.cpp 2013-12-31 11:00:05 UTC (rev 669) @@ -92,12 +92,12 @@ case TYPE: \ return Rcpp::wrap(RepeatedFieldImporter(ref, *message, fieldDesc)); - HANDLE_REPEATED_FIELD(CPPTYPE_INT32, GPB::int32); - HANDLE_REPEATED_FIELD(CPPTYPE_DOUBLE, double); - HANDLE_REPEATED_FIELD(CPPTYPE_FLOAT, float); - HANDLE_REPEATED_FIELD(CPPTYPE_BOOL, bool); - HANDLE_REPEATED_FIELD(CPPTYPE_ENUM, enum_field); - HANDLE_REPEATED_FIELD(CPPTYPE_MESSAGE, message_field); + HANDLE_REPEATED_FIELD(CPPTYPE_INT32, GPB::int32) + HANDLE_REPEATED_FIELD(CPPTYPE_DOUBLE, double) + HANDLE_REPEATED_FIELD(CPPTYPE_FLOAT, float) + HANDLE_REPEATED_FIELD(CPPTYPE_BOOL, bool) + HANDLE_REPEATED_FIELD(CPPTYPE_ENUM, enum_field) + HANDLE_REPEATED_FIELD(CPPTYPE_MESSAGE, message_field) // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 // See // https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 @@ -149,10 +149,10 @@ case CPPTYPE: \ return Rcpp::wrap(ref->Get##SUFFIX(*message, fieldDesc)); - HANDLE_SINGLE_FIELD(CPPTYPE_INT32, Int32); - HANDLE_SINGLE_FIELD(CPPTYPE_DOUBLE, Double); - HANDLE_SINGLE_FIELD(CPPTYPE_FLOAT, Float); - HANDLE_SINGLE_FIELD(CPPTYPE_BOOL, Bool); + HANDLE_SINGLE_FIELD(CPPTYPE_INT32, Int32) + HANDLE_SINGLE_FIELD(CPPTYPE_DOUBLE, Double) + HANDLE_SINGLE_FIELD(CPPTYPE_FLOAT, Float) + HANDLE_SINGLE_FIELD(CPPTYPE_BOOL, Bool) // TODO(mstokely): Rcpp doesn't handle uint32 properly as of 2013/12 // See // https://r-forge.r-project.org/tracker/index.php?func=detail&aid=1360&group_id=155&atid=637 @@ -182,7 +182,6 @@ case CPPTYPE_MESSAGE: return S4_Message(CLONE(&ref->GetMessage(*message, fieldDesc))); - break; default: Rcpp::stop("Unsupported type"); Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-31 08:04:55 UTC (rev 668) +++ pkg/src/mutators.cpp 2013-12-31 11:00:05 UTC (rev 669) @@ -104,6 +104,8 @@ return ret; } + // TODO(mstokely): not long vector clean. int index should be R_xlen_t + // Add test illustrating the problem by using size(repeated_field)<-bignum int32 GET_int32(SEXP x, int index) { switch (TYPEOF(x)) { case INTSXP: @@ -292,7 +294,7 @@ case REALSXP: case LGLSXP: case RAWSXP: { - int nenums = enum_desc->value_count(); + int nenums = enum_desc->value_count(); // Guaranteed to be > 0. std::vector possibles(nenums); for (int i = 0; i < nenums; i++) { possibles[i] = enum_desc->value(i)->number(); @@ -528,8 +530,8 @@ break; \ } - HANDLE_SINGLE_FIELD(CPPTYPE_DOUBLE, Double, double); - HANDLE_SINGLE_FIELD(CPPTYPE_FLOAT, Float, float); + HANDLE_SINGLE_FIELD(CPPTYPE_DOUBLE, Double, double) + HANDLE_SINGLE_FIELD(CPPTYPE_FLOAT, Float, float) case CPPTYPE_BOOL: { // TODO(mstokely): Rcpp should handle this! if ((TYPEOF(value) == LGLSXP) && (LOGICAL(value)[0] == NA_LOGICAL)) { From noreply at r-forge.r-project.org Tue Dec 31 13:07:37 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 13:07:37 +0100 (CET) Subject: [Rprotobuf-commits] r670 - in pkg: . inst/unitTests src Message-ID: <20131231120737.9C423186B2B@r-forge.r-project.org> Author: murray Date: 2013-12-31 13:07:37 +0100 (Tue, 31 Dec 2013) New Revision: 670 Modified: pkg/ChangeLog pkg/inst/unitTests/runit.extremevalues.R pkg/inst/unitTests/runit.int64.R pkg/src/wrapper_Message.cpp Log: Fix type coercion bug in add() method for uint32s and add a missing break statement that erroneously raised an error when setting some int64 fields. Make more function arguments const and remove a superfluous BEGIN_RCPP/END_RCPP. Also add comment about long-vector support. All of these fixes were highlighted by Flexelint. Add tests verifying the bugfixes. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-31 11:00:05 UTC (rev 669) +++ pkg/ChangeLog 2013-12-31 12:07:37 UTC (rev 670) @@ -1,3 +1,14 @@ +2013-12-31 Murray Stokely + + * src/wrapper_Message.cpp: Fix type coercion bug in add() method + for uint32s and add a missing break statement that erroneously + raised an error when setting some int64 fields. Make more + function arguments const and remove a superfluous + BEGIN_RCPP/END_RCPP. Also add comment about long-vector + support. All of these fixes were highlighted by Flexelint. + * inst/unitTests/runit.int64.R (test.int64): Add tests for above. + * inst/unitTests/runit.extremevalues.R (test.uint32): Idem. + 2013-12-30 Murray Stokely * inst/unitTests/runit.extremevalues.R (test.uint32): Add test Modified: pkg/inst/unitTests/runit.extremevalues.R =================================================================== --- pkg/inst/unitTests/runit.extremevalues.R 2013-12-31 11:00:05 UTC (rev 669) +++ pkg/inst/unitTests/runit.extremevalues.R 2013-12-31 12:07:37 UTC (rev 670) @@ -30,7 +30,9 @@ "4294967295") checkEquals(foo$optional_uint32, foo$repeated_uint32[[1]]) - + foo$add("repeated_uint32", c(2^32 - 1, 2^32 - 1)) + checkEquals(length(unique(foo$repeated_uint32)), 1) + # fixed32 are a more efficient representation of uint32 foo$optional_fixed32 <- 2^32 - 1 foo$repeated_fixed32 <- c(foo$optional_fixed32, foo$optional_fixed32) Modified: pkg/inst/unitTests/runit.int64.R =================================================================== --- pkg/inst/unitTests/runit.int64.R 2013-12-31 11:00:05 UTC (rev 669) +++ pkg/inst/unitTests/runit.int64.R 2013-12-31 12:07:37 UTC (rev 670) @@ -25,6 +25,10 @@ a <- new(protobuf_unittest.TestAllTypes) a$repeated_int64 <- 1 + # Now just test that we can use add to set int64 fields. + a$add("repeated_int64", 2:10) + checkEquals(length(a$repeated_int64), 10) + # Verify we can set character strings of large 64-bit ints a$repeated_int64 <- c("9007199254740992", "9007199254740993") checkEquals(length(a$repeated_int64), 2) @@ -49,4 +53,5 @@ options("RProtoBuf.int64AsString" = TRUE) # But we can see they are different if we treat them as strings. checkEquals(length(unique(a$repeated_int64)), 2) + } Modified: pkg/src/wrapper_Message.cpp =================================================================== --- pkg/src/wrapper_Message.cpp 2013-12-31 11:00:05 UTC (rev 669) +++ pkg/src/wrapper_Message.cpp 2013-12-31 12:07:37 UTC (rev 670) @@ -9,8 +9,8 @@ /* helpers */ /* this is only to be called for repeated fields */ -int MESSAGE_GET_REPEATED_INT(GPB::Message* message, GPB::FieldDescriptor* field_desc, int index) { - BEGIN_RCPP +int MESSAGE_GET_REPEATED_INT(const GPB::Message* message, const GPB::FieldDescriptor* field_desc, + int index) { const GPB::Reflection* ref = message->GetReflection(); switch (field_desc->type()) { @@ -33,14 +33,13 @@ default: Rcpp_error("cannot cast to int"); } - VOID_END_RCPP - return 0; // -Wall + return 0; // Unreachable for -Wall } /* this is only to be called for repeated fields */ -double MESSAGE_GET_REPEATED_DOUBLE(GPB::Message* message, GPB::FieldDescriptor* field_desc, +double MESSAGE_GET_REPEATED_DOUBLE(const GPB::Message* message, + const GPB::FieldDescriptor* field_desc, int index) { - BEGIN_RCPP const GPB::Reflection* ref = message->GetReflection(); switch (field_desc->type()) { @@ -51,7 +50,6 @@ default: Rcpp_error("cannot cast to double"); } - VOID_END_RCPP return 0; // -Wall } @@ -133,6 +131,7 @@ int file = open(filename, O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666); /* using partial to allow partially filled messages */ + // TODO(mstokely): Check return value and throw Rcpp::stop if 0? message->SerializePartialToFileDescriptor(file); close(file); @@ -427,7 +426,7 @@ return (res); } -bool identical_messages_(GPB::Message* m1, GPB::Message* m2, double tol) { +bool identical_messages_(const GPB::Message* m1, const GPB::Message* m2, double tol) { const GPB::Descriptor* d1 = m1->GetDescriptor(); const GPB::Descriptor* d2 = m2->GetDescriptor(); @@ -535,7 +534,7 @@ for (int j = 0; j < fs; j++) { const GPB::Message* mm1 = &ref->GetRepeatedMessage(*m1, field_desc, j); const GPB::Message* mm2 = &ref->GetRepeatedMessage(*m2, field_desc, j); - if (!identical_messages_((GPB::Message*)mm1, (GPB::Message*)mm2, tol)) { + if (!identical_messages_(mm1, mm2, tol)) { return false; } } @@ -604,7 +603,7 @@ case TYPE_GROUP: { const GPB::Message* mm1 = &ref->GetMessage(*m1, field_desc); const GPB::Message* mm2 = &ref->GetMessage(*m2, field_desc); - if (!identical_messages_((GPB::Message*)mm1, (GPB::Message*)mm2, tol)) { + if (!identical_messages_(mm1, mm2, tol)) { return false; } break; @@ -618,12 +617,13 @@ return true; } -RPB_FUNCTION_2(bool, identical_messages, Rcpp::XPtr m1, Rcpp::XPtr m2) { +RPB_FUNCTION_2(bool, identical_messages, Rcpp::XPtr m1, + Rcpp::XPtr m2) { return identical_messages_(m1, m2, 0.0); } -RPB_FUNCTION_3(bool, all_equal_messages, Rcpp::XPtr m1, Rcpp::XPtr m2, - double tol) { +RPB_FUNCTION_3(bool, all_equal_messages, Rcpp::XPtr m1, + Rcpp::XPtr m2, double tol) { return identical_messages_(m1, m2, tol); } @@ -723,6 +723,7 @@ for (int i = 0; i < value_size; i++) { ref->AddInt64(message, field_desc, GET_int64(values, i)); } + break; default: Rcpp::stop("Cannot convert to int64"); } @@ -739,7 +740,7 @@ case LGLSXP: case RAWSXP: { for (int i = 0; i < value_size; i++) { - ref->AddUInt32(message, field_desc, GET_int32(values, i)); + ref->AddUInt32(message, field_desc, GET_uint32(values, i)); } break; } @@ -994,7 +995,7 @@ default: throw std::range_error("unknown type"); } - return R_NilValue; // -Wall + return R_NilValue; // Unreachable. For -Wall } /** @@ -1110,6 +1111,7 @@ default: throw std::range_error("impossible to convert to a enum"); } + break; } case TYPE_MESSAGE: case TYPE_GROUP: { From noreply at r-forge.r-project.org Tue Dec 31 13:31:12 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 13:31:12 +0100 (CET) Subject: [Rprotobuf-commits] r671 - in pkg: . src Message-ID: <20131231123112.3736118692D@r-forge.r-project.org> Author: murray Date: 2013-12-31 13:31:11 +0100 (Tue, 31 Dec 2013) New Revision: 671 Modified: pkg/ChangeLog pkg/src/DescriptorPoolLookup.cpp pkg/src/extensions.cpp pkg/src/wrapper_Descriptor.cpp pkg/src/wrapper_FieldDescriptor.cpp pkg/src/wrapper_FileDescriptor.cpp Log: More Flexelint cleanup. Remove unused variables (masked in a way as compilers with -Wall didn't catch this), unreachable statements, an unused header, etc. Modified: pkg/ChangeLog =================================================================== --- pkg/ChangeLog 2013-12-31 12:07:37 UTC (rev 670) +++ pkg/ChangeLog 2013-12-31 12:31:11 UTC (rev 671) @@ -8,6 +8,13 @@ support. All of these fixes were highlighted by Flexelint. * inst/unitTests/runit.int64.R (test.int64): Add tests for above. * inst/unitTests/runit.extremevalues.R (test.uint32): Idem. + * src/wrapper_FieldDescriptor.cpp (RPB_HANDLE_CASE): Remove + unreachable statement in a macro. + * src/wrapper_Descriptor.cpp (rprotobuf): Remove unused variable, + rename another variable for clarity, and add some TODOs. + * src/wrapper_FileDescriptor.cpp (rprotobuf): Idem. + * src/DescriptorPoolLookup.cpp (rprotobuf): Remove unreachable statement. + * src/extensions.cpp: Remove unused header. 2013-12-30 Murray Stokely Modified: pkg/src/DescriptorPoolLookup.cpp =================================================================== --- pkg/src/DescriptorPoolLookup.cpp 2013-12-31 12:07:37 UTC (rev 670) +++ pkg/src/DescriptorPoolLookup.cpp 2013-12-31 12:31:11 UTC (rev 671) @@ -52,7 +52,6 @@ std::string message = std::string("Could not load proto file '") + CHAR(STRING_ELT(files, j)) + "'\n"; Rcpp_error(message.c_str()); - continue; } int ntypes = file_desc->message_type_count(); for (int i = 0; i < ntypes; i++) { Modified: pkg/src/extensions.cpp =================================================================== --- pkg/src/extensions.cpp 2013-12-31 12:07:37 UTC (rev 670) +++ pkg/src/extensions.cpp 2013-12-31 12:31:11 UTC (rev 671) @@ -20,7 +20,6 @@ */ #include "rprotobuf.h" -#include "fieldtypes.h" #include "Rcppsupport.h" namespace rprotobuf { Modified: pkg/src/wrapper_Descriptor.cpp =================================================================== --- pkg/src/wrapper_Descriptor.cpp 2013-12-31 12:07:37 UTC (rev 670) +++ pkg/src/wrapper_Descriptor.cpp 2013-12-31 12:31:11 UTC (rev 671) @@ -54,22 +54,21 @@ Rcpp::CharacterVector names(n); Rcpp::List res(n); - int i = 0; - int j = 0; - for (i = 0; i < nfields; j++, i++) { + int cnt = 0; + for (i = 0; i < nfields; cnt++, i++) { const GPB::FieldDescriptor* fd = desc->field(i); - res[j] = S4_FieldDescriptor(fd); - names[j] = fd->name(); + res[cnt] = S4_FieldDescriptor(fd); + names[cnt] = fd->name(); } - for (i = 0; i < ntypes; j++, i++) { + for (i = 0; i < ntypes; cnt++, i++) { const GPB::Descriptor* d = desc->nested_type(i); - res[j] = S4_Descriptor(d); - names[j] = d->name(); + res[cnt] = S4_Descriptor(d); + names[cnt] = d->name(); } - for (i = 0; i < nenums; j++, i++) { + for (i = 0; i < nenums; cnt++, i++) { const GPB::EnumDescriptor* ed = desc->enum_type(i); - res[j] = S4_EnumDescriptor(ed); - names[j] = ed->name(); + res[cnt] = S4_EnumDescriptor(ed); + names[cnt] = ed->name(); } res.names() = names; @@ -135,6 +134,7 @@ } /* read the message from the file */ + // TODO(mstokely): Check return value! message->ParsePartialFromFileDescriptor(file); close(file); return (S4_Message(message)); @@ -151,6 +151,7 @@ if (!message) { throw std::range_error("could not call factory->GetPrototype(desc)->New()"); } + // TODO(mstokely): Check return value! message->ParsePartialFromCodedStream(&coded_stream); S4_Message res(message); Modified: pkg/src/wrapper_FieldDescriptor.cpp =================================================================== --- pkg/src/wrapper_FieldDescriptor.cpp 2013-12-31 12:07:37 UTC (rev 670) +++ pkg/src/wrapper_FieldDescriptor.cpp 2013-12-31 12:31:11 UTC (rev 671) @@ -42,7 +42,6 @@ #define RPB_HANDLE_CASE(__CPP__, __LC__) \ case CPPTYPE_##__CPP__: { \ return Rcpp::wrap(d->default_value_##__LC__()); \ - break; \ } RPB_FUNCTION_1(SEXP, METHOD(default_value), Rcpp::XPtr d) { @@ -61,7 +60,6 @@ case CPPTYPE_ENUM: { return Rf_ScalarInteger(d->default_value_enum()->number()); - break; } default: break; Modified: pkg/src/wrapper_FileDescriptor.cpp =================================================================== --- pkg/src/wrapper_FileDescriptor.cpp 2013-12-31 12:07:37 UTC (rev 670) +++ pkg/src/wrapper_FileDescriptor.cpp 2013-12-31 12:31:11 UTC (rev 671) @@ -63,24 +63,23 @@ Rcpp::CharacterVector names(n); Rcpp::List res(n); - int i = 0; - int j = 0; - for (i = 0; i < ntypes; j++, i++) { - res[j] = S4_Descriptor(desc->message_type(i)); - names[j] = desc->message_type(i)->name(); + int count = 0; + for (i = 0; i < ntypes; count++, i++) { + res[count] = S4_Descriptor(desc->message_type(i)); + names[count] = desc->message_type(i)->name(); } - for (i = 0; i < nenums; j++, i++) { - res[j] = S4_EnumDescriptor(desc->enum_type(i)); - names[j] = desc->enum_type(i)->name(); + for (i = 0; i < nenums; count++, i++) { + res[count] = S4_EnumDescriptor(desc->enum_type(i)); + names[count] = desc->enum_type(i)->name(); } - for (i = 0; i < nserv; j++, i++) { - res[j] = S4_ServiceDescriptor(desc->service(i)); - names[j] = desc->service(i)->name(); + for (i = 0; i < nserv; count++, i++) { + res[count] = S4_ServiceDescriptor(desc->service(i)); + names[count] = desc->service(i)->name(); } - for (i = 0; i < nexts; j++, i++) { - res[j] = S4_FieldDescriptor(desc->extension(i)); + for (i = 0; i < nexts; count++, i++) { + res[count] = S4_FieldDescriptor(desc->extension(i)); // always use full names for extensions - names[j] = desc->extension(i)->full_name(); + names[count] = desc->extension(i)->full_name(); } res.names() = names; return res; From noreply at r-forge.r-project.org Tue Dec 31 13:44:31 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 13:44:31 +0100 (CET) Subject: [Rprotobuf-commits] r672 - pkg/src Message-ID: <20131231124431.DEA86183DE7@r-forge.r-project.org> Author: murray Date: 2013-12-31 13:44:31 +0100 (Tue, 31 Dec 2013) New Revision: 672 Modified: pkg/src/Rcppsupport.h pkg/src/extensions.cpp pkg/src/wrapper_Descriptor.cpp pkg/src/wrapper_FileDescriptor.cpp Log: Minor build fixes to make last change compile properly. Modified: pkg/src/Rcppsupport.h =================================================================== --- pkg/src/Rcppsupport.h 2013-12-31 12:31:11 UTC (rev 671) +++ pkg/src/Rcppsupport.h 2013-12-31 12:44:31 UTC (rev 672) @@ -33,7 +33,7 @@ class Int64AsStringRepeatedFieldImporter { public: // Probably want to convert to strings here. - typedef string r_import_type; + typedef std::string r_import_type; Int64AsStringRepeatedFieldImporter(const GPB::Reflection* ref_ , const GPB::Message& message_, const GPB::FieldDescriptor* field_) @@ -41,8 +41,8 @@ inline int size() const { return ref->FieldSize(message, field); } - inline string get(int i) const { - stringstream stream; + inline std::string get(int i) const { + std::stringstream stream; int64 val = ref->GetRepeatedInt64(message, field, i); stream << val; return stream.str(); @@ -56,7 +56,7 @@ class UInt64AsStringRepeatedFieldImporter { public: // Probably want to convert to strings here. - typedef string r_import_type; + typedef std::string r_import_type; UInt64AsStringRepeatedFieldImporter(const GPB::Reflection* ref_, const GPB::Message& message_, const GPB::FieldDescriptor* field_) @@ -64,8 +64,8 @@ inline int size() const { return ref->FieldSize(message, field) ; } - inline string get(int i) const { - stringstream stream; + inline std::string get(int i) const { + std::stringstream stream; uint64 val = ref->GetRepeatedUInt64(message, field, i); stream << val; return stream.str(); Modified: pkg/src/extensions.cpp =================================================================== --- pkg/src/extensions.cpp 2013-12-31 12:31:11 UTC (rev 671) +++ pkg/src/extensions.cpp 2013-12-31 12:44:31 UTC (rev 672) @@ -27,7 +27,7 @@ RcppExport SEXP getExtension(SEXP pointer, SEXP sfielddesc) { /* grab the Message pointer */ Rcpp::XPtr message(pointer); - const Reflection* ref = message->GetReflection(); + const GPB::Reflection* ref = message->GetReflection(); const GPB::FieldDescriptor* field_desc = GET_FIELD_DESCRIPTOR_POINTER_FROM_S4(sfielddesc); // extractFieldAsSEXP returns a default (e.g. 0) even when Modified: pkg/src/wrapper_Descriptor.cpp =================================================================== --- pkg/src/wrapper_Descriptor.cpp 2013-12-31 12:31:11 UTC (rev 671) +++ pkg/src/wrapper_Descriptor.cpp 2013-12-31 12:44:31 UTC (rev 672) @@ -55,17 +55,17 @@ Rcpp::CharacterVector names(n); Rcpp::List res(n); int cnt = 0; - for (i = 0; i < nfields; cnt++, i++) { + for (int i = 0; i < nfields; cnt++, i++) { const GPB::FieldDescriptor* fd = desc->field(i); res[cnt] = S4_FieldDescriptor(fd); names[cnt] = fd->name(); } - for (i = 0; i < ntypes; cnt++, i++) { + for (int i = 0; i < ntypes; cnt++, i++) { const GPB::Descriptor* d = desc->nested_type(i); res[cnt] = S4_Descriptor(d); names[cnt] = d->name(); } - for (i = 0; i < nenums; cnt++, i++) { + for (int i = 0; i < nenums; cnt++, i++) { const GPB::EnumDescriptor* ed = desc->enum_type(i); res[cnt] = S4_EnumDescriptor(ed); names[cnt] = ed->name(); Modified: pkg/src/wrapper_FileDescriptor.cpp =================================================================== --- pkg/src/wrapper_FileDescriptor.cpp 2013-12-31 12:31:11 UTC (rev 671) +++ pkg/src/wrapper_FileDescriptor.cpp 2013-12-31 12:44:31 UTC (rev 672) @@ -64,19 +64,19 @@ Rcpp::CharacterVector names(n); Rcpp::List res(n); int count = 0; - for (i = 0; i < ntypes; count++, i++) { + for (int i = 0; i < ntypes; count++, i++) { res[count] = S4_Descriptor(desc->message_type(i)); names[count] = desc->message_type(i)->name(); } - for (i = 0; i < nenums; count++, i++) { + for (int i = 0; i < nenums; count++, i++) { res[count] = S4_EnumDescriptor(desc->enum_type(i)); names[count] = desc->enum_type(i)->name(); } - for (i = 0; i < nserv; count++, i++) { + for (int i = 0; i < nserv; count++, i++) { res[count] = S4_ServiceDescriptor(desc->service(i)); names[count] = desc->service(i)->name(); } - for (i = 0; i < nexts; count++, i++) { + for (int i = 0; i < nexts; count++, i++) { res[count] = S4_FieldDescriptor(desc->extension(i)); // always use full names for extensions names[count] = desc->extension(i)->full_name(); From noreply at r-forge.r-project.org Tue Dec 31 21:07:50 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 21:07:50 +0100 (CET) Subject: [Rprotobuf-commits] r673 - pkg/src Message-ID: <20131231200750.D969D1868F8@r-forge.r-project.org> Author: murray Date: 2013-12-31 21:07:50 +0100 (Tue, 31 Dec 2013) New Revision: 673 Modified: pkg/src/rprotobuf.cpp Log: Mark function definitions extern C with RcppExport as they are in the header file. Modified: pkg/src/rprotobuf.cpp =================================================================== --- pkg/src/rprotobuf.cpp 2013-12-31 12:44:31 UTC (rev 672) +++ pkg/src/rprotobuf.cpp 2013-12-31 20:07:50 UTC (rev 673) @@ -47,7 +47,7 @@ * * @param file proto file name */ -SEXP readProtoFiles(SEXP file, SEXP dirs) { +RcppExport SEXP readProtoFiles(SEXP file, SEXP dirs) { BEGIN_RCPP DescriptorPoolLookup::importProtoFiles(file, dirs); return R_NilValue; @@ -62,7 +62,7 @@ * @return an S4 object of class Descriptor, or NULL if the type * is unknown */ -SEXP getProtobufDescriptor(SEXP type) { +RcppExport SEXP getProtobufDescriptor(SEXP type) { #ifdef RPB_DEBUG Rprintf("\n type = "); @@ -95,7 +95,7 @@ * @return an S4 object of class FieldDescriptor, or NULL if the type * is unknown */ -SEXP getExtensionDescriptor(SEXP type) { +RcppExport SEXP getExtensionDescriptor(SEXP type) { #ifdef RPB_DEBUG Rprintf("\n type = "); Rf_PrintValue(type); @@ -160,7 +160,7 @@ * @param pointer external pointer to a google::protobuf::Descriptor object * @param name name of the thing to extract */ -SEXP do_dollar_Descriptor(SEXP pointer, SEXP name) { +RcppExport SEXP do_dollar_Descriptor(SEXP pointer, SEXP name) { const char* what = CHAR(STRING_ELT(name, 0)); GPB::Descriptor* desc = (GPB::Descriptor*)EXTPTR_PTR(pointer); From noreply at r-forge.r-project.org Tue Dec 31 21:08:38 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 21:08:38 +0100 (CET) Subject: [Rprotobuf-commits] r674 - pkg/src Message-ID: <20131231200838.8B109186A34@r-forge.r-project.org> Author: murray Date: 2013-12-31 21:08:38 +0100 (Tue, 31 Dec 2013) New Revision: 674 Modified: pkg/src/ZeroCopyInputStreamWrapper.cpp pkg/src/ZeroCopyOutputStreamWrapper.cpp Log: Wrap destructors in try/catch to ensure we don't raise an exception here. From Flexelint. Modified: pkg/src/ZeroCopyInputStreamWrapper.cpp =================================================================== --- pkg/src/ZeroCopyInputStreamWrapper.cpp 2013-12-31 20:07:50 UTC (rev 673) +++ pkg/src/ZeroCopyInputStreamWrapper.cpp 2013-12-31 20:08:38 UTC (rev 674) @@ -8,11 +8,12 @@ } ZeroCopyInputStreamWrapper::~ZeroCopyInputStreamWrapper() { - /* first clear the coded stream */ - delete coded_stream; - - /* then the stream itself */ - delete stream; + try { + /* first clear the coded stream */ + delete coded_stream; + /* then the stream itself */ + delete stream; + } catch (...) { } } GPB::io::ZeroCopyInputStream* ZeroCopyInputStreamWrapper::get_stream() { return stream; } GPB::io::CodedInputStream* ZeroCopyInputStreamWrapper::get_coded_stream() { return coded_stream; } Modified: pkg/src/ZeroCopyOutputStreamWrapper.cpp =================================================================== --- pkg/src/ZeroCopyOutputStreamWrapper.cpp 2013-12-31 20:07:50 UTC (rev 673) +++ pkg/src/ZeroCopyOutputStreamWrapper.cpp 2013-12-31 20:08:38 UTC (rev 674) @@ -8,11 +8,12 @@ } ZeroCopyOutputStreamWrapper::~ZeroCopyOutputStreamWrapper() { - /* first clear the coded stream */ - delete coded_stream; - - /* then the stream itself */ - delete stream; + try { + /* first clear the coded stream */ + delete coded_stream; + /* then the stream itself */ + delete stream; + } catch (...) { } } GPB::io::ZeroCopyOutputStream* ZeroCopyOutputStreamWrapper::get_stream() { return stream; } GPB::io::CodedOutputStream* ZeroCopyOutputStreamWrapper::get_coded_stream() { return coded_stream; } From noreply at r-forge.r-project.org Tue Dec 31 21:09:13 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 21:09:13 +0100 (CET) Subject: [Rprotobuf-commits] r675 - pkg/src Message-ID: <20131231200913.16530180FED@r-forge.r-project.org> Author: murray Date: 2013-12-31 21:09:12 +0100 (Tue, 31 Dec 2013) New Revision: 675 Modified: pkg/src/ConnectionOutputStream.cpp Log: Explicitly cast a function return value to void to make it clearer we are ignoring it. Suggested by: Flexelint Modified: pkg/src/ConnectionOutputStream.cpp =================================================================== --- pkg/src/ConnectionOutputStream.cpp 2013-12-31 20:08:38 UTC (rev 674) +++ pkg/src/ConnectionOutputStream.cpp 2013-12-31 20:09:12 UTC (rev 675) @@ -16,12 +16,11 @@ if (!was_open) { /* then we need to close it */ SEXP call = PROTECT(Rf_lang2(Rf_install("close"), con)); - Rf_eval(call, R_GlobalEnv); + (void)Rf_eval(call, R_GlobalEnv); // Ignore SEXP return val of close(). UNPROTECT(1); /* call */ } - /* con will be disposed by the R GC, it is - protected as part of the protection of the - external pointer that wraps this */ + /* con will be disposed by the R GC, it is protected as part of + the protection of the external pointer that wraps this */ } } // namespace rprotobuf From noreply at r-forge.r-project.org Tue Dec 31 21:09:56 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 21:09:56 +0100 (CET) Subject: [Rprotobuf-commits] r676 - pkg/src Message-ID: <20131231200956.2CFA7185EFF@r-forge.r-project.org> Author: murray Date: 2013-12-31 21:09:55 +0100 (Tue, 31 Dec 2013) New Revision: 676 Modified: pkg/src/mutators.cpp Log: Use a specific enum type rather than casting to int. Also explicitly cast to void a return value we ignore. Suggested by: Flexelint Modified: pkg/src/mutators.cpp =================================================================== --- pkg/src/mutators.cpp 2013-12-31 20:09:12 UTC (rev 675) +++ pkg/src/mutators.cpp 2013-12-31 20:09:55 UTC (rev 676) @@ -200,14 +200,14 @@ default: Rcpp::stop("cannot cast SEXP to bool"); } - return (bool)0; // -Wall, should not happen since we only call this when we know it works + return (bool)0; // Unreachable. -Wall } std::string GET_stdstring(SEXP x, int index) { if (TYPEOF(x) == STRSXP) { return (CHAR(STRING_ELT(x, index))); } - return ""; // -Wall, should not happen since we only call this when we know it works + return ""; // Unreachable. -Wall } std::string GET_bytes(SEXP x, int index) { @@ -228,7 +228,7 @@ default: Rcpp::stop("cannot cast SEXP to bytes"); } - return ""; // -Wall, should not happen since we only call this when we know it works + return ""; // Unreachable. -Wall } /** @@ -1158,7 +1158,7 @@ // if the R type is RAWSXP and the cpp type is string or bytes, // then value_size is actually one because the raw vector // is converted to a string - int field_type = field_desc->type(); + GPB::FieldDescriptor::Type field_type = field_desc->type(); if (field_type == TYPE_STRING || field_type == TYPE_BYTES) { if (TYPEOF(value) == RAWSXP) { value_size = 1; @@ -1191,7 +1191,7 @@ Rcpp::CharacterVector names = list.attr("names"); int n = list.size(); for (int i = 0; i < n; i++) { - setMessageField(message, names[i], list[i]); + (void)setMessageField(message, names[i], list[i]); } } From noreply at r-forge.r-project.org Tue Dec 31 21:10:22 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 21:10:22 +0100 (CET) Subject: [Rprotobuf-commits] r677 - pkg/src Message-ID: <20131231201022.7DE6A185F2C@r-forge.r-project.org> Author: murray Date: 2013-12-31 21:10:22 +0100 (Tue, 31 Dec 2013) New Revision: 677 Modified: pkg/src/RconnectionCopyingInputStream.h Log: Mark a member method const. Suggested by: Flexelint Modified: pkg/src/RconnectionCopyingInputStream.h =================================================================== --- pkg/src/RconnectionCopyingInputStream.h 2013-12-31 20:09:55 UTC (rev 676) +++ pkg/src/RconnectionCopyingInputStream.h 2013-12-31 20:10:22 UTC (rev 677) @@ -8,7 +8,7 @@ RconnectionCopyingInputStream(int id); int Read(void* buffer, int size); - bool Failure() { return (failure); } + bool Failure() const { return (failure); } private: int connection_id; From noreply at r-forge.r-project.org Tue Dec 31 21:12:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 21:12:27 +0100 (CET) Subject: [Rprotobuf-commits] r678 - pkg/src Message-ID: <20131231201227.AA3631868E8@r-forge.r-project.org> Author: murray Date: 2013-12-31 21:12:26 +0100 (Tue, 31 Dec 2013) New Revision: 678 Modified: pkg/src/lookup.cpp Log: Replace a call to Rf_error with Rcpp exception handling and BEGIN/END_RCPP. Add an 'unused_' prefix to arguments that we don't use. Modified: pkg/src/lookup.cpp =================================================================== --- pkg/src/lookup.cpp 2013-12-31 20:10:22 UTC (rev 677) +++ pkg/src/lookup.cpp 2013-12-31 20:12:26 UTC (rev 678) @@ -135,9 +135,9 @@ /** * Does nothing. Not applicable */ -int rProtoBufTable_remove(const char *const name, R_ObjectTable *tb) { +int rProtoBufTable_remove(const char *const unused_name, R_ObjectTable *unused_tb) { #ifdef LOOKUP_DEBUG - Rprintf(" >> rProtoBufTable_remove( %s) \n", name); + Rprintf(" >> rProtoBufTable_remove( %s) \n", unused_name); #endif Rf_error("cannot remove from protobuf descriptor pool"); return (0); // make -Wall happy @@ -151,7 +151,7 @@ * @param tb lookup table * @return allways _FALSE_ (for now) */ -Rboolean rProtoBufTable_canCache(const char *const name, R_ObjectTable *tb) { +Rboolean rProtoBufTable_canCache(const char *const unused_name, R_ObjectTable *unused_tb) { #ifdef LOOKUP_DEBUG Rprintf(" >> rProtoBufTable_canCache\n"); #endif @@ -165,9 +165,10 @@ * NULL to indicate assign is not possible on this lookup table * without giving such a hard error. */ -SEXP rProtoBufTable_assign(const char *const name, SEXP value, R_ObjectTable *tb) { +SEXP rProtoBufTable_assign(const char *const unused_name, SEXP unused_value, + R_ObjectTable *unused_tb) { #ifdef LOOKUP_DEBUG - Rprintf(" >> rProtoBufTable_assign( %s ) \n", name); + Rprintf(" >> rProtoBufTable_assign( %s ) \n", unused_name); #endif return (R_NilValue); // make -Wall happy } @@ -190,7 +191,8 @@ return (objects); } -SEXP newProtocolBufferLookup(SEXP possexp) { +RcppExport SEXP newProtocolBufferLookup(SEXP possexp) { + BEGIN_RCPP #ifdef LOOKUP_DEBUG Rprintf("\n"); #endif @@ -199,7 +201,7 @@ SEXP val, klass; tb = (R_ObjectTable *)malloc(sizeof(R_ObjectTable)); - if (!tb) Rf_error("cannot allocate space for an internal R object table"); + if (!tb) throw Rcpp::exception("cannot allocate space for an internal R object table"); tb->type = RPROTOBUF_LOOKUP; /* FIXME: not sure what this should be */ tb->cachedNames = NULL; @@ -229,7 +231,9 @@ int pos = Rcpp::as(possexp); fun(val, Rcpp::Named("pos") = pos, Rcpp::Named("name") = "RProtoBuf:DescriptorPool"); + // TODO(mstokely): Somewhere we should deallocate tb? If package is unattached? return (val); + END_RCPP } } // namespace rprotobuf From noreply at r-forge.r-project.org Tue Dec 31 21:13:27 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 21:13:27 +0100 (CET) Subject: [Rprotobuf-commits] r679 - pkg/src Message-ID: <20131231201328.14E3518694C@r-forge.r-project.org> Author: murray Date: 2013-12-31 21:13:27 +0100 (Tue, 31 Dec 2013) New Revision: 679 Modified: pkg/src/RSourceTree.cpp Log: Replace it++ with ++it for efficiency. Suggested by Flexelint. Modified: pkg/src/RSourceTree.cpp =================================================================== --- pkg/src/RSourceTree.cpp 2013-12-31 20:12:26 UTC (rev 678) +++ pkg/src/RSourceTree.cpp 2013-12-31 20:13:27 UTC (rev 679) @@ -19,7 +19,7 @@ file += filename; file_descriptor = open(file.c_str(), O_RDONLY); if (file_descriptor > 0) break; - it++; + ++it; } } From noreply at r-forge.r-project.org Tue Dec 31 21:13:56 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 21:13:56 +0100 (CET) Subject: [Rprotobuf-commits] r680 - pkg/src Message-ID: <20131231201356.2770918694F@r-forge.r-project.org> Author: murray Date: 2013-12-31 21:13:55 +0100 (Tue, 31 Dec 2013) New Revision: 680 Modified: pkg/src/extractors.cpp Log: Mark functions with extern C / RcppExport to match header. Modified: pkg/src/extractors.cpp =================================================================== --- pkg/src/extractors.cpp 2013-12-31 20:13:27 UTC (rev 679) +++ pkg/src/extractors.cpp 2013-12-31 20:13:55 UTC (rev 680) @@ -57,7 +57,7 @@ * @return the field called "name" of the message if the * message has the field, otherwise an error is generated */ -SEXP getMessageField(SEXP pointer, SEXP name) { +RcppExport SEXP getMessageField(SEXP pointer, SEXP name) { #ifdef RPB_DEBUG Rprintf("\n"); @@ -78,8 +78,8 @@ return (extractFieldAsSEXP(message, field_desc)); } -SEXP extractFieldAsSEXP(const Rcpp::XPtr& message, - const GPB::FieldDescriptor* fieldDesc) { +RcppExport SEXP extractFieldAsSEXP(const Rcpp::XPtr& message, + const GPB::FieldDescriptor* fieldDesc) { BEGIN_RCPP const Reflection* ref = message->GetReflection(); From noreply at r-forge.r-project.org Tue Dec 31 22:51:25 2013 From: noreply at r-forge.r-project.org (noreply at r-forge.r-project.org) Date: Tue, 31 Dec 2013 22:51:25 +0100 (CET) Subject: [Rprotobuf-commits] r681 - pkg/vignettes Message-ID: <20131231215125.B82381868A3@r-forge.r-project.org> Author: edd Date: 2013-12-31 22:51:25 +0100 (Tue, 31 Dec 2013) New Revision: 681 Modified: pkg/vignettes/RProtoBuf-intro.Rnw Log: define consistent color use for hyperref Modified: pkg/vignettes/RProtoBuf-intro.Rnw =================================================================== --- pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-31 20:13:55 UTC (rev 680) +++ pkg/vignettes/RProtoBuf-intro.Rnw 2013-12-31 21:51:25 UTC (rev 681) @@ -6,6 +6,14 @@ \usepackage{url} \usepackage[colorlinks]{hyperref} +\definecolor{link}{rgb}{0,0,0.3} +\hypersetup{ + colorlinks,% + citecolor=link,% + filecolor=link,% + linkcolor=link,% + urlcolor=link +} \setlength{\oddsidemargin}{0pt} \setlength{\textwidth}{17cm} % uh-oh, I use letter :) \setcounter{tocdepth}{2} @@ -1247,7 +1255,7 @@ <<>>= fileDescriptor(tutorial.Person$id) tutorial.Person$id$fileDescriptor() -@ +@ \subsubsection{containing\_type} \label{fielddescriptor-method-containingtype} @@ -1522,7 +1530,7 @@ <<>>= fileDescriptor(tutorial.Person$PhoneType) tutorial.Person$PhoneType$fileDescriptor() -@ +@ \subsubsection{containing\_type} \label{enumdescriptor-method-containingtype} @@ -1532,7 +1540,7 @@ <<>>= tutorial.Person$PhoneType$containing_type() -@ +@ \subsubsection{length} \label{enumdescriptor-method-length} @@ -1542,7 +1550,7 @@ <<>>= length(tutorial.Person$PhoneType) tutorial.Person$PhoneType$length() -@ +@ \subsubsection{has} \label{enumdescriptor-method-has} @@ -1553,7 +1561,7 @@ <<>>= tutorial.Person$PhoneType$has("WORK") tutorial.Person$PhoneType$has("nonexistant") -@ +@ \subsubsection{value\_count} \label{enumdescriptor-method-valuecount} @@ -1564,7 +1572,7 @@ <<>>= value_count(tutorial.Person$PhoneType) tutorial.Person$PhoneType$value_count() -@ +@ \subsubsection{value} \label{enumdescriptor-method-value} @@ -1577,7 +1585,7 @@ tutorial.Person$PhoneType$value(1) tutorial.Person$PhoneType$value(name="HOME") tutorial.Person$PhoneType$value(number=1) -@ +@ \subsection{enum value descriptors} \label{subsec-EnumValueDescriptor} @@ -1728,7 +1736,7 @@ f <- tutorial.Person$fileDescriptor() f f$Person -@ +@ \begin{table}[h] \centering \begin{small} @@ -1957,7 +1965,7 @@ \texttt{addressbook.proto} is the following line : \begin{verbatim} - extensions 100 to 199; + extensions 100 to 199; \end{verbatim} This specifies that other users in other .proto files can use tag @@ -1973,11 +1981,11 @@ "package tutorial;", paste0("extend Person {\n optional string nationality = 100;\n}")), extend.proto) -@ +@ <>= -writeLines(readLines(extend.proto)) -@ +writeLines(readLines(extend.proto)) +@ After importing this new \texttt{.proto} file with an extension defined, we can get or set the value of this extension in Messages of @@ -1985,13 +1993,13 @@ <<>>= library(RProtoBuf) -readProtoFiles(extend.proto) +readProtoFiles(extend.proto) person <- new(tutorial.Person, id=1, name="Murray") person person$setExtension(P("tutorial.nationality"), "USA") cat(as.character(person)) person$getExtension(P("tutorial.nationality")) -@ +@ The character output of this message places the extension type in brackets to differentiate it from other fields in the message, and so