> This page is for version 4.5.
> For other versions, use one of these documentation indexes:
> - 4.6 (Latest) (default): https://docs.nvidia.com/holoscan/sdk-user-guide/4-6-latest/llms.txt
> - ltsb-2.0: https://docs.nvidia.com/holoscan/sdk-user-guide/ltsb-2-0/llms.txt
> - 4.5: https://docs.nvidia.com/holoscan/sdk-user-guide/4-5/llms.txt
> - 4.4: https://docs.nvidia.com/holoscan/sdk-user-guide/4-4/llms.txt
> - 4.3: https://docs.nvidia.com/holoscan/sdk-user-guide/4-3/llms.txt
> - Archives: https://docs.nvidia.com/holoscan/sdk-user-guide/archives/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/holoscan/sdk-user-guide/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/holoscan/sdk-user-guide/_mcp/server.

# holoscan::CodecRegistry

> Class to set codecs for data types.

Class to set codecs for data types.

This class is used to set codecs (serializer + deserializer) for data types.

```cpp showLineNumbers={false}
#include <holoscan/codec_registry.hpp>
```

---

## Constructors

### CodecRegistry \[#codecregistry]

```cpp showLineNumbers={false}
holoscan::CodecRegistry::CodecRegistry()
```

---

## Methods

### get\_codec \[#getcodec]

#### Get the codec function pair (with index)

```cpp showLineNumbers={false}
Codec & holoscan::CodecRegistry::get_codec(
    const std::type_index &index
)
```

Get the codec function pair.

**Returns:** The reference to the Codec object.

**Parameters**

**`index`** `const std::type_index &`

The type index of the parameter.

---

#### Get the codec function pair (with codec name)

```cpp showLineNumbers={false}
Codec & holoscan::CodecRegistry::get_codec(
    const std::string &codec_name
)
```

Get the codec function pair.

**Returns:** The reference to the Codec object.

**Parameters**

**`codec_name`** `const std::string &`

The name of the codec.

---

### get\_serializer \[#getserializer]

#### Get the serializer function (with codec name)

```cpp showLineNumbers={false}
SerializeFunc & holoscan::CodecRegistry::get_serializer(
    const std::string &codec_name
)
```

Get the serializer function.

**Returns:** The reference to the Serializer function.

**Parameters**

**`codec_name`** `const std::string &`

The name of the codec.

---

#### Get the serializer function (with index)

```cpp showLineNumbers={false}
SerializeFunc & holoscan::CodecRegistry::get_serializer(
    const std::type_index &index
)
```

Get the serializer function.

**Returns:** The reference to the Serializer function.

**Parameters**

**`index`** `const std::type_index &`

The type index of the parameter.

---

### get\_deserializer \[#getdeserializer]

#### Get the deserializer function (with codec name)

```cpp showLineNumbers={false}
DeserializeFunc & holoscan::CodecRegistry::get_deserializer(
    const std::string &codec_name
)
```

Get the deserializer function.

**Returns:** The reference to the Deserializer function.

**Parameters**

**`codec_name`** `const std::string &`

The name of the codec.

---

#### Get the deserializer function (with index)

```cpp showLineNumbers={false}
DeserializeFunc & holoscan::CodecRegistry::get_deserializer(
    const std::type_index &index
)
```

Get the deserializer function.

**Returns:** The reference to the Deserializer function.

**Parameters**

**`index`** `const std::type_index &`

The type index of the parameter.

---

### name\_to\_index \[#nametoindex]

```cpp showLineNumbers={false}
expected<std::type_index, RuntimeError> holoscan::CodecRegistry::name_to_index(
    const std::string &codec_name
)
```

Get the std::type\_index corresponding to a codec name.

**Returns:** The std::type\_index corresponding to the name.

**Parameters**

**`codec_name`** `const std::string &`

The name of the codec.

---

### index\_to\_name \[#indextoname]

```cpp showLineNumbers={false}
expected<std::string, RuntimeError> holoscan::CodecRegistry::index_to_name(
    const std::type_index &index
)
```

Get the codec name corresponding to a std::type\_index.

**Returns:** The name of the codec.

**Parameters**

**`index`** `const std::type_index &`

The std::type\_index corresponding to the parameter.

---

### add\_codec \[#addcodec]

#### Add a codec for the type (with codec)

