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

### Accessor

```python
roboto.formats.mcap.accessor.Accessor
```

`from roboto.formats.mcap import Accessor`

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

Function that copies one field's value from a decoded message into an `Accumulator`, and returns `None`.

`compile_accessors` builds one per field from a sample message. Building it finds, from the sample, where the field's path crosses a sequence and which `nsec` components to read as `nanosec`, so a call does only dictionary lookups and writes. A message that lacks the field leaves it unwritten.

### AccessorCache

```python
class roboto.formats.mcap.accessor.AccessorCache
```

`from roboto.formats.mcap.accessor import AccessorCache`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L141-L178)

Cache of the accessors compiled for one read of an MCAP file, keyed by the paths of the fields they read.

Each [`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) holds one and passes it to every [`DecodedMessage`](/docs/reference/python-sdk/roboto/formats/mcap/decoded_message#roboto.formats.mcap.decoded_message.DecodedMessage) it returns, so accessors are compiled once per read rather than once per message. Each reader has its own cache because accessors compiled against one topic's messages can be wrong for another topic with the same paths, such as when a time field is present in one and absent in the other.

#### AccessorCache.get_or_compile()

```python
def get_or_compile(
    fields: collections.abc.Sequence[FieldSelection],
    sample: Any,
    getter: AttrGetter,
) -> list[Accessor]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L154-L178)

Return the accessors for `fields`, compiling them against `sample` when the cache has none.

Accessors compiled against a sample in which a path crosses an empty sequence are returned but not cached: the sample shows nothing past the empty sequence, so a later message whose sequence has elements compiles them again.

**Parameters**

- **fields** (`collections.abc.Sequence[FieldSelection]`): Fields to read. The accessors come back in the same order.
- **sample** (`Any`): Decoded message to compile against.
- **getter** (`AttrGetter`): Attribute reader for `sample`.

**Returns**

- `list[Accessor]`

### Accumulator

```python
roboto.formats.mcap.accessor.Accumulator
```

`from roboto.formats.mcap.accessor import Accumulator`

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

Dictionary that accessors write selected fields into, nested the way the message is.

### AttrGetter

```python
class roboto.formats.mcap.accessor.AttrGetter
```

`from roboto.formats.mcap.accessor import AttrGetter`

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

Bases: `abc.ABC`

Attribute reader for decoded MCAP messages, which accessors use to walk a message along a field's path.

The SDK's own code uses it; to read selected fields from an MCAP file, use [`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) instead. Every decoder the SDK uses returns messages as dictionaries, so `DictAttrGetter` is the only implementation.

#### AttrGetter.get_attribute()

```python
@staticmethod
@abstractmethod
def get_attribute(value, attribute) -> Any
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L52-L60)

Return the value of `attribute` in `value`.

Call it only after `has_attribute` returns `True` for the same arguments.

**Parameters**

- **value**: Decoded message, or a value within one.
- **attribute**: Name of the attribute to read.

**Returns**

- `Any`

#### AttrGetter.get_attribute_names()

```python
@staticmethod
@abstractmethod
def get_attribute_names(value) -> collections.abc.Sequence[str]
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L43-L48)

Return the names of the attributes `value` holds.

**Parameters**

- **value**: Decoded message, or a value within one.

**Returns**

- `collections.abc.Sequence[str]`

#### AttrGetter.has_attribute()

```python
@staticmethod
@abstractmethod
def has_attribute(value, attribute: str) -> bool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L64-L73)

Return whether `value` holds `attribute`.

Returns `False`, rather than raising, when `value` cannot hold attributes, such as a JSON `null`, a scalar, or a list, so a walk along a path stops there.

**Parameters**

- **value**: Decoded message, or a value within one.
- **attribute** (`str`): Name of the attribute to look for.

**Returns**

- `bool`

#### AttrGetter.has_sub_attributes()

```python
@staticmethod
@abstractmethod
def has_sub_attributes(value) -> bool
```

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

Return whether `value` can hold attributes, so a walk along a path can continue into it.

**Parameters**

- **value**: Decoded message, or a value within one.

**Returns**

- `bool`

### DictAttrGetter

```python
class roboto.formats.mcap.accessor.DictAttrGetter
```

`from roboto.formats.mcap.accessor import DictAttrGetter`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L85-L106)

Bases: [`AttrGetter`](/docs/reference/python-sdk/roboto/formats/mcap/accessor#roboto.formats.mcap.accessor.AttrGetter)

Attribute reader that reads decoded messages held as dictionaries.

The JSON, msgpack and ROS decoders return messages, and the structures nested in them, as dictionaries. Any value that is not a dictionary has no attributes.

#### DictAttrGetter.get_attribute()

```python
@staticmethod
def get_attribute(value, attribute)
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L97-L98)

