IDS peak ICV v1.1.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{
36{
37public:
48
49
61 void Write(const peak::common::serialization::IArchive& archive, std::ostream& stream) override;
62
63private:
64 SerializationType m_type;
65};
66
68 : m_type{ type }
69{}
70
71inline void Serializer::Write(const peak::common::serialization::IArchive& archive, std::ostream& stream)
72{
73 std::vector<char> buffer;
74
75 auto* archiveHandle = [&archive]() {
76 try
77 {
78 const auto& realArchive = dynamic_cast<const Archive&>(archive);
79 return peak::common::detail::BackendAccessor<Archive>::BackendHandle(realArchive);
80 }
81 catch (std::bad_cast&)
82 {
83 throw InternalErrorException("The given archive is invalid. This should not happen.", PEAK_ICV_STATUS_INTERNAL_ERROR);
84 }
85 }();
86
87 size_t size{};
89 return PEAK_ICV_C_ABI_PREFIX peak_icv_Archive_ToString_GetSizeInBytes(
90 archiveHandle, helper::MapSerializationTypeToApi(m_type), &size);
91 });
92
93 buffer.resize(size);
94
96 return PEAK_ICV_C_ABI_PREFIX peak_icv_Archive_ToString(
97 archiveHandle, helper::MapSerializationTypeToApi(m_type), buffer.data(), &size);
98 });
99
100 stream.write(buffer.data(), static_cast<std::streamsize>(buffer.size() - 1));
101}
102
103} /* namespace icv */
104} /* namespace peak */
Interface for a hierarchical key-value archive system.
Interface for serializing data to an output stream.
A simple key-value store that implements the IArchive interface.
Thrown on unexpected internal system errors.
A serializer that serializes IArchive objects.
Serializer(SerializationType type=SerializationType::Json)
Constructor with archive and serialization type.
void Write(const peak::common::serialization::IArchive &archive, std::ostream &stream) override
Writes the serialized archive data to an output stream.
SerializationType
Defines the supported serialization formats for the serialization system.
@ Json
JSON (JavaScript Object Notation) format.
void ExecuteAndMapReturnCodes(const CallableType &callableObject)
peak_icv_serialization_type MapSerializationTypeToApi(SerializationType type)