---
sidebar:
  hidden: true
title: roboto.formats.mcap.decoded_message
---
## Module Contents

### DecodedMessage

```python
class roboto.formats.mcap.decoded_message.DecodedMessage(
    msg: Any,
    fields: collections.abc.Sequence[roboto.formats.fields.FieldSelection],
    accessor_cache: Optional[roboto.formats.mcap.accessor.AccessorCache] = None,
)
```

`from roboto.formats.mcap.decoded_message import DecodedMessage`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/decoded_message.py#L18-L110)

Message decoded from an MCAP file, which `to_dict` reduces to the fields a caller selected.

[`next()`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader.next) returns one for each message it reads. Import it from `roboto.formats.mcap.decoded_message`.

**Parameters**

- **msg** (`Any`): Decoded message, as nested dictionaries, sequences, and scalars. JSON, msgpack, ROS 1, ROS 2, and IDL messages all decode to this form.
- **fields** (`collections.abc.Sequence[roboto.formats.fields.FieldSelection]`): Fields `to_dict` returns.
- **accessor_cache** (`Optional[roboto.formats.mcap.accessor.AccessorCache]`): Cache that lets the messages of one read reuse the functions compiled to read each field, instead of compiling them for every message. [`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) passes one. `None` compiles them for this message alone.

#### DecodedMessage.is_path_match()

```python
@staticmethod
def is_path_match(attrib: str, field_path: str) -> bool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/decoded_message.py#L38-L70)

Return whether `attrib` is the same message path as `field_path` or one of its ancestors.

Both paths are dot-delimited, and they are compared component by component, so `"pose.pos"` is no ancestor of `"pose.position.x"`. A component that itself contains a dot cannot be told apart from two nested components.

**Parameters**

- **attrib** (`str`): Message path to test, such as `"pose.position"`.
- **field_path** (`str`): Message path of the selected field, such as `"pose.position.x"`.

**Returns**

- `bool`

**Usage**

```python
DecodedMessage.is_path_match("pose", "pose.position.x")
# True
DecodedMessage.is_path_match("pose.position", "pose.position.x")
# True
DecodedMessage.is_path_match("pose.position.x", "pose.position.x")
# True
DecodedMessage.is_path_match("pose.pos", "pose.position.x")
# False
DecodedMessage.is_path_match("velocity", "pose.position.x")
# False
```

#### DecodedMessage.to_dict()

```python
def to_dict() -> dict
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/decoded_message.py#L82-L110)

Return the message's selected fields as a dictionary nested the way the message is.

The dictionary holds only the fields given at construction:

- A field inside a sequence becomes a list holding one dictionary per element.
- A field the message lacks is left out, though dictionaries that enclose it may appear, empty.
- A path ending in `nsec` that reaches a ROS 2 `Time` or `Duration` value reads that value's `nanosec` key, and returns it under `nanosec`.

**Usage**

```python
from roboto.formats import FieldSelection
fields = [
    FieldSelection(path_in_schema=("pose", "position", "x")),
    FieldSelection(path_in_schema=("velocity",)),
]
message = {"pose": {"position": {"x": 1.5, "y": 0.2}}, "velocity": 2.0, "status": "ok"}
DecodedMessage(message, fields).to_dict()
# {'pose': {'position': {'x': 1.5}}, 'velocity': 2.0}
```

**Returns**

- `dict`
