Unmodeled Adapter
mosaicolabs.bridges.mcap.adapters.unmodeled ¶
UnmodeledAdapter ¶
Bases: MCAPAdapterBase[UnmodeledT, McapT], Generic[UnmodeledT, McapT]
Adapter for translating MCAP messages to Mosaico Unmodeled subclasses.
This is the only MCAP adapter provided by the library. MCAP is a container
format that can carry messages of any schema and encoding, so the structure
of a message cannot be known in advance and no dedicated adapters can be
shipped for it. Every MCAP message is therefore stored in Mosaico as an
Unmodeled payload, keeping its decoded content as raw data.
Rebuilding the original MCAP message from the data saved in Mosaico requires
the original object type to fill with that data, in the same way as the ROS
UnmodeledAdapter relies on a Typestore holding the original message
types. For this purpose, the adapter defines the __mcap_class__ class
variable, which holds the class used to reconstruct the original object. It
is set when each new UnmodeledAdapter is created.
from_dict
classmethod
¶
Converts the raw dictionary data into the specific Mosaico Unmodeled type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mcap_data
|
dict
|
The decoded MCAP message payload. It is updated in place with
the |
required |
publish_time_ns
|
int
|
Message publish time (nanoseconds). |
required |
Returns:
| Name | Type | Description |
|---|---|---|
UnmodeledT |
UnmodeledT
|
The constructed |
to_mcap
classmethod
¶
Rebuilds the native MCAP message from the raw_data of an Unmodeled instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaico_data
|
UnmodeledT
|
The |
required |
Returns:
| Type | Description |
|---|---|
Tuple[McapT, Optional[int]]
|
Tuple[McapT, Optional[int]]: The |
get_or_create
classmethod
¶
Gets or creates an unmodeled adapter for the provided schema name and schema encoding.
If an adapter for the pair is already registered it is returned immediately; otherwise a new subclass is created, registered and returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ontology_type
|
Type[UnmodeledT]
|
The |
required |
mcap_class
|
Type[McapT]
|
The native MCAP message class rebuilt by |
required |
schema_name
|
str
|
The MCAP schema name handled by the adapter. |
required |
schema_encoding
|
str
|
The MCAP schema encoding handled by the adapter. |
required |
Returns:
| Type | Description |
|---|---|
Type[UnmodeledAdapter]
|
Type[UnmodeledAdapter]: The registered adapter class. |
to_native
classmethod
¶
Converts a Mosaico message or ontology object into a serialized native MCAP message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaico_data
|
Union[Message, OntologyT]
|
A |
required |
**kwargs
|
Any
|
Extra arguments forwarded to
|
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
McapReturnType |
McapReturnType
|
The native MCAP message serialized according to |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
NotImplementedError
|
If |
translate
classmethod
¶
Translates a MCAP message instance into a Mosaico Message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
msg
|
MCAPMessage
|
The source container yielded by the MCAPLoader. |
required |
**kwargs
|
Any
|
Contextual data such as calibration parameters or frame overrides. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
Message |
Message
|
A Mosaico Message object containing the instantiated ontology data. |
Raises:
| Type | Description |
|---|---|
Exception
|
If translation fails due to missing fields, type mismatches, or other errors. |
unpack_mosaico_msg
classmethod
¶
Extracts the typed Mosaico payload and its Header (if present) from a wrapped or bare message.
Handles two input cases:
Messagewrapper: the typed data is extracted viaget_data().- Raw ontology instance: returned as-is.
In both cases the Header is extracted from the ontology (if supported), otherwise a
default Header (empty frame_id and zero Time) is returned.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mosaico_msg
|
Union[Message, T]
|
Either a |
required |
Returns:
| Type | Description |
|---|---|
T
|
tuple[T, Header]: A |
Header
|
header is the corresponding |
tuple[T, Header]
|
zero |
Raises:
| Type | Description |
|---|---|
TypeError
|
If mosaico_msg is neither a |
is_mcap_type_valid
classmethod
¶
Checks whether a given MCAP message type (schema_name, schema_encoding) is handled by this adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
encoding_to_validate
|
str
|
The full MCAP encoding string to check
(e.g., |
required |
schema_name_to_validate
|
str
|
The full MCAP schema name string to check
(e.g., |
required |
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
|
schema_metadata
classmethod
¶
Builds the MCAP-specific schema metadata for this adapter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
channel_name
|
str
|
The full name of the MCAP channel the adapter is associated to. |
required |
channel_encoding
|
str
|
The encoding of the MCAP channel the adapter is associated to. |
required |
schema_def
|
str
|
The string representation of the MCAP schema the adapter is
associated to, as produced by the resolved |
required |
Returns:
| Type | Description |
|---|---|
Optional[dict]
|
Optional[dict]: The schema metadata, wrapped under the
|
ontology_data_type
classmethod
¶
Returns the Ontology class type associated with this adapter.