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

### RosCdrCodecDecodeError

```python
exception roboto.formats.mcap.ros_cdr_decoder_factory.RosCdrCodecDecodeError
```

`from roboto.formats.mcap.ros_cdr_decoder_factory import RosCdrCodecDecodeError`

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

Bases: `mcap.exceptions.McapError`

A ROS 1 or CDR message could not be decoded.

Raised by the decoders that `RosCdrCodecDecoderFactory.decoder_for` returns, for any failure other than a field the decoder does not support, which skips the message instead. It surfaces from [`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) when the reader reaches the message.

### RosCdrCodecDecoderFactory

```python
class roboto.formats.mcap.ros_cdr_decoder_factory.RosCdrCodecDecoderFactory
```

`from roboto.formats.mcap.ros_cdr_decoder_factory import RosCdrCodecDecoderFactory`

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

Bases: `mcap.decoder.DecoderFactory`

Decoder factory that decodes ROS 1 and CDR messages in MCAP files.

It decodes channels whose message encoding is `cdr` and whose schema encoding is `ros2msg`, `ros2idl`, or `omgidl`, and channels whose message encoding is `ros1` and whose schema encoding is `ros1msg`. Pass an instance to `mcap.reader.make_reader` in its `decoder_factories`. Decoding runs in the Rust `mcap_codec` extension, from the `roboto-mcap-codec` package, which parses each schema once.

Each message decodes to a `dict` keyed by member name, with values shaped as follows:

- Numeric arrays and sequences, `uint8` and octet sequences included: `array.array`.
- Sequences of structs or of sequences, and the outer dimension of a multidimensional array: `list`.
- Enums: `int`.
- Unions: `{"$discriminator": <discriminator>, <active member>: <value>}`.
- `Time` and `Duration`: a `dict` with the schema's own member names, `sec` and `nanosec` in ROS 2 and `sec` and `nsec` in ROS 1.
- An absent `@optional` member: left out of the `dict`.

`array.array` is not JSON-serializable; convert one with its `tolist()` method before serializing. JSON channels decode through [`JsonDecoderFactory`](/docs/reference/python-sdk/roboto/formats/mcap/json_decoder_factory#roboto.formats.mcap.json_decoder_factory.JsonDecoderFactory) instead, which returns what `json.loads` does: `None` for null fields, plain lists, and integers of any size.

A message the decoder cannot decode because of its schema, such as a `wstring` member in a plain CDR struct or a struct marked `@autoid(HASH)`, decodes to `UNDECODABLE_MESSAGE`, as does every message on a channel whose schema cannot be parsed.

#### RosCdrCodecDecoderFactory.decoder_for()

```python
def decoder_for(
    message_encoding: str,
    schema: Optional[mcap.records.Schema],
) -> Optional[Callable[[bytes], Any]]
```

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

Return the decoder for a channel's messages, or `None` if this factory does not decode them.

The `mcap` reader calls this for each channel it reads. A channel whose pair of message and schema encodings this class does not decode returns `None`, so that another factory can decode it. The decoder is built on the first call for a schema ID and reused afterward.

**Parameters**

- **message_encoding** (`str`): Message encoding of the channel, such as `cdr` or `ros1`.
- **schema** (`Optional[mcap.records.Schema]`): Schema of the channel. `None` returns `None`.

**Returns**

- `Optional[Callable[[bytes], Any]]`: Function that decodes one message's bytes, and returns the decoded `dict` or `UNDECODABLE_MESSAGE`.

**Raises**

- [`RosCdrCodecDecodeError`](/docs/reference/python-sdk/roboto/formats/mcap/ros_cdr_decoder_factory#roboto.formats.mcap.ros_cdr_decoder_factory.RosCdrCodecDecodeError): The message cannot be decoded for a reason other than a field the decoder does not support. Raised when the returned function is called.

### UNDECODABLE_MESSAGE

```python
roboto.formats.mcap.ros_cdr_decoder_factory.UNDECODABLE_MESSAGE
```

`from roboto.formats.mcap.ros_cdr_decoder_factory import UNDECODABLE_MESSAGE`

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

Value a decoder returns in place of a message it cannot decode, so that reading continues with the next message.

[`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) skips every message that decodes to it. The ROS 1, CDR, and msgpack decoders return it for a message whose schema has a field they do not support, and for every message on a channel whose schema they cannot parse.

### make_ros_cdr_codec_decoder_factory()

```python
def roboto.formats.mcap.ros_cdr_decoder_factory.make_ros_cdr_codec_decoder_factory() -> RosCdrCodecDecoderFactory
```

`from roboto.formats.mcap.ros_cdr_decoder_factory import make_ros_cdr_codec_decoder_factory`

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

Build a decoder factory for ROS 1 and CDR messages, as `RosCdrCodecDecoderFactory` describes.

[`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) decodes ROS 1 and CDR channels through it, so most code never calls it.

**Returns**

- `RosCdrCodecDecoderFactory`
