summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/vpp_serializer.py
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2020-12-03 21:06:28 -0500
committerOle Tr�an <otroan@employees.org>2020-12-04 12:14:34 +0000
commit3825d93afeed42e62e41f743df69058511c51079 (patch)
tree5affb734a1f5750c085c74df20ee07c61a87a676 /src/vpp-api/python/vpp_papi/vpp_serializer.py
parenta51f9b3747d3e065b4bc7bb46aea8df11719b6cd (diff)
papi: add support for enumflag part 1 of 2
Allow for papi to accept the new enumflag type. Change-Id: I8d8dc8fdb122e9a1b1881f5b2558635c75e4a299 Type: feature Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com> (cherry picked from commit 299abebe2942b4c78b85f9f3b8843f8213bf1efe)
Diffstat (limited to 'src/vpp-api/python/vpp_papi/vpp_serializer.py')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_serializer.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_serializer.py b/src/vpp-api/python/vpp_papi/vpp_serializer.py
index 81ce53e378d..644aeac65c6 100644
--- a/src/vpp-api/python/vpp_papi/vpp_serializer.py
+++ b/src/vpp-api/python/vpp_papi/vpp_serializer.py
@@ -356,7 +356,10 @@ class VLAList_legacy(Packer):
)
+# Will change to IntEnum after 21.04 release
class VPPEnumType(Packer):
+ output_class = IntFlag
+
def __init__(self, name, msgdef, options=None):
self.size = types['u32'].size
self.name = name
@@ -371,9 +374,9 @@ class VPPEnumType(Packer):
continue
ename, evalue = f
e_hash[ename] = evalue
- self.enum = IntFlag(name, e_hash)
+ self.enum = self.output_class(name, e_hash)
types[name] = self
- class_types[name] = VPPEnumType
+ class_types[name] = self.__class__
self.options = options
def __getattr__(self, name):
@@ -382,7 +385,6 @@ class VPPEnumType(Packer):
def __bool__(self):
return True
-
def pack(self, data, kwargs=None):
if data is None: # Default to zero if not specified
if self.options and 'default' in self.options:
@@ -396,16 +398,23 @@ class VPPEnumType(Packer):
x, size = types[self.enumtype].unpack(data, offset)
return self.enum(x), size
- @staticmethod
- def _get_packer_with_options(f_type, options):
- return VPPEnumType(f_type, types[f_type].msgdef, options=options)
+ @classmethod
+ def _get_packer_with_options(cls, f_type, options):
+ return cls(f_type, types[f_type].msgdef, options=options)
def __repr__(self):
- return "VPPEnumType(name=%s, msgdef=%s, options=%s)" % (
- self.name, self.msgdef, self.options
+ return "%s(name=%s, msgdef=%s, options=%s)" % (
+ self.__class__.__name__, self.name, self.msgdef, self.options
)
+class VPPEnumFlagType(VPPEnumType):
+ output_class = IntFlag
+
+ def __init__(self, name, msgdef, options=None):
+ super(VPPEnumFlagType, self).__init__(name, msgdef, options)
+
+
class VPPUnionType(Packer):
def __init__(self, name, msgdef):
self.name = name