From d1a6d6c388aaec54f58f611808c7de191ed2b27b Mon Sep 17 00:00:00 2001 From: Arkadiusz Szczepkowicz Date: Tue, 23 Jul 2024 15:48:43 +0200 Subject: [PATCH] #268: Add comments in the deserializeType method --- src/checkpoint/dispatch/dispatch.h | 4 ++-- src/checkpoint/dispatch/dispatch.impl.h | 27 ++++++++++++++++--------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/checkpoint/dispatch/dispatch.h b/src/checkpoint/dispatch/dispatch.h index 46e0a2a3..16f87129 100644 --- a/src/checkpoint/dispatch/dispatch.h +++ b/src/checkpoint/dispatch/dispatch.h @@ -213,7 +213,7 @@ struct Prefixed { /** * \brief Unpack \c T from packed byte-buffer \c mem * - * \param[in] t_buf bytes holding a serialized \c T + * \param[in] mem bytes holding a serialized \c T * \param[in] check_type the flag to control type validation * \param[in] check_mem the flag to control memory validation * \param[in] args arguments to the unpacker's constructor @@ -221,7 +221,7 @@ struct Prefixed { * \return a pointer to an unpacked \c T */ template - static T* unpack(T* t_buf, bool check_type = true, bool check_mem = true, Args&&... args); + static T* unpack(T* mem, bool check_type = true, bool check_mem = true, Args&&... args); }; template diff --git a/src/checkpoint/dispatch/dispatch.impl.h b/src/checkpoint/dispatch/dispatch.impl.h index d88e3b00..cfadb5d1 100644 --- a/src/checkpoint/dispatch/dispatch.impl.h +++ b/src/checkpoint/dispatch/dispatch.impl.h @@ -303,7 +303,9 @@ packBuffer(T& target, SerialSizeType size, BufferObtainFnType fn) { } template -typename std::enable_if::value || !vrt::VirtualSerializeTraits::has_virtual_serialize, buffer::ImplReturnType>::type +typename std::enable_if< + !std::is_class::value || !vrt::VirtualSerializeTraits::has_virtual_serialize, + buffer::ImplReturnType>::type serializeType(T& target, BufferObtainFnType fn) { auto len = Standard::size(target); debug_checkpoint("serializeType: len=%ld\n", len); @@ -311,8 +313,9 @@ serializeType(T& target, BufferObtainFnType fn) { } template -typename std::enable_if::value - || !vrt::VirtualSerializeTraits::has_virtual_serialize, T*>::type +typename std::enable_if< + !std::is_class::value || !vrt::VirtualSerializeTraits::has_virtual_serialize, + T*>::type deserializeType(SerialByteType* data, SerialByteType* allocBuf) { auto mem = allocBuf ? allocBuf : Standard::allocate(); auto t_buf = std::unique_ptr(Standard::construct(mem)); @@ -322,7 +325,6 @@ deserializeType(SerialByteType* data, SerialByteType* allocBuf) { return traverser; } -// TODO: this also needs to be updated template void deserializeType(InPlaceTag, SerialByteType* data, T* t) { Standard::unpack>(t, data); @@ -345,30 +347,35 @@ struct PrefixedType { }; template -typename std::enable_if::value && vrt::VirtualSerializeTraits::has_virtual_serialize, buffer::ImplReturnType>::type +typename std::enable_if< + std::is_class::value && vrt::VirtualSerializeTraits::has_virtual_serialize, + buffer::ImplReturnType>::type serializeType(T& target, BufferObtainFnType fn) { auto prefixed = PrefixedType(&target); - auto len = Standard::size, Sizer>(prefixed); + auto len = Standard::size(prefixed); debug_checkpoint("serializeType: len=%ld\n", len); - return packBuffer>(prefixed, len, fn); + return packBuffer(prefixed, len, fn); } template -typename std::enable_if::value - && vrt::VirtualSerializeTraits::has_virtual_serialize, T*>::type +typename std::enable_if< + std::is_class::value && vrt::VirtualSerializeTraits::has_virtual_serialize, + T*>::type deserializeType(SerialByteType* data, SerialByteType* allocBuf) { using BaseType = vrt::checkpoint_base_type_t; auto prefix_mem = Standard::allocate(); auto prefix_buf = std::unique_ptr(Standard::construct(prefix_mem)); + // Unpack TypeIdx, ignore checks for type and memory used - unpacking will only use a part of the data vrt::TypeIdx* prefix = Prefixed::unpack>(prefix_buf.get(), false, false, data); prefix_buf.release(); + // allocate memory based on the readed TypeIdx auto mem = allocBuf ? allocBuf : vrt::objregistry::allocateConcreteType(*prefix); auto t_buf = vrt::objregistry::constructConcreteType(*prefix, mem); auto prefixed = PrefixedType(t_buf); - + // Unpack PrefixedType, ignore checks for unpacked type and execute checks for memory used auto* traverser = Prefixed::unpack>(&prefixed, false, true, data); return static_cast(traverser->target_);