def get_type(self, type_name: str) -> interfaces.objects.Template: """Resolves a symbol name into an object template. This always construct a new python object, rather than using a cached value otherwise changes made later may affect the cached copy. Calling clone after every native type construction was extremely slow. """ # NOTE: These need updating whenever the object init signatures change prefix = "" if constants.BANG in type_name: name_split = type_name.split(constants.BANG) if len(name_split) > 2: raise ValueError( "SymbolName cannot contain multiple {} separators".format( constants.BANG)) table_name, type_name = name_split prefix = table_name + constants.BANG additional = {} # type: Dict[str, Any] obj = None # type: Optional[Type[interfaces.objects.ObjectInterface]] if type_name == 'void' or type_name == 'function': obj = objects.Void elif type_name == 'array': obj = objects.Array additional = {"count": 0, "subtype": self.get_type('void')} elif type_name == 'enum': obj = objects.Enumeration additional = {"base_type": self.get_type('void'), "choices": {}} elif type_name == 'bitfield': obj = objects.BitField additional = { "start_bit": 0, "end_bit": 0, "base_type": self.get_type('void') } elif type_name == 'string': obj = objects.String additional = {"max_length": 0} elif type_name == 'bytes': obj = objects.Bytes additional = {"length": 0} if obj is not None: return objects.templates.ObjectTemplate(obj, type_name=prefix + type_name, **additional) _native_type, native_format = self._native_dictionary[type_name] if type_name == 'pointer': additional = {'subtype': self.get_type('void')} return objects.templates.ObjectTemplate( self.get_type_class(type_name), # pylint: disable=W0142 type_name=prefix + type_name, data_format=objects.DataFormatInfo(*native_format), **additional)
def get_key(self) -> str: """Returns the Key value as a 4 character string""" tag_bytes = objects.convert_value_to_data( self.Key, int, objects.DataFormatInfo(4, "little", False)) return "".join([chr(x) if 32 < x < 127 else '' for x in tag_bytes])