zserio.typeinfo module¶
The module contains classes for type info.
- class zserio.typeinfo.CaseInfo(case_expressions: List[Any], field: MemberInfo | None)[source]¶
Bases:
object
Case info class which provides information about choice cases in generated choices.
Constructor.
- Parameters:
case_expressions – List of case expression in the choice case. When empty, it’s a default case.
field – Field associated with the choice case, can be empty.
- property case_expressions: List[Any]¶
Gets case expressions in the choice case. An empty list denotes the default case.
- Returns:
List of case expressions as evaluated constant values.
- property field: MemberInfo | None¶
Gets field associated with the choice case. Can be empty.
- Returns:
Field MemberInfo.
- class zserio.typeinfo.ItemInfo(schema_name: str, py_item: Any, is_deprecated: bool, is_removed: bool)[source]¶
Bases:
object
Item info class which provides information about items of generated enumerable types.
Constructor.
- Parameters:
schema_name – Name of the item as is defined in Zserio schema.
py_item – Reference to the generated item.
- property is_deprecated: bool¶
Gets flag whether the item is deprecated.
- Returns:
True when the item is deprecated, false otherwise.
- property is_removed: bool¶
Gets flag whether the item is removed.
- Returns:
True when the item is removed, false otherwise.
- property py_item: Any¶
Gets reference to the item generated in Python.
- Returns:
Python item.
- property schema_name: str¶
Gets name of the item as is defined in Zserio schema.
- Returns:
Item name in Zserio schema.
- class zserio.typeinfo.MemberAttribute(value)[source]¶
Bases:
Enum
Member attribute type to be used in MemberInfo.
Determines type of the second element in the attribute tuple returned in attributes list from MemberInfo.
- ALIGN = 4¶
- ARRAY_LENGTH = 13¶
- CLIENT_METHOD_NAME = 22¶
- CONSTRAINT = 10¶
- EXTENDED = 3¶
- FUNCTION_NAME = 11¶
- FUNCTION_RESULT = 12¶
- IMPLICIT = 14¶
- INITIALIZER = 6¶
- IS_SET_INDICATOR_NAME = 9¶
- IS_USED_INDICATOR_NAME = 8¶
- OFFSET = 5¶
- OPTIONAL = 7¶
- PACKED = 15¶
- PROPERTY_NAME = 1¶
- PUBLISH = 20¶
- REQUEST_TYPE = 23¶
- SQL_CONSTRAINT = 17¶
- SQL_TYPE_NAME = 16¶
- SUBSCRIBE = 21¶
- TOPIC = 19¶
- TYPE_ARGUMENTS = 2¶
- VIRTUAL = 18¶
- class zserio.typeinfo.MemberInfo(schema_name: str, typeinfo: TypeInfo | RecursiveTypeInfo, *, attributes: Dict[MemberAttribute, Any] | None = None)[source]¶
Bases:
object
Member info class which provides information about members of compound types.
Member info constructor.
- Parameters:
schema_name – Name of the member as is defined in Zserio schema.
type_info – Type info of the member.
attributes – List of member attributes.
- property attributes: Dict[MemberAttribute, Any]¶
Gets dictionary with member attributes.
Attribute is a an arbitrary value which type is given by the key, which is MemberAttribute enumeration. All expressions are stored as strings.
Possible attributes:
(MemberAttribute.PROPERTY_NAME, 'field1')
contains name of the property generated in Python
(MemberAttribute.TYPE_ARGUMENTS, [(lambda self, zserio_index: self.field1), ...])
for compound type members, keeps type arguments for parameterized types or dynamic bit fields, the value contains list of lambda functions evaluating particular arguments expression, where the lambdas take parent and an element index (which can be None if not used) as arguments
for members of sql tables, keeps type arguments for columns, the value contains list of lambdas where the lambdas take either single explicit parameter argument for explicit parameters or single ‘self’ argument, which is an object providing property-like getters for column names used in expressions
(MemberAttribute.EXTENDED, None)
denotes that the member field is extended, the value is always None
(MemberAttribute.ALIGN, lambda: 8)
denotes that the member field has an alignment, the value is a lambda function which returns the alignment constant value
(MemberAttribute.OFFSET, lambda self: self.offset_field)
denotes that the member field has an offset, the value contains the offset expression as a lambda function taking single parent argument
(MemberAttribute.INITIALIZER, lambda: 10)
denotes that the member field has an initializer, the value is a lambda function which returns the the initializer constant value
(MemberAttribute.OPTIONAL, None)
,(MemberAttribute.OPTIONAL, lambda self: self.field1 != 0)
denotes that the member is an optional, when the value is None, then it’s an auto optional, otherwise it contains the optional clause as a lambda function taking single parent argument
(MemberAttribute.IS_USED_INDICATOR_NAME, 'is_field_used)
if the member is an optional, the value contains the “is_used” indicator name generated in Python
(MemberAttribute.IS_SET_INDICATOR_NAME, 'is_field_set)
if the member is an optional, the value contains the “is_set” indicator name generated in Python
(MemberAttribute.CONSTRAINT, lambda self: field > 10)
denotes that the member has a constraint, the value contains the constraint expression as a lambda function taking single parent argument
(MemberAttribute.FUNCTION_NAME, 'function_name')
keeps the generated function name
MemberAttribute.FUNCTION_RESULT, lambda self: self.field1 + 5)
keeps the result expression of a function as a lambda function taking single parent argument
(MemberAttribute.ARRAY_LENGTH, None)
,(MemberAttribute.ARRAY_LENGTH, lambda self: self.field1 + 1)
denotes that the member is an array, when the value is None, then it’s an auto array, otherwise it contains the length expression as a lambda function taking single parent argument
(MemberAttribute.IMPLICIT, None)
denotes that the member is an implicit array, the value is always None
(MemberAttribute.PACKED, None)
denotes that the member is a packed array, the value is always None
(MemberAttribute.SQL_TYPE_NAME, 'INTEGER')
keeps SQLite type name used for this column
(MemberAttribute.SQL_CONSTRAINT, 'PRIMARY KEY NOT NULL')
denotes that the member has a SQL constraint
(MemberAttribute.VIRTUAL, None)
denotes that the column in a SQL table is virtual
(MemberAttribute.TOPIC, 'topic/definition')
keeps the topic definition of a pub-sub message
(MemberAttribute.PUBLISH, 'publish_message_name')
denotes that the pub-sub message is published, the value contains the publishing method name
(MemberAttribute.SUBSCRIBE, 'subscribe_message_name')
denotes that the pub-sub message is subscribed, the value contains the subscribing method name
(MemberAttribute.CLIENT_METHOD_NAME, 'client_method_name')
keeps the name of the method in the generated Client class
(MemberAttribute.REQUEST_TYPE, request_type.type_info())
keeps the request type TypeInfo, note that response type is in the method TypeInfo
- Returns:
Member attributes.
- property schema_name: str¶
Gets name of the member as is defined in Zserio schema.
- Returns:
Member name in Zserio schema.
- property type_info: TypeInfo | RecursiveTypeInfo¶
Gets type info of this member.
- Returns:
Type info.
- class zserio.typeinfo.RecursiveTypeInfo(type_info_func: Callable[[], TypeInfo])[source]¶
Bases:
object
Type info for recursive types used as a wrapper around generated static type_info method to prevent infinite recursion in type info definition.
Constructor.
- Parameters:
type_info_func – Generated static type_info method to wrap.
- property attributes: Dict[TypeAttribute, Any]¶
See
TypeInfo.attributes
.
- property py_type: Type¶
See
TypeInfo.py_type
.
- property schema_name: str¶
See
TypeInfo.schema_name
.
- class zserio.typeinfo.TypeAttribute(value)[source]¶
Bases:
Enum
Type attribute type to be used in TypeInfo.
Determines type of the second element in the attribute tuple returned in attributes list from TypeInfo.
- BITMASK_VALUES = 4¶
- CASES = 9¶
- COLUMNS = 12¶
- ENUM_ITEMS = 3¶
- FIELDS = 5¶
- FUNCTIONS = 7¶
- MESSAGES = 17¶
- METHODS = 18¶
- PARAMETERS = 6¶
- SELECTOR = 8¶
- SQL_CONSTRAINT = 14¶
- TABLES = 13¶
- TEMPLATE_ARGUMENTS = 11¶
- TEMPLATE_NAME = 10¶
- UNDERLYING_TYPE = 1¶
- UNDERLYING_TYPE_ARGUMENTS = 2¶
- VIRTUAL_TABLE_USING = 15¶
- WITHOUT_ROWID = 16¶
- class zserio.typeinfo.TypeInfo(schema_name: str, py_type: Type, *, attributes: Dict[TypeAttribute, Any] | None = None)[source]¶
Bases:
object
Type info class which provides information about generated types.
Type info constructor.
- Parameters:
schema_name – Zserio schema full type name.
py_type – Reference to the generated type.
attributes – List of type attributes.
- property attributes: Dict[TypeAttribute, Any]¶
Gets dictionary with type attributes.
Attribute is a an arbitrary value which type is given by the key, which is TypeAttribute enumeration.
(TypeAttribute.UNDERLYING_TYPE, TypeInfo(...))
denotes that the type has an underlying type (e.g. enum or bitmask), the value is a TypeInfo of the underlying type
(TypeAttribute.UNDERLYING_TYPE_ARGUMENTS, [lambda: 5])
keeps type arguments of the underlying type when it is a dynamic bit field, the value is a lambda function which returns the argument constant value
(TypeAttribute.ENUM_ITEMS, [ItemInfo(...), ItemInfo(...), ...])
denotes that the type is an enumeration, the value contains list of enum items ItemInfo
(TypeAttribute.BITMASK_VALUES, [ItemInfo(...), ItemInfo(...), ...])
denotes that the type is a bitmask, the value contains list of bitmask values ItemInfo
(TypeAttribute.FIELDS, [MemberInfo(...), MemberInfo(...), ...])
denotes that the type is a compound type, the value contains list of fields MemberInfo, the attribute is present even for empty compounds and then it contains the empty list
(TypeAttribute.PARAMETERS, [MemberInfo(...), MemberInfo(...), ...])
denotes that the compound type is parameterized type, the value contains non-empty list of parameters MemberInfo, for non-parameterized types the attribute is not present
(TypeAttribute.FUNCTIONS, [MemberInfo(...), MemberInfo(...), ...])
denotes that the compound type has functions, the value contains non-empty list of functions MemberInfo, for compounds without functions the attribute is not present
(TypeAttribute.SELECTOR, None
)(TypeAttribute.SELECTOR, lambda self: self.param1)
denotes that the type is either a union (when the value is None) or choice when the value contains the selector expression as a lambda function taking single parent argument
(TypeAttribute.CASES, [CaseInfo(...), CaseInfo(...), ...])
denotes that the type is a choice, the value contains list of CaseInfo for each choice case
note that the TypeAttribute.FIELDS attribute is present also in choices
(TypeAttribute.TEMPLATE_NAME, 'TemplatedStructure')
denotes that the type is a template instantiation, the value contains the template name
(TypeAttribute.TEMPLATE_ARGUMENTS, [test.TemplateArg.type_info(), ...])
present when the type is a template instantiation, the value contains list of template arguments TypeInfo
(TypeAttribute.COLUMNS, [MemberInfo(...), MemberInfo(...), ...])
denotes that the type is a SQL table, the value contains list of columns MemberInfo
(TypeAttribute.TABLES, [MemberInfo(...), MemberInfo(...), ...])
denotes that the type is a SQL database, the value contain list of tables MemberInfo
(TypeAttribute.SQL_CONSTRAINT, 'PRIMARY KEY(columnA)')
denotes that the SQL table contains a SQL constraint
(TypeAttribute.VIRTUAL_TABLE_USING, 'fts4')
denotes that the SQL table is a virtual table, the value contains the used virtual table module
(TypeAttribute.WITHOUT_ROWID, None)
denotes that the SQL table is a WITHOUT ROWID table, the value is always None
(TypeAttribute.MESSAGES, [MemberInfo(...), MemberInfo(...), ...])
denotes that the type is a pub-sub, the value contains list of messages MemberInfo
(TypeAttribute.METHODS, [MemberInfo(...), MemberInfo(...), ...])
denotes that the type is a service, the value contains list of methods MemberInfo
:returns Type attributes.
- property py_type: Type¶
Gets Python type generated for this Zserio type.
- Returns:
Python type.
- property schema_name: str¶
Returns the full type name as is defined in Zserio schema.
- Returns:
Zserio schema full type name.