ADTF  3.18.2
leaf_value_access.h
Go to the documentation of this file.
1 
16 #ifndef DDL_PREVIEW_LEAF_VALUE_ACCESS_PRIVATE_CLASS_HEADER
17 #define DDL_PREVIEW_LEAF_VALUE_ACCESS_PRIVATE_CLASS_HEADER
18 
21 #include <ddl/codec/codec_index.h>
24 
25 #include <cstring>
26 #include <stdexcept>
27 
28 namespace ddl {
29 namespace codec {
30 
34 enum class LeafDataRepresentation : uint8_t {
39  deserialized = 0x00,
44  serialized = 0x01,
49  serialized_be = 0x03,
54  serialized_le = 0x01
55 };
56 
60 enum class LeafElementType : uint8_t {
61  let_bool = static_cast<uint8_t>(ElementType::cet_bool),
62  let_int8 = static_cast<uint8_t>(ElementType::cet_int8),
63  let_uint8 =
64  static_cast<uint8_t>(ElementType::cet_uint8),
65  let_int16 =
66  static_cast<uint8_t>(ElementType::cet_int16),
67  let_uint16 =
68  static_cast<uint8_t>(ElementType::cet_uint16),
69  let_int32 =
70  static_cast<uint8_t>(ElementType::cet_int32),
71  let_uint32 =
72  static_cast<uint8_t>(ElementType::cet_uint32),
73  let_int64 =
74  static_cast<uint8_t>(ElementType::cet_int64),
75  let_uint64 =
76  static_cast<uint8_t>(ElementType::cet_uint64),
77  let_float = static_cast<uint8_t>(ElementType::cet_float),
78  let_double = static_cast<uint8_t>(ElementType::cet_double),
79 };
80 
85 struct LeafLayout {
87  static constexpr uint32_t _invalid_pos = static_cast<uint32_t>(-1);
89  static constexpr size_t _max_byte_size = 31;
91  static constexpr size_t _max_bit_size = 255;
92 
94  uint32_t byte_pos =
95  _invalid_pos; // we do not need to use size_t here because CodecLayout will have bits!
97  uint8_t bit_pos = {}; // bitpos is only set in serialzed representation
99  LeafElementType element_type{}; // elementtype
101  uint8_t bit_size = {}; // max. 255bit for userdefined types!
103  uint8_t data_flags = static_cast<uint8_t>(LeafDataRepresentation::deserialized);
104 };
105 
118 private:
119  template <bool ThrowError>
120  using throw_error = std::integral_constant<bool, ThrowError>;
121 
122 public:
126  LeafCodecIndex() = delete;
132  LeafCodecIndex(const CodecIndex& codec_index,
134  {
135  convertToLeafLayout</*throw_error=*/true>(codec_index, _leaf_layout, rep);
136  }
141  const LeafLayout& getLayout() const noexcept
142  {
143  return _leaf_layout;
144  }
145 
157  template <bool ThrowError>
158  static bool convertToLeafLayout(const CodecIndex& codec_index,
159  LeafLayout& leaf_layout,
161  {
162  if (!checkLeafLayout<ThrowError>(codec_index, rep)) {
163  return false;
164  }
165  return convertToLeafLayout(codec_index, leaf_layout, rep, throw_error<ThrowError>{});
166  }
167 
168 private:
170  static bool convertToLeafLayout(const CodecIndex& codec_index,
171  LeafLayout& leaf_layout,
173  throw_error<false>) noexcept
174  {
175  const auto& layout = codec_index.getLayout();
176  leaf_layout.element_type = static_cast<LeafElementType>(layout.type_info->getType());
178  leaf_layout.data_flags = static_cast<uint8_t>(LeafDataRepresentation::deserialized);
179  leaf_layout.byte_pos = static_cast<uint32_t>(layout.deserialized.bit_offset / 8);
180  if (layout.deserialized.type_bit_size > (std::numeric_limits<uint8_t>::max)()) {
181  return false;
182  }
183  // no bitpos in serialized representation
184  leaf_layout.bit_size = static_cast<uint8_t>(layout.deserialized.type_bit_size);
185  }
186  else {
187  leaf_layout.data_flags |=
188  (layout.byte_order == dd::ByteOrder::e_be) ?
189  static_cast<uint8_t>(LeafDataRepresentation::serialized_be) :
190  static_cast<uint8_t>(LeafDataRepresentation::serialized_le);
191  leaf_layout.bit_pos = layout.serialized.bit_offset % 8;
192  leaf_layout.byte_pos = static_cast<uint32_t>(layout.serialized.bit_offset / 8 +
193  ((leaf_layout.bit_pos == 0) ? 0 : 1));
194  if (layout.serialized.type_bit_size_used > (std::numeric_limits<uint8_t>::max)()) {
195  return false;
196  }
197  leaf_layout.bit_size = static_cast<uint8_t>(layout.serialized.type_bit_size_used);
198  if (layout.serialized.type_bit_size_used == layout.deserialized.type_bit_size &&
199  leaf_layout.bit_pos == 0 &&
200  layout.byte_order == dd::ByteOrderDefault::getPlatformDefault()) {
201  // this means: the same type is used in serialized and deserialized without byteswap
202  // the simple fast memcopy operation can be used
203  // switch back to deserialzed option, but keep bytepos!
204  leaf_layout.data_flags = static_cast<uint8_t>(LeafDataRepresentation::deserialized);
205  }
206  }
207  return true;
208  }
209 
211  static bool convertToLeafLayout(const CodecIndex& codec_index,
212  LeafLayout& leaf_layout,
214  throw_error<true>)
215  {
216  if (!convertToLeafLayout(codec_index, leaf_layout, rep, throw_error<false>{})) {
217  throw std::runtime_error(
218  "element size exceeds maximal bit size for small leaf layout of" +
219  std::to_string((std::numeric_limits<uint8_t>::max)()));
220  }
221  return true;
222  }
223 
225  template <typename T>
226  static bool checkTypeSize(const CodecIndex& codec_index,
228  bool exact_check_on_serialized,
229  throw_error<false>) noexcept
230  {
231  const auto size_to_check = (rep == ddl::DataRepresentation::serialized) ?
232  (codec_index.getLayout().serialized.type_bit_size / 8) :
233  (codec_index.getLayout().deserialized.type_bit_size / 8);
234  if (rep == ddl::DataRepresentation::serialized && !exact_check_on_serialized) {
235  if (sizeof(T) < size_to_check) {
236  return false;
237  }
238  }
239  return (sizeof(T) == size_to_check);
240  }
241 
243  template <typename T>
244  static bool checkTypeSize(const CodecIndex& codec_index,
246  bool exact_check,
247  throw_error<true>)
248  {
249  if (!checkTypeSize<T>(codec_index, rep, exact_check, throw_error<false>{})) {
250  throw std::runtime_error(
251  "Standard datatype is only supported if bit size is not customized. Found "
252  "element type with different size to standard!");
253  }
254  return true;
255  }
256 
258  template <bool ThrowError>
259  static bool checkLeafLayout(const CodecIndex& codec_index, ddl::DataRepresentation rep)
260  {
261  switch (codec_index.getType()) {
262  case ElementType::cet_empty: // fall thru
264  if (ThrowError) {
265  throw std::runtime_error("Small leaf layouts can only be used for leaf elements!");
266  }
267  return false;
268  break;
269  }
270  case ElementType::cet_bool: {
271  return checkTypeSize<bool>(codec_index, rep, false, throw_error<ThrowError>{});
272  break;
273  }
275  case ElementType::cet_uint8: {
276  return checkTypeSize<int8_t>(codec_index, rep, false, throw_error<ThrowError>{});
277  break;
278  }
281  return checkTypeSize<int16_t>(codec_index, rep, false, throw_error<ThrowError>{});
282  break;
283  }
286  return checkTypeSize<int32_t>(codec_index, rep, false, throw_error<ThrowError>{});
287  break;
288  }
289  case ElementType::cet_float: {
290  return checkTypeSize<int32_t>(codec_index, rep, true, throw_error<ThrowError>{});
291  break;
292  }
295  return checkTypeSize<int64_t>(codec_index, rep, false, throw_error<ThrowError>{});
296  break;
297  }
299  return checkTypeSize<int64_t>(codec_index, rep, true, throw_error<ThrowError>{});
300  break;
301  }
303  if (ThrowError) {
304  throw std::runtime_error(
305  "user supported types are not supported in small leaf layout");
306  }
307  else {
308  return false;
309  }
310  }
311  }
312  return true;
313  }
316 };
317 
318 #if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
319 #pragma GCC diagnostic ignored \
320  "-Wattributes" // standard type attributes are ignored when used in templates
321 #endif // defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
322 
323 namespace detail {
324 
325 template <typename ValueType>
327  : public std::is_arithmetic<a_util::underlying_type_or_type_t<ValueType>> {
328 };
329 
330 template <typename ElementValueTypeFrom, typename TargetValueTypeTo>
332  : public std::integral_constant<
333  bool,
334  (!std::is_enum<TargetValueTypeTo>::value &&
335  a_util::is_explicitly_convertible_to_v<ElementValueTypeFrom, TargetValueTypeTo>) ||
336  (std::is_enum<TargetValueTypeTo>::value &&
337  !std::is_floating_point<ElementValueTypeFrom>::value)> {
338 };
339 
340 template <typename ValueType>
342  : public std::integral_constant<
343  bool,
344  a_util::is_explicitly_convertible_to_v<bool, ValueType> ||
345  a_util::is_explicitly_convertible_to_v<int8_t, ValueType> ||
346  a_util::is_explicitly_convertible_to_v<uint8_t, ValueType> ||
347  a_util::is_explicitly_convertible_to_v<int16_t, ValueType> ||
348  a_util::is_explicitly_convertible_to_v<uint16_t, ValueType> ||
349  a_util::is_explicitly_convertible_to_v<int32_t, ValueType> ||
350  a_util::is_explicitly_convertible_to_v<uint32_t, ValueType> ||
351  a_util::is_explicitly_convertible_to_v<int64_t, ValueType> ||
352  a_util::is_explicitly_convertible_to_v<uint64_t, ValueType> ||
353  a_util::is_explicitly_convertible_to_v<float, ValueType> ||
354  a_util::is_explicitly_convertible_to_v<double, ValueType>> {
355 };
356 
364 template <typename ElementValueType,
365  typename TargetValueType,
366  bool conversion_allowed =
375  static TargetValueType convert(const ElementValueType& element_value)
376  {
377  return static_cast<TargetValueType>(element_value);
378  }
379 };
380 
387 template <typename ElementValueType, typename TargetValueType>
388 struct TargetValueConverter<ElementValueType, TargetValueType, false> {
395  static TargetValueType convert(const ElementValueType&)
396  {
398  "The used type must at least convertible from one fundamental type (bool, "
399  "any int, float, double) explicitly!");
400  throw std::runtime_error("unsupported type conversion requested");
401  }
402 };
403 
404 template <typename ElementValueTypeTo, typename SourceValueTypeFrom>
406  : public std::integral_constant<
407  bool,
408  (!std::is_enum<SourceValueTypeFrom>::value &&
409  a_util::is_explicitly_convertible_to_v<SourceValueTypeFrom, ElementValueTypeTo>) ||
410  (std::is_enum<SourceValueTypeFrom>::value &&
411  !std::is_floating_point<ElementValueTypeTo>::value)> {
412 };
413 
414 template <typename ValueType>
416  : public std::integral_constant<
417  bool,
418  a_util::is_explicitly_convertible_to_v<ValueType, bool> ||
419  a_util::is_explicitly_convertible_to_v<ValueType, int8_t> ||
420  a_util::is_explicitly_convertible_to_v<ValueType, uint8_t> ||
421  a_util::is_explicitly_convertible_to_v<ValueType, int16_t> ||
422  a_util::is_explicitly_convertible_to_v<ValueType, uint16_t> ||
423  a_util::is_explicitly_convertible_to_v<ValueType, int32_t> ||
424  a_util::is_explicitly_convertible_to_v<ValueType, uint32_t> ||
425  a_util::is_explicitly_convertible_to_v<ValueType, int64_t> ||
426  a_util::is_explicitly_convertible_to_v<ValueType, uint64_t> ||
427  a_util::is_explicitly_convertible_to_v<ValueType, float> ||
428  a_util::is_explicitly_convertible_to_v<ValueType, double>> {
429 };
430 
438 template <typename ElementValueType,
439  typename SourceValueType,
440  bool conversion_allowed =
451  static bool convert(ElementValueType& element_value, const SourceValueType& value)
452  {
453  element_value = static_cast<ElementValueType>(value);
454  return true;
455  }
456 };
457 
464 template <typename ElementValueType, typename SourceValueType>
465 struct SourceValueConverter<ElementValueType, SourceValueType, false> {
473  static bool convert(ElementValueType&, const SourceValueType&)
474  {
476  "The used type must at least convertible to one fundamental type (bool, any "
477  "int, float, double) explicitly");
478  return false;
479  }
480 };
481 
494 template <typename ElementValueType, typename TargetValueType>
495 TargetValueType readBytes(const void* data, const size_t& data_size, uint32_t byte_pos)
496 {
497  ElementValueType value;
498  if (byte_pos + sizeof(ElementValueType) > data_size) {
499  throw std::runtime_error("copy action exceeds buffersize");
500  }
501  std::memcpy(&value, static_cast<const uint8_t*>(data) + byte_pos, sizeof(ElementValueType));
503 }
504 
517 template <typename ElementValueType, typename SourceValueType>
518 void writeBytes(void* data,
519  const size_t& data_size,
520  uint32_t byte_pos,
521  const SourceValueType& source_value)
522 {
523  if (byte_pos + sizeof(ElementValueType) > data_size) {
524  throw std::runtime_error("copy action exceeds buffersize");
525  }
526  else {
527  ElementValueType value;
529  std::memcpy(static_cast<uint8_t*>(data) + byte_pos, &value, sizeof(ElementValueType));
530  }
531  else {
532  throw std::runtime_error("unsupported type conversion requested");
533  }
534  }
535 }
536 
550 template <typename ElementValueType, typename TargetValueType>
551 TargetValueType readBits(const void* data,
552  size_t data_size,
553  size_t bit_offset,
554  size_t bit_size,
555  a_util::memory::Endianess byte_order)
556 {
557  ElementValueType value{};
558  a_util::memory::BitSerializer bit_reader(const_cast<void*>(data), data_size);
559  auto res = bit_reader.read<ElementValueType>(bit_offset, bit_size, &value, byte_order);
560  if (res) {
562  }
563  throw std::runtime_error(res.getDescription());
564 }
565 
579 template <typename ElementValueType, typename SourceValueType>
580 void writeBits(void* data,
581  size_t data_size,
582  size_t bit_offset,
583  size_t bit_size,
584  a_util::memory::Endianess byte_order,
585  const SourceValueType& source_value)
586 {
587  ElementValueType value{};
589  a_util::memory::BitSerializer bit_reader(data, data_size);
590  const auto res =
591  bit_reader.write<ElementValueType>(bit_offset, bit_size, value, byte_order);
592  if (!res) {
593  throw std::runtime_error(res.getDescription());
594  }
595  }
596  else {
597  throw std::runtime_error("unsupported type conversion requested");
598  }
599 }
600 
612 template <typename ValueType>
613 ValueType readDeserializedBytes(const void* data, const size_t& data_size, const LeafLayout& layout)
614 {
615  switch (layout.element_type) {
617  return readBytes<bool, ValueType>(data, data_size, layout.byte_pos);
618  }
620  return readBytes<uint8_t, ValueType>(data, data_size, layout.byte_pos);
621  }
623  return readBytes<int8_t, ValueType>(data, data_size, layout.byte_pos);
624  }
626  return readBytes<uint16_t, ValueType>(data, data_size, layout.byte_pos);
627  }
629  return readBytes<int16_t, ValueType>(data, data_size, layout.byte_pos);
630  }
632  return readBytes<uint32_t, ValueType>(data, data_size, layout.byte_pos);
633  }
635  return readBytes<int32_t, ValueType>(data, data_size, layout.byte_pos);
636  }
638  return readBytes<uint64_t, ValueType>(data, data_size, layout.byte_pos);
639  }
641  return readBytes<int64_t, ValueType>(data, data_size, layout.byte_pos);
642  }
644  return readBytes<float, ValueType>(data, data_size, layout.byte_pos);
645  }
647  return readBytes<double, ValueType>(data, data_size, layout.byte_pos);
648  }
649  default: // all others are not supported
650  {
651  break;
652  }
653  }
654  throw std::runtime_error("invalid type");
655 }
656 
667 template <typename ValueType>
668 ValueType readSerializedBits(const void* data, const size_t& data_size, const LeafLayout& layout)
669 {
670  const size_t bit_pos = layout.byte_pos * 8 + layout.bit_pos;
671  const size_t bit_size = layout.bit_size;
672  const a_util::memory::Endianess byte_order =
673  ((layout.data_flags & static_cast<uint8_t>(LeafDataRepresentation::serialized_be)) ==
674  static_cast<uint8_t>(LeafDataRepresentation::serialized_be)) ?
675  a_util::memory::bit_big_endian :
676  a_util::memory::bit_little_endian;
677  switch (layout.element_type) {
679  return readBits<bool, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
680  }
682  return readBits<uint8_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
683  }
685  return readBits<int8_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
686  }
688  return readBits<uint16_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
689  }
691  return readBits<int16_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
692  }
694  return readBits<uint32_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
695  }
697  return readBits<int32_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
698  }
700  return readBits<uint64_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
701  }
703  return readBits<int64_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
704  }
706  return readBits<float, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
707  }
709  return readBits<double, ValueType>(data, data_size, bit_pos, bit_size, byte_order);
710  }
711  default: // all others are not supported
712  {
713  break;
714  }
715  }
716  throw std::runtime_error("invalid type");
717 }
718 
729 template <typename ValueType>
730 void writeDeserializedBytes(void* data,
731  const size_t& data_size,
732  const LeafLayout& layout,
733  const ValueType& value)
734 {
735  switch (layout.element_type) {
737  return writeBytes<bool, ValueType>(data, data_size, layout.byte_pos, value);
738  }
740  return writeBytes<uint8_t, ValueType>(data, data_size, layout.byte_pos, value);
741  }
743  return writeBytes<int8_t, ValueType>(data, data_size, layout.byte_pos, value);
744  }
746  return writeBytes<uint16_t, ValueType>(data, data_size, layout.byte_pos, value);
747  }
749  return writeBytes<int16_t, ValueType>(data, data_size, layout.byte_pos, value);
750  }
752  return writeBytes<uint32_t, ValueType>(data, data_size, layout.byte_pos, value);
753  }
755  return writeBytes<int32_t, ValueType>(data, data_size, layout.byte_pos, value);
756  }
758  return writeBytes<uint64_t, ValueType>(data, data_size, layout.byte_pos, value);
759  }
761  return writeBytes<int64_t, ValueType>(data, data_size, layout.byte_pos, value);
762  }
764  return writeBytes<float, ValueType>(data, data_size, layout.byte_pos, value);
765  }
767  return writeBytes<double, ValueType>(data, data_size, layout.byte_pos, value);
768  }
769  default: // all others are not supported
770  {
771  break;
772  }
773  }
774  throw std::runtime_error("invalid type");
775 }
776 
788 template <typename ValueType>
789 void writeSerializedBits(void* data,
790  const size_t& data_size,
791  const LeafLayout& layout,
792  const ValueType& value)
793 {
794  const size_t bit_pos = layout.byte_pos * 8 + layout.bit_pos;
795  const size_t bit_size = layout.bit_size;
796  const a_util::memory::Endianess byte_order =
797  ((layout.data_flags & static_cast<uint8_t>(LeafDataRepresentation::serialized_be)) ==
798  static_cast<uint8_t>(LeafDataRepresentation::serialized_be)) ?
799  a_util::memory::bit_big_endian :
800  a_util::memory::bit_little_endian;
801  switch (layout.element_type) {
803  return writeBits<bool, ValueType>(data, data_size, bit_pos, bit_size, byte_order, value);
804  }
806  return writeBits<uint8_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order, value);
807  }
809  return writeBits<int8_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order, value);
810  }
812  return writeBits<uint16_t, ValueType>(
813  data, data_size, bit_pos, bit_size, byte_order, value);
814  }
816  return writeBits<int16_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order, value);
817  }
819  return writeBits<uint32_t, ValueType>(
820  data, data_size, bit_pos, bit_size, byte_order, value);
821  }
823  return writeBits<int32_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order, value);
824  }
826  return writeBits<uint64_t, ValueType>(
827  data, data_size, bit_pos, bit_size, byte_order, value);
828  }
830  return writeBits<int64_t, ValueType>(data, data_size, bit_pos, bit_size, byte_order, value);
831  }
833  return writeBits<float, ValueType>(data, data_size, bit_pos, bit_size, byte_order, value);
834  }
836  return writeBits<double, ValueType>(data, data_size, bit_pos, bit_size, byte_order, value);
837  }
838  default: // all others are not supported
839  {
840  break;
841  }
842  }
843  throw std::runtime_error("invalid type");
844 }
845 
846 } // namespace detail
847 
848 #if defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
849 #pragma GCC diagnostic warning \
850  "-Wattributes" // standard type attributes are ignored when used in templates
851 #endif // defined(__GNUC__) && (__GNUC__ == 5) && defined(__QNX__)
852 
860 template <typename ValueType>
870  static ValueType getValue(const void* data,
871  const size_t data_size,
872  const LeafLayout& leaf_layout)
873  {
874  if ((leaf_layout.data_flags & static_cast<uint8_t>(LeafDataRepresentation::serialized)) ==
875  static_cast<uint8_t>(LeafDataRepresentation::serialized)) {
876  return detail::readSerializedBits<ValueType>(data, data_size, leaf_layout);
877  }
878  else {
879  return detail::readDeserializedBytes<ValueType>(data, data_size, leaf_layout);
880  }
881  }
882 };
883 
891 template <typename ValueType>
901  static void setValue(void* data,
902  const size_t data_size,
903  const LeafLayout& leaf_layout,
904  const ValueType& value)
905  {
906  if ((leaf_layout.data_flags & static_cast<uint8_t>(LeafDataRepresentation::serialized)) ==
907  static_cast<uint8_t>(LeafDataRepresentation::serialized)) {
908  detail::writeSerializedBits<ValueType>(data, data_size, leaf_layout, value);
909  }
910  else {
911  detail::writeDeserializedBytes<ValueType>(data, data_size, leaf_layout, value);
912  }
913  }
914 };
915 } // namespace codec
916 } // namespace ddl
917 
918 #ifdef DDL_NO_SUPPORT_FOR_CONSTEXPR_CONDITION
919 #undef DDL_NO_SUPPORT_FOR_CONSTEXPR_CONDITION
920 #endif
921 
922 #endif
a_util::result::Result write(size_t start_bit, size_t bit_length, T value, Endianess endianess=get_platform_endianess())
Write value to bitfield.
a_util::result::Result read(size_t start_bit, size_t bit_length, T *value, Endianess endianess=get_platform_endianess())
Read value from bitfield.
Fast Access Index Type for the coders.
Definition: codec_index.h:132
ElementType getType() const
Get the elements type if CodecIndex is valid.
The Leaf codec index is a small layout information index to access the decoders/codecs data very fast...
static bool convertToLeafLayout(const CodecIndex &codec_index, LeafLayout &leaf_layout, ddl::DataRepresentation rep, throw_error< false >) noexcept
For internal use only.
const LeafLayout & getLayout() const noexcept
Get the leaf layout.
LeafLayout _leaf_layout
For internal use only.
static bool checkLeafLayout(const CodecIndex &codec_index, ddl::DataRepresentation rep)
For internal use only.
static bool convertToLeafLayout(const CodecIndex &codec_index, LeafLayout &leaf_layout, ddl::DataRepresentation rep, throw_error< true >)
For internal use only.
static bool checkTypeSize(const CodecIndex &codec_index, ddl::DataRepresentation rep, bool exact_check, throw_error< true >)
For internal use only.
static bool convertToLeafLayout(const CodecIndex &codec_index, LeafLayout &leaf_layout, ddl::DataRepresentation rep)
Retrieves a valid, small, 8-bytes LeafLayout from a CodecIndex.
LeafCodecIndex()=delete
no CTOR
LeafCodecIndex(const CodecIndex &codec_index, ddl::DataRepresentation rep=DataRepresentation::deserialized)
CTOR.
static bool checkTypeSize(const CodecIndex &codec_index, ddl::DataRepresentation rep, bool exact_check_on_serialized, throw_error< false >) noexcept
For internal use only.
static ByteOrder getPlatformDefault()
Get the current Platform Byteorder.
Implementation of the CodecIndex.
Definition of Data Representation header for Codec API.
void writeBits(void *data, size_t data_size, size_t bit_offset, size_t bit_size, a_util::memory::Endianess byte_order, const SourceValueType &source_value)
Write the bits of the element to the data area after conversion from source_value.
TargetValueType readBits(const void *data, size_t data_size, size_t bit_offset, size_t bit_size, a_util::memory::Endianess byte_order)
Read the bits from a data area and converts this value to the TargetValueType.
ValueType readDeserializedBytes(const void *data, const size_t &data_size, const LeafLayout &layout)
Retrieves a value from the given data area with the layout information of the layout.
void writeBytes(void *data, const size_t &data_size, uint32_t byte_pos, const SourceValueType &source_value)
Writes the value of source_value to the data area after conversion to the elements ElementValueType.
TargetValueType readBytes(const void *data, const size_t &data_size, uint32_t byte_pos)
Read the bytes from a data area and converts this value to the TargetValueType.
void writeSerializedBits(void *data, const size_t &data_size, const LeafLayout &layout, const ValueType &value)
Writes a value to the given data area with the layout information of the layout.
ValueType readSerializedBits(const void *data, const size_t &data_size, const LeafLayout &layout)
Retrieves a value from the given data area with the layout information of the layout.
void writeDeserializedBytes(void *data, const size_t &data_size, const LeafLayout &layout, const ValueType &value)
Writes a value to the given data area with the layout information of the layout.
cString to_string(const tResult &i_oResult, eResultFormatFlags i_eFormatFlags=eResultFormatFlags::RFF_DisableNone, const tChar *i_strFormat=nullptr)
Copy all information of an assigned result object to a (formatted) string.
@ cet_float
Variant type is float.
@ cet_int16
Variant type is std::int16_t.
@ cet_int8
Variant type is std::int8_t.
@ cet_uint64
Variant type is std::uint64_t.
@ cet_uint8
Variant type is std::uint8_t.
@ cet_uint32
Variant type is std::uint32_t.
@ cet_sub_codec
type marks a subcodec/substructure with children
@ cet_bool
Variant type is bool.
@ cet_uint16
Variant type is std::uint16_t.
@ cet_int32
Variant type is std::int32_t.
@ cet_int64
Variant type is std::int64_t.
@ cet_empty
Variant type is empty.
@ cet_user_type
type marks a user defined type
@ cet_double
Variant type is double.
LeafDataRepresentation
LeafLayout data representation flags.
@ serialized_le
first bit is set second bit is not set for serialized data representation in little endianess of the ...
@ deserialized
first bit is zero for deserialized data representation of the LeafCodecIndex::data_flags
@ serialized_be
first and second bit is set for serialized data representation in big endianess of the LeafCodecIndex...
@ serialized
first bit is set for serialized data representation of the LeafCodecIndex::data_flags
LeafElementType
Valid ElementTypes for the LeafLayout.
@ let_uint64
LeafElementType type is std::uint64_t.
@ let_uint8
LeafElementType type is std::uint8_t.
@ let_double
LeafElementType type is double.
@ let_int8
LeafElementType type is std::int8_t.
@ let_int64
LeafElementType type is std::int64_t.
@ let_float
LeafElementType type is float.
@ let_int32
LeafElementType type is std::int32_t.
@ let_uint32
LeafElementType type is std::uint32_t.
@ let_bool
LeafElementType type is bool.
@ let_uint16
LeafElementType type is std::uint16_t.
@ let_int16
LeafElementType type is std::int16_t.
Utility for the Neutrino gcc5 compiler which has really no std::to_string implementation!
small leaf layout information to access codec data very fast.
static constexpr size_t _max_byte_size
max type byte size of an element (usually this can not be reached for standard data types)
LeafElementType element_type
type of the value. accept all valid leaf types, except user defined types
uint8_t bit_size
type bit size of an element for serialized or deserialized
uint8_t bit_pos
bit position of the element for serialized only
uint8_t data_flags
flags of the described layout
static constexpr size_t _max_bit_size
max type bit size of an element (usually this can not be reached for standard data types)
uint32_t byte_pos
byte position of the element for serialized or deserialized
static constexpr uint32_t _invalid_pos
invalid position for byte_pos
Value getter to retrieve the current value of the given element as a ValueType if supported from a da...
static ValueType getValue(const void *data, const size_t data_size, const LeafLayout &leaf_layout)
Returns the current value of the given element as a ValueType if supported.
Value setter to set the current value of the given element from a type ValueType if supported.
static void setValue(void *data, const size_t data_size, const LeafLayout &leaf_layout, const ValueType &value)
Sets the current value if the given element as a ValueType if supported.
static bool convert(ElementValueType &, const SourceValueType &)
Should convert a value of SourceValueType to a element_value of type ElementValueType,...
Converter to convert from a value of SourceValueType to a value of ElementValueType.
static bool convert(ElementValueType &element_value, const SourceValueType &value)
Converts a value of SourceValueType to a element_value of type ElementValueType.
static TargetValueType convert(const ElementValueType &)
Should convert a value of ElementValueType to a value of type ElementValueType, but this specialized ...
Converter to convert a value of ElementValueType to a value of TargetValueType.
static TargetValueType convert(const ElementValueType &element_value)
Converts a element_value to as value of type TargetValueType.
Class and function templates extending std type traits functionality.
Raw memory related functionality.