NVIDIA Holoscan SDK v3.8.0

Class CodecRegistry

class CodecRegistry

Class to set codecs for data types.

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

Public Types

using SerializeFunc = std::function<expected<size_t, RuntimeError>(const Message&, holoscan::Endpoint*)>

Function type for serializing a data type.

using DeserializeFunc = std::function<expected<Message, RuntimeError>(holoscan::Endpoint*)>

Function type for deserializing a data type.

using Codec = std::pair<SerializeFunc, DeserializeFunc>

Function pair type for serialization and deserialization of a data type.

Public Functions

inline Codec &get_codec(const std::type_index &index)

Get the codec function pair.

Parameters

index – The type index of the parameter.

Returns

The reference to the Codec object.

inline Codec &get_codec(const std::string &codec_name)

Get the codec function pair.

Parameters

codec_name – The name of the codec.

Returns

The reference to the Codec object.

inline SerializeFunc &get_serializer(const std::string &codec_name)

Get the serializer function.

Parameters

codec_name – The name of the codec.

Returns

The reference to the Serializer function.

inline SerializeFunc &get_serializer(const std::type_index &index)

Get the serializer function.

Parameters

index – The type index of the parameter.

Returns

The reference to the Serializer function.

inline DeserializeFunc &get_deserializer(const std::string &codec_name)

Get the deserializer function.

Parameters

codec_name – The name of the codec.

Returns

The reference to the Deserializer function.

inline DeserializeFunc &get_deserializer(const std::type_index &index)

Get the deserializer function.

Parameters

index – The type index of the parameter.

Returns

The reference to the Deserializer function.

inline expected<std::type_index, RuntimeError> name_to_index(const std::string &codec_name)

Get the std::type_index corresponding to a codec name.

Parameters

codec_name – The name of the codec.

Returns

The std::type_index corresponding to the name.

inline expected<std::string, RuntimeError> index_to_name(const std::type_index &index)

Get the codec name corresponding to a std::type_index.

Parameters

index – The std::type_index corresponding to the parameter.

Returns

The name of the codec.

template<typename typeT>
inline void add_codec(std::pair<SerializeFunc, DeserializeFunc> &codec, const std::string &codec_name, bool overwrite = true)

Add a codec for the type.

Template Parameters

typeT – the type of the parameter.

Parameters
  • codec – a pair containing a serialization function and deserialization function.

  • codec_name – the name of the codec to add.

  • overwrite – if true, any existing codec with matching codec_name will be overwritten.

inline void 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 – the type index of the parameter.

  • codec – a pair containing a serialization function and deserialization function.

  • codec_name – the name of the codec to add.

  • overwrite – if true, any existing codec with matching codec_name will be overwritten.

template<typename typeT>
inline void add_codec(const std::string &codec_name, bool overwrite = true)

Add a codec for the type.

Template Parameters

typeT – the type for which a codec is being added

Parameters
  • codec_name – The name of the codec to add.

  • overwrite – if true, any existing codec with matching codec_name will be overwritten.

Public Static Functions

static CodecRegistry &get_instance()

Get the instance object.

Returns

The reference to the CodecRegistry instance.

static inline expected<size_t, RuntimeError> serialize(const Message &message, holoscan::Endpoint *endpoint)

Serialize the message object.

Template Parameters

typeT – The data type within the message.

Parameters
  • message – The message to serialize.

  • endpoint – The serialization endpoint (buffer).

template<typename typeT>
static inline expected<Message, RuntimeError> deserialize(holoscan::Endpoint *endpoint)

Deserialize the message object.

Template Parameters

typeT – The data type within the message.

Parameters

endpoint – The serialization endpoint (buffer).

Public Static Attributes

static SerializeFunc none_serialize = [](constMessage& , holoscan::Endpoint* ) -> expected<size_t, RuntimeError> {HOLOSCAN_LOG_ERROR("Unable toserializemessage");return static_cast<size_t>(0);}
static DeserializeFunc none_deserialize = [](holoscan::Endpoint* ) -> expected<Message, RuntimeError> {HOLOSCAN_LOG_ERROR("Unable todeserializemessage");returnMessage();}
static Codec none_codec = std::make_pair(none_serialize, none_deserialize)

Default Codec for Arg.

Previous Class ClockInterface
Next Class Component
© Copyright 2022-2025, NVIDIA. Last updated on Nov 6, 2025