summaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/vpp_serializer.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/vpp-api/python/vpp_papi/vpp_serializer.py')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_serializer.py54
1 files changed, 31 insertions, 23 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_serializer.py b/src/vpp-api/python/vpp_papi/vpp_serializer.py
index a001cca565a..f78972979cd 100644
--- a/src/vpp-api/python/vpp_papi/vpp_serializer.py
+++ b/src/vpp-api/python/vpp_papi/vpp_serializer.py
@@ -55,14 +55,10 @@ class BaseTypes(object):
return self.packer.unpack_from(data, offset)[0], self.packer.size
-types = {}
-types['u8'] = BaseTypes('u8')
-types['u16'] = BaseTypes('u16')
-types['u32'] = BaseTypes('u32')
-types['i32'] = BaseTypes('i32')
-types['u64'] = BaseTypes('u64')
-types['f64'] = BaseTypes('f64')
-types['bool'] = BaseTypes('bool')
+types = {'u8': BaseTypes('u8'), 'u16': BaseTypes('u16'),
+ 'u32': BaseTypes('u32'), 'i32': BaseTypes('i32'),
+ 'u64': BaseTypes('u64'), 'f64': BaseTypes('f64'),
+ 'bool': BaseTypes('bool')}
def vpp_get_type(name):
@@ -72,6 +68,10 @@ def vpp_get_type(name):
return None
+class VPPSerializerValueError(ValueError):
+ pass
+
+
class FixedList_u8(object):
def __init__(self, name, field_type, num):
self.name = name
@@ -85,16 +85,18 @@ class FixedList_u8(object):
if not list:
return b'\x00' * self.size
if len(list) > self.num:
- raise ValueError('Fixed list length error for "{}", got: {}'
- ' expected: {}'
- .format(self.name, len(list), self.num))
+ raise VPPSerializerValueError(
+ 'Fixed list length error for "{}", got: {}'
+ ' expected: {}'
+ .format(self.name, len(list), self.num))
return self.packer.pack(list)
def unpack(self, data, offset=0, result=None):
if len(data[offset:]) < self.num:
- raise ValueError('Invalid array length for "{}" got {}'
- ' expected {}'
- .format(self.name, len(data[offset:]), self.num))
+ raise VPPSerializerValueError(
+ 'Invalid array length for "{}" got {}'
+ ' expected {}'
+ .format(self.name, len(data[offset:]), self.num))
return self.packer.unpack(data, offset)
@@ -106,8 +108,9 @@ class FixedList(object):
def pack(self, list, kwargs):
if len(list) != self.num:
- raise ValueError('Fixed list length error, got: {} expected: {}'
- .format(len(list), self.num))
+ raise VPPSerializerValueError(
+ 'Fixed list length error, got: {} expected: {}'
+ .format(len(list), self.num))
b = bytes()
for e in list:
b += self.packer.pack(e)
@@ -137,8 +140,9 @@ class VLAList(object):
if not list:
return b""
if len(list) != kwargs[self.length_field]:
- raise ValueError('Variable length error, got: {} expected: {}'
- .format(len(list), kwargs[self.length_field]))
+ raise VPPSerializerValueError(
+ 'Variable length error, got: {} expected: {}'
+ .format(len(list), kwargs[self.length_field]))
b = bytes()
# u8 array
@@ -187,7 +191,8 @@ class VLAList_legacy():
total = 0
# Return a list of arguments
if (len(data) - offset) % self.packer.size:
- raise ValueError('Legacy Variable Length Array length mismatch.')
+ raise VPPSerializerValueError(
+ 'Legacy Variable Length Array length mismatch.')
elements = int((len(data) - offset) / self.packer.size)
r = []
for e in range(elements):
@@ -241,7 +246,8 @@ class VPPUnionType(object):
f_type, f_name = f
if f_type not in types:
logger.debug('Unknown union type {}'.format(f_type))
- raise ValueError('Unknown message type {}'.format(f_type))
+ raise VPPSerializerValueError(
+ 'Unknown message type {}'.format(f_type))
fields.append(f_name)
size = types[f_type].size
self.packers[f_name] = types[f_type]
@@ -309,7 +315,8 @@ class VPPType(object):
self.fieldtypes.append(f_type)
if f_type not in types:
logger.debug('Unknown type {}'.format(f_type))
- raise ValueError('Unknown message type {}'.format(f_type))
+ raise VPPSerializerValueError(
+ 'Unknown message type {}'.format(f_type))
if len(f) == 3: # list
list_elements = f[2]
if list_elements == 0:
@@ -345,8 +352,9 @@ class VPPType(object):
# Try one of the format functions
if data and type(data) is not dict and a not in data:
- raise ValueError("Invalid argument: {} expected {}.{}".
- format(data, self.name, a))
+ raise VPPSerializerValueError(
+ "Invalid argument: {} expected {}.{}".
+ format(data, self.name, a))
# Defaulting to zero.
if not data or a not in data: # Default to 0