From 1960170e6a7abdf29f4097bfac9355bfc88a4e29 Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Thu, 3 Sep 2020 11:47:33 -0400 Subject: [PATCH] `_FieldType`: add `size_is_dynamic` property This new property indicates if the field type's size is static or dynamic. A string field type has a dynamic size, as well as any structure field type which contains one, recursively. As of this version, all other field types have static sizes. Signed-off-by: Philippe Proulx --- barectf/config.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/barectf/config.py b/barectf/config.py index 1920c87..6772de9 100644 --- a/barectf/config.py +++ b/barectf/config.py @@ -43,6 +43,10 @@ class _FieldType: def alignment(self) -> Alignment: raise NotImplementedError + @property + def size_is_dynamic(self): + return False + class _BitArrayFieldType(_FieldType): def __init__(self, size: Count, byte_order: Optional[ByteOrder] = None, @@ -193,6 +197,10 @@ class StringFieldType(_FieldType): def alignment(self) -> Alignment: return Alignment(8) + @property + def size_is_dynamic(self): + return True + class _ArrayFieldType(_FieldType): def __init__(self, element_field_type: _FieldType): @@ -273,6 +281,10 @@ class StructureFieldType(_FieldType): def alignment(self) -> Alignment: return self._alignment + @property + def size_is_dynamic(self): + return any([member.field_type.size_is_dynamic for member in self.members.values()]) + @property def members(self) -> StructureFieldTypeMembers: return self._members -- 2.34.1