From bc52d70a191a271cb57c868b078a0d4c7fd85245 Mon Sep 17 00:00:00 2001
From: Sven Gestegard Robertz <sven.robertz@cs.lth.se>
Date: Sat, 15 Feb 2014 20:18:53 +0100
Subject: [PATCH] added example python encoder

---
 examples/simple/example_encoder.py | 19 +++++++++++++++++++
 examples/simple/run.sh             |  4 ++++
 2 files changed, 23 insertions(+)
 create mode 100755 examples/simple/example_encoder.py

diff --git a/examples/simple/example_encoder.py b/examples/simple/example_encoder.py
new file mode 100755
index 0000000..4993373
--- /dev/null
+++ b/examples/simple/example_encoder.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+import labcomm
+import sys
+import simple
+
+if __name__ == '__main__':
+    encoder = labcomm.Encoder(labcomm.StreamWriter(open(sys.argv[1], 'w')))
+    encoder.add_decl(simple.theTwoInts.signature)
+    encoder.add_decl(simple.IntString.signature)
+    foo = simple.theTwoInts()
+    foo.a = 13
+    foo.b = 37
+    encoder.encode(foo, simple.theTwoInts.signature)
+
+    bar = simple.IntString()
+    bar.x = 1742
+    bar.s = "A string from Python"
+    encoder.encode(bar, simple.IntString.signature)
diff --git a/examples/simple/run.sh b/examples/simple/run.sh
index 182039a..f1ed3ee 100644
--- a/examples/simple/run.sh
+++ b/examples/simple/run.sh
@@ -2,6 +2,10 @@ export LD_LIBRARY_PATH=../../lib/c/
 
 java -cp .:../../lib/java:gen Encoder encoded_data
 ./example_decoder encoded_data
+
+PYTHONPATH=../../lib/python:gen ./example_encoder.py encoded_data
+java -cp .:../../lib/java:gen Decoder encoded_data
+
 ./example_encoder encoded_data
 java -cp .:../../lib/java:gen Decoder encoded_data
 
-- 
GitLab