MCPcopy Create free account
hub / github.com/FreeOpcUa/python-opcua / parse_struct

Method parse_struct

schemas/generate_model.py:362–406  ·  view source on GitHub ↗
(self, child)

Source from the content-addressed store, hash-verified

360 self.model.structs.append(obj)
361
362 def parse_struct(self, child):
363 tag = child.tag[40:]
364 struct = Struct()
365 for key, val in child.attrib.items():
366 if key == 'Name':
367 struct.name = val
368 elif key == 'BaseType':
369 if ':' in val:
370 prefix, val = val.split(':')
371 struct.basetype = val
372 tmp = struct
373 while tmp.basetype:
374 struct.parents.append(tmp.basetype)
375 tmp = self.model.get_struct(tmp.basetype)
376 else:
377 print(f'Error unknown key: {key}')
378 for el in child:
379 tag = el.tag[40:]
380 if tag == 'Field':
381 field = Field()
382 for key, val in el.attrib.items():
383 if key == 'Name':
384 field.name = val
385 elif key == 'TypeName':
386 field.uatype = val.split(':')[1]
387 elif key == 'LengthField':
388 field.length = val
389 elif key == 'SourceType':
390 field.sourcetype = val
391 elif key == 'SwitchField':
392 field.switchfield = val
393 elif key == 'SwitchValue':
394 field.switchvalue = val
395 elif key == 'Length':
396 field.bitlength = int(val)
397 else:
398 print(f'Unknown field item: {struct.name} {key}')
399
400 struct.fields.append(field)
401 elif tag == 'Documentation':
402 struct.doc = el.text
403 else:
404 print(f'Unknown tag: {tag}')
405
406 return struct
407
408 def parse_enum(self, child):
409 tag = child.tag[40:]

Callers 1

parseMethod · 0.95

Calls 3

StructClass · 0.70
FieldClass · 0.70
get_structMethod · 0.45

Tested by

no test coverage detected