Return the value of `attribute` in `value`.

Call it only after `has_attribute` returns `True` for the same arguments.

**Parameters**

- **value**: Decoded message, or a value within one.
- **attribute**: Name of the attribute to read.

#### DictAttrGetter.get_attribute_names()

```python
@staticmethod
def get_attribute_names(value)
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L93-L94)

Return the names of the attributes `value` holds.

**Parameters**

- **value**: Decoded message, or a value within one.

#### DictAttrGetter.has_attribute()

```python
@staticmethod
def has_attribute(value, attribute: str) -> bool
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L101-L102)

Return whether `value` holds `attribute`.

Returns `False`, rather than raising, when `value` cannot hold attributes, such as a JSON `null`, a scalar, or a list, so a walk along a path stops there.

**Parameters**

- **value**: Decoded message, or a value within one.
- **attribute** (`str`): Name of the attribute to look for.

**Returns**

- `bool`

#### DictAttrGetter.has_sub_attributes()

```python
@staticmethod
def has_sub_attributes(value)
```

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L105-L106)

Return whether `value` can hold attributes, so a walk along a path can continue into it.

**Parameters**

- **value**: Decoded message, or a value within one.

### PathInSchema

```python
roboto.formats.mcap.accessor.PathInSchema
```

`from roboto.formats.mcap.accessor import PathInSchema`

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

Path of one field through a message's schema, such as `("header", "stamp", "sec")`.

### Resolution

```python
roboto.formats.mcap.accessor.Resolution
```

`from roboto.formats.mcap import Resolution`

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

Compiled form of one field's path: one that writes nothing, a chain of dictionary keys, or a sequence crossing.

A sequence crossing applies a further resolution to each element of the sequence. Build one with `none_resolution`, `simple_resolution` or `sequence_resolution`, and turn it into an accessor with `build_accessor`.

### build_accessor()

```python
def roboto.formats.mcap.accessor.build_accessor(resolution: Resolution) -> Accessor
```

`from roboto.formats.mcap import build_accessor`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L405-L421)

Build the accessor that reads the path `resolution` describes.

It reads no message, so a resolution built from a schema can be turned into an accessor before any message is read. The accessor writes the field into the accumulator as [`to_dict()`](/docs/reference/python-sdk/roboto/formats/mcap/decoded_message#roboto.formats.mcap.decoded_message.DecodedMessage.to_dict) describes.

**Parameters**

- **resolution** (`Resolution`): Resolution to build from, such as one `remap_time_fields` returns.

**Returns**

- `Accessor`

### compile_accessors()

```python
def roboto.formats.mcap.accessor.compile_accessors(
    fields: collections.abc.Sequence[FieldSelection],
    sample: Any,
    getter: AttrGetter,
) -> tuple[list[Accessor], bool]
```

`from roboto.formats.mcap import compile_accessors`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L181-L209)

Build one accessor per field, compiled against `sample`, without caching them.

[`to_dict()`](/docs/reference/python-sdk/roboto/formats/mcap/decoded_message#roboto.formats.mcap.decoded_message.DecodedMessage.to_dict) builds a message's accessors through it, directly or through `AccessorCache.get_or_compile`, which caches them, so most code never calls it.

**Parameters**

- **fields** (`collections.abc.Sequence[FieldSelection]`): Fields to read.
- **sample** (`Any`): Decoded message to compile against.
- **getter** (`AttrGetter`): Attribute reader for `sample`.

**Returns**

- `tuple[list[Accessor], bool]`: `(accessors, fully_resolved)`: one accessor per field, in the order of `fields`, and whether `sample` showed every path in full. `fully_resolved` is `False` when a path crosses a sequence that is empty in `sample`; the accessor then reads the rest of that path as a chain of dictionary keys, which a later message may not match, so do not reuse those accessors for later messages.

### getter_for()

```python
def roboto.formats.mcap.accessor.getter_for(message: Any) -> AttrGetter
```

`from roboto.formats.mcap import getter_for`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L113-L123)

