[Rprotobuf-commits] r715 - in pkg/inst: . python

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Jan 4 22:06:34 CET 2014


Author: jeroenooms
Date: 2014-01-04 22:06:34 +0100 (Sat, 04 Jan 2014)
New Revision: 715

Added:
   pkg/inst/python/
   pkg/inst/python/readmsg.py
   pkg/inst/python/runtest.sh
   pkg/inst/python/writemsg.R
Log:
adding some python tests

Added: pkg/inst/python/readmsg.py
===================================================================
--- pkg/inst/python/readmsg.py	                        (rev 0)
+++ pkg/inst/python/readmsg.py	2014-01-04 21:06:34 UTC (rev 715)
@@ -0,0 +1,16 @@
+#!/usr/bin/env python
+#
+# Simple test script to read a serialized message in python
+#
+import rexp_pb2;
+import glob;
+
+messages = glob.glob("*.msg");
+for myfile in messages:
+	print("Reading message " + myfile + " ...")
+	f = open(myfile, 'rb')
+	msg = rexp_pb2.REXP();	
+	msg.ParseFromString(f.read())
+	f.close();
+	print(msg)
+	del msg

Added: pkg/inst/python/runtest.sh
===================================================================
--- pkg/inst/python/runtest.sh	                        (rev 0)
+++ pkg/inst/python/runtest.sh	2014-01-04 21:06:34 UTC (rev 715)
@@ -0,0 +1,16 @@
+#!/bin/sh
+
+#write some PB data with R
+Rscript writemsg.R
+
+#compile proto file
+cp -f ../proto/rexp.proto .
+protoc rexp.proto --python_out=.
+rm rexp.proto
+
+#read with python and print
+python readmsg.py
+
+#cleanup tmp files
+rm rexp_pb2.py
+rm *.msg


Property changes on: pkg/inst/python/runtest.sh
___________________________________________________________________
Added: svn:executable
   + *

Added: pkg/inst/python/writemsg.R
===================================================================
--- pkg/inst/python/writemsg.R	                        (rev 0)
+++ pkg/inst/python/writemsg.R	2014-01-04 21:06:34 UTC (rev 715)
@@ -0,0 +1,13 @@
+#simple R script to serialize some R objects
+library(RProtoBuf)
+
+#some vectors
+serialize_pb(c(1,2,pi, NA,NaN,Inf,-Inf), "double.msg")
+serialize_pb(c(1L, 2L, NA), "integer.msg")
+serialize_pb(c(TRUE, FALSE, NA), "logical.msg")
+serialize_pb(c("foo", "bar", NA), "character.msg")
+serialize_pb(charToRaw("This is a test"), "raw.msg")
+
+#lists
+serialize_pb(list(foo=c(1,2,pi), bar=TRUE, baz="blabla", zoo=NULL), "list.msg")
+serialize_pb(iris[1:3,], "dataframe.msg")



More information about the Rprotobuf-commits mailing list