+ @property
+ def scope(self):
+ """
+ Return the FieldDeclaration's scope.
+ """
+ return self._s
+
+class IntegerFieldDeclaration(FieldDeclaration):
+ """Do not instantiate."""
+ def __init__(self):
+ raise NotImplementedError("IntegerFieldDeclaration cannot be instantiated")
+
+ @property
+ def signedness(self):
+ """
+ Return the signedness of an integer:
+ 0 if unsigned; 1 if signed; -1 on error.
+ """
+ return _bt_ctf_get_int_signedness(self._fd)
+
+ @property
+ def base(self):
+ """Return the base of an int or a negative value on error."""
+ return _bt_ctf_get_int_base(self._fd)
+
+ @property
+ def byte_order(self):
+ """
+ Return the byte order. One of class ByteOrder's entries.
+ """
+ ret = _bt_ctf_get_int_byte_order(self._fd)
+ if ret == 1234:
+ return ByteOrder.BYTE_ORDER_LITTLE_ENDIAN
+ elif ret == 4321:
+ return ByteOrder.BYTE_ORDER_BIG_ENDIAN
+ else:
+ return ByteOrder.BYTE_ORDER_UNKNOWN
+
+ @property
+ def length(self):
+ """
+ Return the size, in bits, of an int or a negative
+ value on error.
+ """
+ return _bt_ctf_get_int_len(self._fd)
+
+ @property
+ def encoding(self):
+ """
+ Return the encoding. One of class CTFStringEncoding's entries.
+ Return a negative value on error.
+ """
+ return _bt_ctf_get_encoding(self._fd)
+
+class EnumerationFieldDeclaration(FieldDeclaration):
+ """Do not instantiate."""
+ def __init__(self):
+ raise NotImplementedError("EnumerationFieldDeclaration cannot be instantiated")
+
+class ArrayFieldDeclaration(FieldDeclaration):
+ """Do not instantiate."""
+ def __init__(self):
+ raise NotImplementedError("ArrayFieldDeclaration cannot be instantiated")
+
+ @property
+ def length(self):
+ """
+ Return the length of an array or a negative
+ value on error.
+ """
+ return _bt_ctf_get_array_len(self._fd)
+
+ @property
+ def element_declaration(self):
+ """
+ Return element declaration.
+ """
+ field_decl_ptr = _bt_python_get_array_element_declaration(self._fd)
+ return _create_field_declaration(field_decl_ptr, "", self.scope)
+
+class SequenceFieldDeclaration(FieldDeclaration):
+ """Do not instantiate."""
+ def __init__(self):
+ raise NotImplementedError("SequenceFieldDeclaration cannot be instantiated")
+
+ @property
+ def element_declaration(self):
+ """
+ Return element declaration.
+ """
+ field_decl_ptr = _bt_python_get_sequence_element_declaration(self._fd)
+ return _create_field_declaration(field_decl_ptr, "", self.scope)
+
+class FloatFieldDeclaration(FieldDeclaration):
+ """Do not instantiate."""
+ def __init__(self):
+ raise NotImplementedError("FloatFieldDeclaration cannot be instantiated")
+
+class StructureFieldDeclaration(FieldDeclaration):
+ """Do not instantiate."""
+ def __init__(self):
+ raise NotImplementedError("StructureFieldDeclaration cannot be instantiated")
+
+class StringFieldDeclaration(FieldDeclaration):
+ """Do not instantiate."""
+ def __init__(self):
+ raise NotImplementedError("StringFieldDeclaration cannot be instantiated")
+
+class VariantFieldDeclaration(FieldDeclaration):
+ """Do not instantiate."""
+ def __init__(self):
+ raise NotImplementedError("VariantFieldDeclaration cannot be instantiated")
+
+def field_error():
+ """
+ Return the last error code encountered while
+ accessing a field and reset the error flag.
+ Return 0 if no error, a negative value otherwise.
+ """
+ return _bt_ctf_field_get_error()
+
+def _create_field_declaration(declaration_ptr, name, scope):
+ """
+ Private field declaration factory.
+ """
+ if declaration_ptr is None:
+ raise ValueError("declaration_ptr must be valid")
+ if not scope in _scopes:
+ raise ValueError("Invalid scope provided")
+
+ type = _bt_ctf_field_type(declaration_ptr)
+ declaration = None
+ if type == CTFTypeId.INTEGER:
+ declaration = IntegerFieldDeclaration.__new__(IntegerFieldDeclaration)
+ elif type == CTFTypeId.ENUM:
+ declaration = EnumerationFieldDeclaration.__new__(EnumerationFieldDeclaration)
+ elif type == CTFTypeId.ARRAY:
+ declaration = ArrayFieldDeclaration.__new__(ArrayFieldDeclaration)
+ elif type == CTFTypeId.SEQUENCE:
+ declaration = SequenceFieldDeclaration.__new__(SequenceFieldDeclaration)
+ elif type == CTFTypeId.FLOAT:
+ declaration = FloatFieldDeclaration.__new__(FloatFieldDeclaration)
+ elif type == CTFTypeId.STRUCT:
+ declaration = StructureFieldDeclaration.__new__(StructureFieldDeclaration)
+ elif type == CTFTypeId.STRING:
+ declaration = StringFieldDeclaration.__new__(StringFieldDeclaration)
+ elif type == CTFTypeId.VARIANT:
+ declaration = VariantFieldDeclaration.__new__(VariantFieldDeclaration)
+ else:
+ return declaration
+
+ declaration._fd = declaration_ptr
+ declaration._s = scope
+ declaration._name = name
+ return declaration
+
+class _Definition(object):
+ def __init__(self, definition_ptr, scope):
+ self._d = definition_ptr
+ self._s = scope
+ if not scope in _scopes:
+ ValueError("Invalid scope provided")
+
+ @property
+ def name(self):
+ """Return the name of a field or None on error."""
+ return _bt_ctf_field_name(self._d)
+
+ @property
+ def type(self):
+ """Return the type of a field or -1 if unknown."""
+ return _bt_ctf_field_type(_bt_ctf_get_decl_from_def(self._d))
+
+ @property
+ def declaration(self):
+ """Return the associated Definition object."""
+ return _create_field_declaration(_bt_ctf_get_decl_from_def(self._d), self.name, self.scope)
+
+ def _get_enum_str(self):