Class CodecRegistry
Defined in File codec_registry.hpp
-
class CodecRegistry
Class to set codecs for data types.
This class is used to set codecs (serializer + deserializer) for data types.
Public Types
- using GXFEndpoint = nvidia::gxf::Endpoint
- using SerializeFunc = std::function<nvidia::gxf::Expected<size_t>(const Message&, GXFEndpoint*)>
Function type for serializing a data type.
- using DeserializeFunc = std::function<nvidia::gxf::Expected<Message>(GXFEndpoint*)>
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
- Returns
index – The type index of the parameter.
The reference to the Codec object.
-
inline Codec &get_codec(const std::string &codec_name)
Get the codec function pair.
- Parameters
- Returns
codec_name – The name of the codec.
The reference to the Codec object.
-
inline SerializeFunc &get_serializer(const std::string &codec_name)
Get the serializer function.
- Parameters
- Returns
codec_name – The name of the codec.
The reference to the Serializer function.
-
inline SerializeFunc &get_serializer(const std::type_index &index)
Get the serializer function.
- Parameters
- Returns
index – The type index of the parameter.
The reference to the Serializer function.
-
inline DeserializeFunc &get_deserializer(const std::string &codec_name)
Get the deserializer function.
- Parameters
- Returns
codec_name – The name of the codec.
The reference to the Deserializer function.
-
inline DeserializeFunc &get_deserializer(const std::type_index &index)
Get the deserializer function.
- Parameters
- Returns
index – The type index of the parameter.
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
- Returns
codec_name – The name of the codec.
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
- Returns
index – The std::type_index corresponding to the parameter.
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
- 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.
typeT – the type of the parameter.
-
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
- 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.
typeT – the type for which a codec is being added
Public Static Functions
-
static CodecRegistry &get_instance()
Get the instance object.
- Returns
The reference to the CodecRegistry instance.
-
static inline nvidia::gxf::Expected<size_t> serialize(const Message &message, GXFEndpoint *gxf_endpoint)
Serialize the message object.
- Template Parameters
- Parameters
message – The message to serialize.
endpoint – The serialization endpoint (buffer).
typeT – The data type within the message.
-
template<typename typeT>
static inline nvidia::gxf::Expected<Message> deserialize(GXFEndpoint *gxf_endpoint) Deserialize the message object.
- Template Parameters
- Parameters
message – The message to serialize.
endpoint – The serialization endpoint (buffer).
typeT – The data type within the message.
Public Static Attributes
-
static SerializeFunc none_serialize =
[]([[maybe_unused]] constMessage& message,[[maybe_unused]] GXFEndpoint* buffer) -> nvidia::gxf::Expected<size_t> {HOLOSCAN_LOG_ERROR("Unable toserializemessage");return 0;}
-
static DeserializeFunc none_deserialize =
[]([[maybe_unused]] GXFEndpoint* buffer) -> nvidia::gxf::Expected<Message> {HOLOSCAN_LOG_ERROR("Unable todeserializemessage");returnMessage();}
- static Codec none_codec = std::make_pair(none_serialize, none_deserialize)