Return the attribute reader for `message`.

[`to_dict()`](/docs/reference/python-sdk/roboto/formats/mcap/decoded_message#roboto.formats.mcap.decoded_message.DecodedMessage.to_dict) finds each message's attribute reader through it, so most code never calls it. Every decoder returns messages as dictionaries, and `DictAttrGetter` treats any other value as having no attributes, so this returns the same `DictAttrGetter` for every message.

**Parameters**

- **message** (`Any`): Decoded message to read.

**Returns**

- `AttrGetter`

### is_codec_time_value()

```python
def roboto.formats.mcap.accessor.is_codec_time_value(val: Any) -> bool
```

`from roboto.formats.mcap.accessor import is_codec_time_value`

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

Return whether `val` is a ROS 2 `Time` or `Duration` value, as the SDK's ROS decoder returns it.

[`to_dict()`](/docs/reference/python-sdk/roboto/formats/mcap/decoded_message#roboto.formats.mcap.decoded_message.DecodedMessage.to_dict) recognizes these values through it, so most code never calls it. The decoder returns such a value as a dictionary with exactly the keys `sec` and `nanosec` and nothing else marking it as a time, so the check compares keys. Some topics' message paths name the sub-second field `nsec`; recognizing the value lets the SDK read `nanosec` for such a path, which would otherwise read nothing. ROS 1 `Time` values and JSON time values use the key `nsec`, so they do not match and need no renaming.

**Parameters**

- **val** (`Any`): Decoded value to test.

**Returns**

- `bool`

### none_resolution()

```python
def roboto.formats.mcap.accessor.none_resolution() -> Resolution
```

`from roboto.formats.mcap import none_resolution`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L244-L246)

Build a resolution whose accessor writes nothing, for a path the message lacks.

**Returns**

- `Resolution`

### remap_time_fields()

```python
def roboto.formats.mcap.accessor.remap_time_fields(
    resolution: Resolution,
    sample: Any,
    getter: AttrGetter,
) -> tuple[Resolution, bool]
```

`from roboto.formats.mcap import remap_time_fields`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L268-L297)

Return `resolution` with `nsec` renamed to `nanosec` past each ROS 2 time value on its path in `sample`.

Some topics' message paths name the sub-second field of a ROS 2 `Time` or `Duration` value `nsec`, but the SDK's ROS decoder returns it under `nanosec`. This walks `sample` along `resolution` and renames every `nsec` component that follows such a value, so the accessor `build_accessor` builds from the result reads the key the message has. Paths that already name the field `nanosec` are returned unchanged, as are ROS 1 and JSON time values, which use `nsec`.

**Parameters**

- **resolution** (`Resolution`): Resolution to rename components in.
- **sample** (`Any`): Decoded message to walk.
- **getter** (`AttrGetter`): Attribute reader for `sample`.

**Returns**

- `tuple[Resolution, bool]`: `(remapped, time_resolved)`: `resolution` with those components renamed, and whether `sample` showed which components to rename. `time_resolved` is `False` when the path past a sequence has a `sec` or `nsec` component and the sequence is missing, empty or not a sequence in `sample`: no element shows whether to rename, so check the resolution again against a later message. It is `True` otherwise, including for a resolution with no time component.

### sequence_resolution()

```python
def roboto.formats.mcap.accessor.sequence_resolution(
    pre_path: collections.abc.Sequence[str],
    sub: Resolution,
) -> Resolution
```

`from roboto.formats.mcap import sequence_resolution`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L258-L265)

Build a resolution that crosses the sequence at `pre_path` and applies `sub` to each element.

**Parameters**

- **pre_path** (`collections.abc.Sequence[str]`): Keys from the top of the message to the sequence.
- **sub** (`Resolution`): Resolution of the rest of the path, from each element of the sequence.

**Returns**

- `Resolution`

### simple_resolution()

```python
def roboto.formats.mcap.accessor.simple_resolution(
    path: collections.abc.Sequence[str],
) -> Resolution
```

`from roboto.formats.mcap import simple_resolution`

[Source](https://github.com/roboto-ai/roboto-python-sdk/blob/main/src/roboto/formats/mcap/accessor.py#L249-L255)

Build a resolution that reads `path` as a chain of dictionary keys, crossing no sequence.

**Parameters**

- **path** (`collections.abc.Sequence[str]`): Keys from the top of the message to the field.

**Returns**

- `Resolution`
