# logger.setLevel(logging.DEBUG)
#
logger = logging.getLogger(__name__)
-FORMAT = "[%(filename)s:%(lineno)s - %(funcName)s() ] %(message)s"
-logging.basicConfig(format=FORMAT)
class BaseTypes():
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:
# 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)
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)
.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):
result.append(x)
offset += p.size
return self.tuple._make(result)
+
+
+class VPPMessage(VPPType):
+ pass