Advertisement
Guest User

Untitled

a guest
Jul 3rd, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 12.26 KB | None | 0 0
  1. //
  2. // This is an AUTO-GENERATED UAVCAN DSDL data type implementation. Curious? See https://opencyphal.org.
  3. // You shouldn't attempt to edit this file.
  4. //
  5. // Checking this file under version control is not recommended since metadata in this header will change for each
  6. // build invocation. TODO: add --reproducible option to prevent any volatile metadata from being generated.
  7. //
  8. // Generator:     nunavut-1.8.2 (serialization was enabled)
  9. // Source file:   /workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl
  10. // Generated at:  2022-07-03 13:42:58.422535 UTC
  11. // Is deprecated: no
  12. // Fixed port-ID: None
  13. // Full name:     uavcan.primitive.Unstructured
  14. // Type Version:  1.0
  15. // Support
  16. //    Support Namespace: nunavut.lang.cpp.support
  17. //    Support Version:   (1, 0, 0)
  18. // Template Set (package)
  19. //    priority: 0
  20. //    package:  nunavut.lang.cpp.templates
  21. //    version:  (1, 0, 0)
  22. // Platform
  23. //     python_implementation:  CPython
  24. //     python_version:  3.8.10
  25. //     python_release_level:  final
  26. //     python_build:  ('default', 'Mar 15 2022 12:22:08')
  27. //     python_compiler:  GCC 9.4.0
  28. //     python_revision:  
  29. //     python_xoptions:  {}
  30. //     runtime_platform:  Linux-5.13.0-52-generic-x86_64-with-glibc2.29
  31. // Language Options
  32. //     target_endianness:  any
  33. //     omit_float_serialization_support:  False
  34. //     enable_serialization_asserts:  True
  35. //     enable_override_variable_array_capacity:  False
  36. //     std:  c++14
  37. //     variable_array_type:  std::vector<{TYPE},std::allocator<{TYPE}>>
  38. //     cast_format:  static_cast<{type}>({value})
  39. //     enable_allocator_support:  False
  40. // Uses Language Features
  41. //     Uses std_variant:no
  42. #ifndef UAVCAN_PRIMITIVE_UNSTRUCTURED_1_0_HPP_INCLUDED
  43. #define UAVCAN_PRIMITIVE_UNSTRUCTURED_1_0_HPP_INCLUDED
  44.  
  45. #include "nunavut/support/serialization.hpp"
  46. #include "nunavut/support/variable_length_array.hpp"
  47. #include <cstdint>
  48. #include <vector>
  49.  
  50. namespace uavcan
  51. {
  52. namespace primitive
  53. {
  54. // +-------------------------------------------------------------------------------------------------------------------+
  55. // | LANGUAGE OPTION ASSERTIONS
  56. // |    These static assertions ensure that the header is being used with
  57. // | Nunavut C++ serialization support that is compatible with the language
  58. // | options in effect when that support code was generated.
  59. // +-------------------------------------------------------------------------------------------------------------------+
  60. static_assert( nunavut::support::options::target_endianness == 1693710260,
  61.               "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
  62.               "is trying to use a serialization library that was compiled with "
  63.               "different language options. This is dangerous and therefore not "
  64.               "allowed." );
  65. static_assert( nunavut::support::options::omit_float_serialization_support == 0,
  66.               "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
  67.               "is trying to use a serialization library that was compiled with "
  68.               "different language options. This is dangerous and therefore not "
  69.               "allowed." );
  70. static_assert( nunavut::support::options::enable_serialization_asserts == 1,
  71.               "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
  72.               "is trying to use a serialization library that was compiled with "
  73.               "different language options. This is dangerous and therefore not "
  74.               "allowed." );
  75. static_assert( nunavut::support::options::enable_override_variable_array_capacity == 0,
  76.               "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
  77.               "is trying to use a serialization library that was compiled with "
  78.               "different language options. This is dangerous and therefore not "
  79.               "allowed." );
  80. static_assert( nunavut::support::options::std == 3161622713,
  81.               "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
  82.               "is trying to use a serialization library that was compiled with "
  83.               "different language options. This is dangerous and therefore not "
  84.               "allowed." );
  85. static_assert( nunavut::support::options::variable_array_type == 991883379,
  86.               "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
  87.               "is trying to use a serialization library that was compiled with "
  88.               "different language options. This is dangerous and therefore not "
  89.               "allowed." );
  90. static_assert( nunavut::support::options::cast_format == 1407868567,
  91.               "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
  92.               "is trying to use a serialization library that was compiled with "
  93.               "different language options. This is dangerous and therefore not "
  94.               "allowed." );
  95. static_assert( nunavut::support::options::enable_allocator_support == 0,
  96.               "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
  97.               "is trying to use a serialization library that was compiled with "
  98.               "different language options. This is dangerous and therefore not "
  99.               "allowed." );
  100.  
  101.  
  102. // +-------------------------------------------------------------------------------------------------------------------+
  103. // | This implementation uses a minimal variant implementation that is forward-compatible with the same types generated
  104. // | using the C++17 variant type in the standard library. This minimal variant implementation is limited in the
  105. // | following ways:
  106. // |    1. Supports only emplace and get_if.
  107. // |    2. Only support access by index (see the IndexOf property of the VariantType).
  108. // |    3. This object cannot be copy-constructed nor move-constructed.
  109. // |    4. There is an O(n) lookup in this object's destructor and in the
  110. // |       emplace method.
  111. // |
  112. // | The C++17 version of this object will define the same emplace and get_if wrappers so code written against this
  113. // | version will be fully-forward compatible, but the C++17 version exposes the variant type directly allowing full
  114. // | use of that standard library feature – it is therefore not backwards-compatible.
  115. // +-------------------------------------------------------------------------------------------------------------------+
  116. ///
  117. /// An unstructured collection of bytes, e.g., raw binary image.
  118. ///
  119. struct Unstructured_1_0 final
  120. {
  121.     // +---------------------------------------------------------------------------------------------------------------+
  122.     // | PORT IDENTIFIERS
  123.     // +---------------------------------------------------------------------------------------------------------------+
  124.     /// This type does not have a fixed port-ID. See https://forum.opencyphal.org/t/choosing-message-and-service-ids/889
  125.     static constexpr bool HasFixedPortID = false;
  126.  
  127.     static constexpr bool IsServiceType = false;
  128.  
  129.     /// Extent is the minimum amount of memory required to hold any serialized representation of any compatible
  130.     /// version of the data type; or, on other words, it is the the maximum possible size of received objects of this type.
  131.     /// The size is specified in bytes (rather than bits) because by definition, extent is an integer number of bytes long.
  132.     /// When allocating a deserialization (RX) buffer for this data type, it should be at least extent bytes large.
  133.     /// When allocating a serialization (TX) buffer, it is safe to use the size of the largest serialized representation
  134.     /// instead of the extent because it provides a tighter bound of the object size; it is safe because the concrete type
  135.     /// is always known during serialization (unlike deserialization). If not sure, use extent everywhere.
  136.  
  137.     static constexpr std::size_t EXTENT_BYTES                    =258UL;
  138.     static constexpr std::size_t SERIALIZATION_BUFFER_SIZE_BYTES =258UL;
  139.     static_assert(EXTENT_BYTES >= SERIALIZATION_BUFFER_SIZE_BYTES, "Internal constraint violation");
  140.     static_assert(EXTENT_BYTES < (std::numeric_limits<std::size_t>::max() /8U), "This message is too large to be handled by current types!");
  141.    
  142.     // +----------------------------------------------------------------------+
  143.     // | FIELDS
  144.     // +----------------------------------------------------------------------+
  145.    
  146.     std::vector<std::uint8_t,std::allocator<std::uint8_t>> value;
  147.  
  148.     nunavut::support::SerializeResult
  149.     serialize(nunavut::support::bitspan out_buffer) const
  150.     {
  151.         const std::size_t capacity_bits = out_buffer.size();
  152.         if ((static_cast<std::size_t>(capacity_bits)) < 2064UL)
  153.         {
  154.             return -nunavut::support::Error::SERIALIZATION_BUFFER_TOO_SMALL;
  155.         }
  156.         // Notice that fields that are not an integer number of bytes long may overrun the space allocated for them
  157.         // in the serialization buffer up to the next byte boundary. This is by design and is guaranteed to be safe.
  158.         NUNAVUT_ASSERT(out_buffer.offset_alings_to_byte());
  159.         {   // saturated uint8[<=256] value
  160.             NUNAVUT_ASSERT(out_buffer.offset_alings_to_byte());
  161.             NUNAVUT_ASSERT(2064ULL <= out_buffer.size());
  162.             if (value.size() > 256)
  163.             {
  164.                 return -nunavut::support::Error::REPRESENTATION_BAD_ARRAY_LENGTH;
  165.             }
  166.             // Array length prefix: truncated uint16
  167.             const auto _result3_ = out_buffer.setUxx(value.size(), 16U);
  168.             if(not _result3_){
  169.                 return -_result3_.error();
  170.             }
  171.             out_buffer.add_offset(16U);
  172.             NUNAVUT_ASSERT(out_buffer.offset_alings_to_byte());
  173.             for (size_t _index2_ = 0U; _index2_ < value.size(); ++_index2_)
  174.             {
  175.                 NUNAVUT_ASSERT(out_buffer.offset_alings_to_byte());
  176.                 NUNAVUT_ASSERT(8ULL <= out_buffer.size());
  177.                 // Saturation code not emitted -- native representation matches the serialized representation.
  178.                 const auto _result3_ = out_buffer.setUxx(value[_index2_], 8U);
  179.                 if(not _result3_){
  180.                     return -_result3_.error();
  181.                 }
  182.                 out_buffer.add_offset(8U);
  183.             }
  184.         }
  185.         {
  186.             const auto _result0_ = out_buffer.padAndMoveToAlignment(8U);
  187.             if(not _result0_){
  188.                 return -_result0_.error();
  189.             }
  190.         }
  191.         // It is assumed that we know the exact type of the serialized entity, hence we expect the size to match.
  192.         NUNAVUT_ASSERT(out_buffer.offset() >= 16ULL);
  193.         NUNAVUT_ASSERT(out_buffer.offset() <= 2064ULL);
  194.         NUNAVUT_ASSERT(out_buffer.offset_alings_to_byte());
  195.         return out_buffer.offset_bytes_ceil();
  196.     }
  197.  
  198.     nunavut::support::SerializeResult
  199.     deserialize(nunavut::support::const_bitspan in_buffer)
  200.     {
  201.         const auto capacity_bits = in_buffer.size();
  202.         // saturated uint8[<=256] value
  203.         NUNAVUT_ASSERT(in_buffer.offset_alings_to_byte());
  204.         {
  205.             // Array length prefix: truncated uint16
  206.         const std::uint16_t _size0_ = in_buffer.getU16(16U);
  207.         in_buffer.add_offset(16U);
  208.             if ( _size0_ > 256U)
  209.             {
  210.                 return -nunavut::support::Error::REPRESENTATION_BAD_ARRAY_LENGTH;
  211.             }
  212.             value.resize(_size0_);
  213.         NUNAVUT_ASSERT(in_buffer.offset_alings_to_byte());
  214.             for (size_t _index5_ = 0U; _index5_ < value.size(); ++_index5_)
  215.             {
  216.                 NUNAVUT_ASSERT(in_buffer.offset_alings_to_byte());
  217.             value[_index5_] = in_buffer.getU8(8U);
  218.             in_buffer.add_offset(8U);
  219.             }
  220.         }
  221.         in_buffer.align_offset_to<8U>();
  222.         NUNAVUT_ASSERT(in_buffer.offset_alings_to_byte());
  223.         auto _bits_got_ = std::min<std::size_t>(in_buffer.offset(), capacity_bits);
  224.         NUNAVUT_ASSERT(capacity_bits >= _bits_got_);
  225.         return { static_cast<std::size_t>(_bits_got_ / 8U) };
  226.     }
  227. };
  228.  
  229. } // namespace primitive
  230. } // namespace uavcan
  231.  
  232. #endif // UAVCAN_PRIMITIVE_UNSTRUCTURED_1_0_HPP_INCLUDED
  233.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement