ADTF  3.18.2
workspace/conan/dev_essential/1.3.3/dw/stable/package/37682420cd166e229516a41c8d6a139a0b13e1e1/include/ddl/serialization/serialization.h
Go to the documentation of this file.
1 
15 #ifndef DDL_SERIALIZER_CLASS_HEADER
16 #define DDL_SERIALIZER_CLASS_HEADER
17 
18 #include <a_util/result.h>
19 #include <ddl/codec/codec.h>
20 
21 #include <assert.h>
22 
23 namespace ddl {
24 namespace codec {
25 
29 _MAKE_RESULT(-3, ERR_AUTIL_UNEXPECTED);
36 template <typename DECODER, typename ENCODER>
37 a_util::result::Result transform(const DECODER& decoder, ENCODER& encoder)
38 {
39  try {
40  forEachLeafElement(decoder.getElements(), [&encoder](const auto& element) {
41  uint64_t value_pointer; // this is the max possible size of a data type at the moment!
42  // Usertypes are not allowed to be greater!
43  element.getRawValue(&value_pointer, sizeof(value_pointer));
44  encoder.setElementRawValue(element.getIndex(), &value_pointer, sizeof(value_pointer));
45  });
46  }
47  catch (const std::exception&) {
48  return ERR_AUTIL_UNEXPECTED;
49  }
50  return {};
51 }
52 
63  bool zero = false);
64 
65 } // namespace codec
66 } // namespace ddl
67 
69 
70 #endif // DDL_SERIALIZER_CLASS_HEADER
Memory buffer class to encapsulate and manage raw contiguously memory.
Definition: memorybuffer.h:23
A common result class usable as return value throughout.
bool zero(void *dest, std::size_t dest_size, std::size_t bytes_to_zero)
Portable safe memzero.
a_util::result::Result transform(const DECODER &decoder, ENCODER &encoder)
Copies all elements from a decoder to a codec.
_MAKE_RESULT(-3, ERR_AUTIL_UNEXPECTED)
Creates an a_util error ERR_AUTIL_UNEXPECTED.
void forEachLeafElement(ElementsType &elements, const std::function< void(std::conditional_t< std::is_const< ElementsType >::value, const typename ElementsType::element_type, typename ElementsType::element_type > &)> &func)
Iterates ALL leaf elements within ALL array elements.
a_util::result::Result transformToBuffer(const codec::Decoder &decoder, a_util::memory::MemoryBuffer &buffer, bool zero=false)
Tranforms the data from a given decoder into the opposite data representation.
Implementation of the ADTF default media description.
Common include for component a_util::result.