Commit 05041bf4 authored by Anders Blomdell's avatar Anders Blomdell
Browse files

Added StreamWriter and StreamReader to python library.

Updated wiki_example to use StreamReader. 
parent 7e5d6af5
...@@ -25,3 +25,9 @@ example.h ...@@ -25,3 +25,9 @@ example.h
example.py example.py
examples/wiki_example/example.encoded examples/wiki_example/example.encoded
example.encoded example.encoded
examples/simple/*.class
examples/simple/encoded_data
examples/simple/example_decoder
examples/simple/example_encoder
lib/c/test/test_labcomm_basic_type_encoding
lib/c/test/test_labcomm_generated_encoding
SUBDIRS=compiler lib examples test SUBDIRS=compiler lib test examples
export LABCOMM_JAR=$(shell pwd)/compiler/labComm.jar export LABCOMM_JAR=$(shell pwd)/compiler/labComm.jar
export LABCOMM=java -jar $(LABCOMM_JAR) export LABCOMM=java -jar $(LABCOMM_JAR)
......
...@@ -2,7 +2,8 @@ all: ...@@ -2,7 +2,8 @@ all:
echo To be done... echo To be done...
test: test:
echo To be done... echo More to be done...
cd simple ; sh compile.sh && sh run.sh
clean: clean:
echo To be done... echo To be done...
...@@ -3,29 +3,8 @@ ...@@ -3,29 +3,8 @@
import labcomm import labcomm
import sys import sys
class FileReader:
def __init__(self, name):
self.f = open(name)
pass
def start(self, decoder, version):
other_version = decoder.decode_string()
if version != other_version:
raise Exception("LabComm version mismatch %s != %s" %
(version, other_version))
pass
def read(self, count):
s = self.f.read(count)
if len(s) == 0:
raise Exception("EOF")
return s
def mark(self, value, decl):
pass
if __name__ == "__main__": if __name__ == "__main__":
d = labcomm.Decoder(FileReader(sys.argv[1])) d = labcomm.Decoder(labcomm.StreamReader(open(sys.argv[1])))
while True: while True:
try: try:
......
class StreamReader:
def __init__(self, stream):
self.stream = stream
pass
def start(self, decoder, version):
other_version = decoder.decode_string()
if version != other_version:
raise Exception("LabComm version mismatch %s != %s" %
(version, other_version))
pass
def read(self, count):
result = self.stream.read(count)
if len(result) == 0:
raise EOFError()
return result
def mark(self, value, decl):
pass
pass
class StreamWriter:
def __init__(self, stream):
self.stream = stream
pass
def start(self, encoder, version):
encoder.encode_string(version)
pass
def write(self, data):
self.stream.write(data)
pass
def mark(self):
self.stream.flush()
pass
pass
import labcomm.LabComm import labcomm.LabComm
from labcomm.StreamReader import StreamReader
from labcomm.StreamWriter import StreamWriter
Decoder = labcomm.LabComm.Decoder Decoder = labcomm.LabComm.Decoder
Encoder = labcomm.LabComm.Encoder Encoder = labcomm.LabComm.Encoder
......
...@@ -127,18 +127,7 @@ class Test: ...@@ -127,18 +127,7 @@ class Test:
self.next = threading.Semaphore(0) self.next = threading.Semaphore(0)
decoder = threading.Thread(target=self.decode, args=(p.stdout,)) decoder = threading.Thread(target=self.decode, args=(p.stdout,))
decoder.start() decoder.start()
class Writer: encoder = labcomm.Encoder(labcomm.StreamWriter(p.stdin))
def start(self, encoder, version):
encoder.encode_string(version)
pass
def write(self, data):
p.stdin.write(data)
pass
def mark(self):
p.stdin.flush()
pass
pass
encoder = labcomm.Encoder(Writer())
for name,signature in self.signatures: for name,signature in self.signatures:
encoder.add_decl(signature) encoder.add_decl(signature)
pass pass
...@@ -164,22 +153,7 @@ class Test: ...@@ -164,22 +153,7 @@ class Test:
pass pass
def decode(self, f): def decode(self, f):
class Reader: decoder = labcomm.Decoder(labcomm.StreamReader(f))
def start(self, decoder, version):
other_version = decoder.decode_string()
if version != other_version:
raise Exception("LabComm version mismatch %s != %s" %
(version, other_version))
pass
def read(self, count):
result = f.read(count)
if len(result) == 0:
raise EOFError()
return result
def mark(self, value, decl):
pass
pass
decoder = labcomm.Decoder(Reader())
try: try:
while True: while True:
value,decl = decoder.decode() value,decl = decoder.decode()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment