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

### MsgpackDecodeError

```python
exception roboto.formats.mcap.msgpack_decoder_factory.MsgpackDecodeError
```

`from roboto.formats.mcap.msgpack_decoder_factory import MsgpackDecodeError`

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

Bases: `mcap.exceptions.McapError`

A msgpack-encoded MCAP message could not be decoded.

The function that `MsgpackDecoderFactory.decoder_for` returns raises it, so it surfaces while [`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) reads a msgpack channel. A message with a field the decoder does not support is skipped instead, and does not raise it.

### MsgpackDecoderFactory

```python
class roboto.formats.mcap.msgpack_decoder_factory.MsgpackDecoderFactory
```

`from roboto.formats.mcap.msgpack_decoder_factory import MsgpackDecoderFactory`

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

Bases: `mcap.decoder.DecoderFactory`

Decoder factory that decodes msgpack-encoded MCAP messages into nested dictionaries, lists, and scalar values.

[`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) decodes msgpack channels with it; to decode them with the `mcap` library directly, pass an instance to `mcap.reader.make_reader`. It decodes with the `roboto-mcap-codec` package, and parses each schema once, then reuses the result for every message on that schema.

It skips messages it cannot decode rather than stop the rest of the file being read: for each one, its decoder returns [`UNDECODABLE_MESSAGE`](/docs/reference/python-sdk/roboto/formats/mcap/ros_cdr_decoder_factory#roboto.formats.mcap.ros_cdr_decoder_factory.UNDECODABLE_MESSAGE), which [`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) passes over. It skips:

- Every message on a schema it cannot parse.
- Each message with a field the decoder does not support.

In both cases it logs one warning per schema.

> **Note**
>
> A field that msgpack-numpy encoded, a map with binary keys (`nd`, `type`, `shape`, `data`) such as the payload of a compressed-video packet, decodes to an empty dictionary and its bytes are lost. The message's other fields decode normally. Treat a payload field that is not `bytes` as undecodable rather than assume it holds frame data.

#### MsgpackDecoderFactory.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/msgpack_decoder_factory.py#L59-L84)

Return a function that decodes messages on a msgpack channel with this schema.

The `mcap` library's reader calls this when it decodes the first message on a channel.

**Parameters**

- **message_encoding** (`str`): Message encoding of the channel.
- **schema** (`Optional[mcap.records.Schema]`): Schema of the channel, or `None` when the channel has none.

**Returns**

- `Optional[Callable[[bytes], Any]]`: Function that decodes one message's bytes, or `None` when `message_encoding` is not `msgpack` or `schema` is `None`, so the `mcap` reader tries its other decoder factories.

**Raises**

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

### make_msgpack_decoder_factory()

```python
def roboto.formats.mcap.msgpack_decoder_factory.make_msgpack_decoder_factory() -> MsgpackDecoderFactory
```

`from roboto.formats.mcap.msgpack_decoder_factory import make_msgpack_decoder_factory`

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

Build a decoder factory for msgpack-encoded MCAP messages.

[`McapReader`](/docs/reference/python-sdk/roboto/formats/mcap/reader#roboto.formats.mcap.reader.McapReader) decodes msgpack channels through it, so most code never calls it. `MsgpackDecoderFactory()` builds the same factory.

**Returns**

- `MsgpackDecoderFactory`
