[Rprotobuf-commits] r723 - in pkg: . inst/unitTests man

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Jan 5 04:50:08 CET 2014


Author: murray
Date: 2014-01-05 04:50:05 +0100 (Sun, 05 Jan 2014)
New Revision: 723

Modified:
   pkg/ChangeLog
   pkg/inst/unitTests/runit.serialize.R
   pkg/man/ArrayInputStream-class.Rd
Log:
Add a basic test and some examples to the man page of using
ArrayInputStream, which now works.  I think the design may be a bit
muddled here as the CodedInputStream consumes from the
ZeroCopyInputStream which precludes examples like the original ones
commented out here from working.  We may need to change htis a bit.

This makes a great interactive way to understand how protocol buffer
serialization works, but I don't have a strong need for this since
serialize() of the whole message (done in C++) works fine.



Modified: pkg/ChangeLog
===================================================================
--- pkg/ChangeLog	2014-01-05 03:26:03 UTC (rev 722)
+++ pkg/ChangeLog	2014-01-05 03:50:05 UTC (rev 723)
@@ -10,10 +10,13 @@
 	* inst/unitTests/runit.serialize.R (test.encoding): Add tests
 	  verifying the exact byte serialization as described in the
 	  encoding documentation.
+	  (test.arrayinputstream): Add new test of ArrayInputStreams.
 	* src/wrapper_ZeroCopyInputStream.cpp (rprotobuf): Add
 	  BEGIN/END_RCPP macros to gracefully catch exceptions and return
 	  them as R language errors.
 	* src/streams.cpp (rprotobuf): Idem.
+	* man/ArrayInputStream-class.Rd: Add some examples of using
+	  ArrayInputStream.
 
 2014-01-04  Dirk Eddelbuettel  <edd at debian.org>
 

Modified: pkg/inst/unitTests/runit.serialize.R
===================================================================
--- pkg/inst/unitTests/runit.serialize.R	2014-01-05 03:26:03 UTC (rev 722)
+++ pkg/inst/unitTests/runit.serialize.R	2014-01-05 03:50:05 UTC (rev 723)
@@ -25,6 +25,19 @@
 	}
 }
 
+test.arrayinputstream <- function() {
+    # Note: This class is experimental, and some parts of the design
+    # may need to change, but this works now.
+    stream <- ArrayInputStream(as.raw(0:10))
+    checkEquals(stream$ReadRaw(5), as.raw(0:4))
+
+    stringstream <- ArrayInputStream(as.raw(c(0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67)))
+    checkEquals(stringstream$ReadString(as.integer(7)), "testing")
+
+    intstream <- ArrayInputStream(as.raw(c(0x9e, 0xa7, 0x05)))
+    checkEquals(intstream$ReadVarint32(), 86942)
+}
+
 test.encoding <- function() {
         if (!exists("protobuf_encoding_test.Test1",
                     "RProtoBuf:DescriptorPool")) {

Modified: pkg/man/ArrayInputStream-class.Rd
===================================================================
--- pkg/man/ArrayInputStream-class.Rd	2014-01-05 03:26:03 UTC (rev 722)
+++ pkg/man/ArrayInputStream-class.Rd	2014-01-05 03:50:05 UTC (rev 723)
@@ -25,17 +25,24 @@
 \seealso{
 	\linkS4class{ZeroCopyInputStream} for methods
 }
-% \examples{
+\examples{
+stream <- ArrayInputStream(as.raw(0:10))
+stream$ReadRaw(5)
+
+stringsstream <- ArrayInputStream(as.raw(c(0x74, 0x65, 0x73, 0x74, 0x69, 0x6e, 0x67)))
+stringsstream$ReadString(7)
+
+intstream <- ArrayInputStream(as.raw(c(0x9e, 0xa7, 0x05)))
+intstream$ReadVarint32()
+}
 % local({
 % 	stream <- ArrayInputStream( as.raw(0:10) )
 % 	stopifnot( identical( stream$Next(), as.raw(0:10) ) )
 % 	stream$BackUp( 5 )
 % 	stopifnot( identical( stream$Next(), as.raw(6:10) ) )
-% 	
+%
 % 	# limiting the block size
 % 	stream <- ArrayInputStream( as.raw(0:10), 5 )
 % 	stopifnot( identical(length( stream$Next() ), 5L ) )
 % })
-% 
-% }
 \keyword{classes}



More information about the Rprotobuf-commits mailing list