IDS peak ICV v1.3.0
Loading...
Searching...
No Matches
peak_icv_serializer.hpp
Go to the documentation of this file.
1
11#pragma once
12
15
23
24namespace peak
25{
26namespace icv
27{
54{
55public:
71
87 void Write(const peak::common::serialization::IArchive& archive, std::ostream& stream) override;
88
89private:
90 SerializationType m_type;
91};
92
94 : m_type{ type }
95{}
96
97inline void Serializer::Write(const peak::common::serialization::IArchive& archive, std::ostream& stream)
98{
99 std::vector<char> buffer;
100
101 auto* archiveHandle = [&archive]() {
102 try
103 {
104 const auto& realArchive = dynamic_cast<const Archive&>(archive);
105 return peak::common::detail::BackendAccessor<Archive>::BackendHandle(realArchive);
106 }
107 catch (std::bad_cast&)
108 {
109 throw InternalErrorException("The given archive is invalid. This should not happen.", PEAK_ICV_STATUS_INTERNAL_ERROR);
110 }
111 }();
112
113 size_t size{};
115 return PEAK_ICV_C_ABI_PREFIX peak_icv_Archive_ToString_GetSizeInBytes(
116 archiveHandle, helper::MapSerializationTypeToApi(m_type), &size);
117 });
118
119 buffer.resize(size);
120
122 return PEAK_ICV_C_ABI_PREFIX peak_icv_Archive_ToString(
123 archiveHandle, helper::MapSerializationTypeToApi(m_type), buffer.data(), &size);
124 });
125
126 stream.write(buffer.data(), static_cast<std::streamsize>(buffer.size() - 1));
127}
128
129} /* namespace icv */
130} /* namespace peak */
Interface for a hierarchical key-value archive system.
Interface for serializing data to an output stream.
A key-value store that implements the IArchive interface.
Occurs when a failure happens during processing due to an unhandled internal routine condition.
Serializer for writing IArchive objects to an output stream.
Serializer(SerializationType type=SerializationType::Json)
Constructs a Serializer with the specified serialization type.
void Write(const peak::common::serialization::IArchive &archive, std::ostream &stream) override
Serializes an archive and writes it to a stream.
SerializationType
Enumeration of supported serialization formats.
@ Json
JSON (JavaScript Object Notation) format.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
peak_icv_serialization_type MapSerializationTypeToApi(SerializationType type)