pyloxi: rewrite deserialization to use OFReader
diff --git a/py_gen/templates/common.py b/py_gen/templates/common.py
index 516bf05..ccf6032 100644
--- a/py_gen/templates/common.py
+++ b/py_gen/templates/common.py
@@ -39,29 +39,30 @@
 # HACK make this module visible as 'common' to simplify code generation
 common = sys.modules[__name__]
 
-def unpack_list_flow_stats_entry(buf):
-    return loxi.generic_util.unpack_list(flow_stats_entry.unpack, "!H", buf)
+def unpack_list_flow_stats_entry(reader):
+    return loxi.generic_util.unpack_list_lv16(reader, flow_stats_entry.unpack)
 
-def unpack_list_queue_prop(buf):
-    def deserializer(buf):
-        type, = struct.unpack_from("!H", buf)
-        if type == const.OFPQT_MIN_RATE:
-            return queue_prop_min_rate.unpack(buf)
+def unpack_list_queue_prop(reader):
+    def deserializer(reader, typ):
+        if typ == const.OFPQT_MIN_RATE:
+            return queue_prop_min_rate.unpack(reader)
         else:
-            raise loxi.ProtocolError("unknown queue prop %d" % type)
-    return loxi.generic_util.unpack_list(deserializer, "!2xH", buf)
+            raise loxi.ProtocolError("unknown queue prop %d" % typ)
+    return loxi.generic_util.unpack_list_tlv16(reader, deserializer)
 
-def unpack_list_packet_queue(buf):
-    return loxi.generic_util.unpack_list(packet_queue.unpack, "!4xH", buf)
+def unpack_list_packet_queue(reader):
+    def wrapper(reader):
+        length, = reader.peek('!4xH')
+        return packet_queue.unpack(reader.slice(length))
+    return loxi.generic_util.unpack_list(reader, wrapper)
 
-def unpack_list_hello_elem(buf):
-    def deserializer(buf):
-        type, = struct.unpack_from("!H", buf)
-        if type == const.OFPHET_VERSIONBITMAP:
-            return hello_elem_versionbitmap.unpack(buf)
+def unpack_list_hello_elem(reader):
+    def deserializer(reader, typ):
+        if typ == const.OFPHET_VERSIONBITMAP:
+            return hello_elem_versionbitmap.unpack(reader)
         else:
             return None
-    return [x for x in loxi.generic_util.unpack_list(deserializer, "!2xH", buf) if x != None]
+    return [x for x in loxi.generic_util.unpack_list_tlv16(reader, deserializer) if x != None]
 
 :: for ofclass in ofclasses:
 :: include('_ofclass.py', ofclass=ofclass, superclass="object")