Python API: Add enum and union support.
[vpp.git] / src / vpp-api / python / vpp_papi / vpp_serializer.py
index 146a8f6..7f5c5ac 100644 (file)
@@ -24,8 +24,6 @@ import logging
 # logger.setLevel(logging.DEBUG)
 #
 logger = logging.getLogger(__name__)
-FORMAT = "[%(filename)s:%(lineno)s - %(funcName)s() ] %(message)s"
-logging.basicConfig(format=FORMAT)
 
 
 class BaseTypes():
@@ -72,6 +70,8 @@ class FixedList_u8():
         self.size = self.packer.size
 
     def pack(self, list, kwargs):
+        """Packs a fixed length bytestring. Left-pads with zeros
+        if input data is too short."""
         logger.debug("Data: {}".format(list))
 
         if len(list) > self.num:
@@ -131,8 +131,7 @@ class VLAList():
 
         # u8 array
         if self.packer.size == 1:
-            p = BaseTypes('u8', len(list))
-            return p.pack(list)
+            return bytearray(list)
 
         for e in list:
             b += self.packer.pack(e)
@@ -166,6 +165,10 @@ class VLAList_legacy():
 
     def pack(self, list, kwargs=None):
         logger.debug("Data: {}".format(list))
+
+        if self.packer.size == 1:
+            return bytes(list)
+
         b = bytes()
         for e in list:
             b += self.packer.pack(e)
@@ -317,7 +320,11 @@ class VPPType():
                              .format(a))
                 b += b'\x00' * self.packers[i].size
                 continue
-            b += self.packers[i].pack(data[a], kwargs)
+
+            if isinstance(self.packers[i], VPPType):
+                b += self.packers[i].pack(data[a], kwargs[a])
+            else:
+                b += self.packers[i].pack(data[a], kwargs)
         return b
 
     def unpack(self, data, offset=0, result=None):
@@ -330,3 +337,7 @@ class VPPType():
             result.append(x)
             offset += p.size
         return self.tuple._make(result)
+
+
+class VPPMessage(VPPType):
+    pass