```cpp showLineNumbers={false}
template <typename typeT>
void holoscan::CodecRegistry::add_codec(
    std::pair<SerializeFunc, DeserializeFunc> &codec,
    const std::string &codec_name,
    bool overwrite = true
)
```

Add a codec for the type.

**Template parameters**

**`typeT`** `typename`

The type of the parameter.

---

**Parameters**

**`codec`** `std::pair<SerializeFunc, DeserializeFunc> &`

A pair containing a serialization function and deserialization function.

---

**`codec_name`** `const std::string &`

The name of the codec to add.

---

**`overwrite`** `bool` — default: true

If true, any existing codec with matching codec\_name will be overwritten.

---

#### Add a codec for the type (with codec and index)

```cpp showLineNumbers={false}
void holoscan::CodecRegistry::add_codec(
    const std::type_index &index,
    std::pair<SerializeFunc, DeserializeFunc> &codec,
    const std::string &codec_name,
    bool overwrite = true
)
```

Add a codec for the type.

**Parameters**

**`index`** `const std::type_index &`

The type index of the parameter.

---

**`codec`** `std::pair<SerializeFunc, DeserializeFunc> &`

A pair containing a serialization function and deserialization function.

---

**`codec_name`** `const std::string &`

The name of the codec to add.

---

**`overwrite`** `bool` — default: true

If true, any existing codec with matching codec\_name will be overwritten.

---

#### Add a codec for the type

```cpp showLineNumbers={false}
template <typename typeT>
void holoscan::CodecRegistry::add_codec(
    const std::string &codec_name,
    bool overwrite = true
)
```

Add a codec for the type.

**Template parameters**

**`typeT`** `typename`

The type for which a codec is being added

---

**Parameters**

**`codec_name`** `const std::string &`

The name of the codec to add.

---

**`overwrite`** `bool` — default: true

If true, any existing codec with matching codec\_name will be overwritten.

---

---

## Static methods

### get\_instance \[#getinstance]

```cpp showLineNumbers={false}
static CodecRegistry & holoscan::CodecRegistry::get_instance()
```

Get the instance object.

**Returns:** The reference to the `CodecRegistry` instance.

### serialize \[#serialize]

```cpp showLineNumbers={false}
static expected<size_t, RuntimeError> holoscan::CodecRegistry::serialize(
    const Message &message,
    holoscan::Endpoint *endpoint
)
```

Serialize the message object.

**Parameters**

**`message`** `const Message &`

The message to serialize.

---

**`endpoint`** `holoscan::Endpoint *`

The serialization endpoint (buffer).

---

### deserialize \[#deserialize]

```cpp showLineNumbers={false}
template <typename typeT>
static expected<Message, RuntimeError> holoscan::CodecRegistry::deserialize(
    holoscan::Endpoint *endpoint
)
```

Deserialize the message object.

**Template parameters**

**`typeT`** `typename`

The data type within the message.

---

**Parameters**

**`endpoint`** `holoscan::Endpoint *`

The serialization endpoint (buffer).

---

---

## Types

### Typedefs

| Name              | Definition                                                                                | Description                                                              |
| ----------------- | ----------------------------------------------------------------------------------------- | ------------------------------------------------------------------------ |
| `SerializeFunc`   | `std::function< expected< size_t, RuntimeError >(const Message &, holoscan::Endpoint *)>` | Function type for serializing a data type.                               |
| `DeserializeFunc` | `std::function< expected< Message, RuntimeError >(holoscan::Endpoint *)>`                 | Function type for deserializing a data type.                             |
| `Codec`           | `std::pair< SerializeFunc, DeserializeFunc >`                                             | Function pair type for serialization and deserialization of a data type. |

---

## Member variables

| Name                      | Type                                                                             | Description                                      |
| ------------------------- | -------------------------------------------------------------------------------- | ------------------------------------------------ |
| `none_serialize` static   | `SerializeFunc`                                                                  |                                                  |
| `none_deserialize` static | `DeserializeFunc`                                                                |                                                  |
| `none_codec` static       | `Codec`                                                                          | Default Codec for [Arg](arg).                    |
| `index_to_name_map_`      | `std::unordered_map< std::type_index, std::string >`                             | Mapping from type\_index to name.                |
| `name_to_index_map_`      | `std::unordered_map< std::string, std::type_index >`                             | Mapping from name to type\_index.                |
| `codec_map_`              | `std::unordered_map< std::string, std::pair< SerializeFunc, DeserializeFunc > >` | [Map](map) of codec name to codec function pair. |