Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // This is an AUTO-GENERATED UAVCAN DSDL data type implementation. Curious? See https://opencyphal.org.
- // You shouldn't attempt to edit this file.
- //
- // Checking this file under version control is not recommended since metadata in this header will change for each
- // build invocation. TODO: add --reproducible option to prevent any volatile metadata from being generated.
- //
- // Generator: nunavut-1.8.2 (serialization was enabled)
- // Source file: /workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl
- // Generated at: 2022-07-03 13:42:58.422535 UTC
- // Is deprecated: no
- // Fixed port-ID: None
- // Full name: uavcan.primitive.Unstructured
- // Type Version: 1.0
- // Support
- // Support Namespace: nunavut.lang.cpp.support
- // Support Version: (1, 0, 0)
- // Template Set (package)
- // priority: 0
- // package: nunavut.lang.cpp.templates
- // version: (1, 0, 0)
- // Platform
- // python_implementation: CPython
- // python_version: 3.8.10
- // python_release_level: final
- // python_build: ('default', 'Mar 15 2022 12:22:08')
- // python_compiler: GCC 9.4.0
- // python_revision:
- // python_xoptions: {}
- // runtime_platform: Linux-5.13.0-52-generic-x86_64-with-glibc2.29
- // Language Options
- // target_endianness: any
- // omit_float_serialization_support: False
- // enable_serialization_asserts: True
- // enable_override_variable_array_capacity: False
- // std: c++14
- // variable_array_type: std::vector<{TYPE},std::allocator<{TYPE}>>
- // cast_format: static_cast<{type}>({value})
- // enable_allocator_support: False
- // Uses Language Features
- // Uses std_variant:no
- #ifndef UAVCAN_PRIMITIVE_UNSTRUCTURED_1_0_HPP_INCLUDED
- #define UAVCAN_PRIMITIVE_UNSTRUCTURED_1_0_HPP_INCLUDED
- #include "nunavut/support/serialization.hpp"
- #include "nunavut/support/variable_length_array.hpp"
- #include <cstdint>
- #include <vector>
- namespace uavcan
- {
- namespace primitive
- {
- // +-------------------------------------------------------------------------------------------------------------------+
- // | LANGUAGE OPTION ASSERTIONS
- // | These static assertions ensure that the header is being used with
- // | Nunavut C++ serialization support that is compatible with the language
- // | options in effect when that support code was generated.
- // +-------------------------------------------------------------------------------------------------------------------+
- static_assert( nunavut::support::options::target_endianness == 1693710260,
- "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
- "is trying to use a serialization library that was compiled with "
- "different language options. This is dangerous and therefore not "
- "allowed." );
- static_assert( nunavut::support::options::omit_float_serialization_support == 0,
- "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
- "is trying to use a serialization library that was compiled with "
- "different language options. This is dangerous and therefore not "
- "allowed." );
- static_assert( nunavut::support::options::enable_serialization_asserts == 1,
- "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
- "is trying to use a serialization library that was compiled with "
- "different language options. This is dangerous and therefore not "
- "allowed." );
- static_assert( nunavut::support::options::enable_override_variable_array_capacity == 0,
- "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
- "is trying to use a serialization library that was compiled with "
- "different language options. This is dangerous and therefore not "
- "allowed." );
- static_assert( nunavut::support::options::std == 3161622713,
- "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
- "is trying to use a serialization library that was compiled with "
- "different language options. This is dangerous and therefore not "
- "allowed." );
- static_assert( nunavut::support::options::variable_array_type == 991883379,
- "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
- "is trying to use a serialization library that was compiled with "
- "different language options. This is dangerous and therefore not "
- "allowed." );
- static_assert( nunavut::support::options::cast_format == 1407868567,
- "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
- "is trying to use a serialization library that was compiled with "
- "different language options. This is dangerous and therefore not "
- "allowed." );
- static_assert( nunavut::support::options::enable_allocator_support == 0,
- "/workspaces/project/dsdl/public_regulated_data_types/uavcan/primitive/Unstructured.1.0.dsdl "
- "is trying to use a serialization library that was compiled with "
- "different language options. This is dangerous and therefore not "
- "allowed." );
- // +-------------------------------------------------------------------------------------------------------------------+
- // | This implementation uses a minimal variant implementation that is forward-compatible with the same types generated
- // | using the C++17 variant type in the standard library. This minimal variant implementation is limited in the
- // | following ways:
- // | 1. Supports only emplace and get_if.
- // | 2. Only support access by index (see the IndexOf property of the VariantType).
- // | 3. This object cannot be copy-constructed nor move-constructed.
- // | 4. There is an O(n) lookup in this object's destructor and in the
- // | emplace method.
- // |
- // | The C++17 version of this object will define the same emplace and get_if wrappers so code written against this
- // | version will be fully-forward compatible, but the C++17 version exposes the variant type directly allowing full
- // | use of that standard library feature – it is therefore not backwards-compatible.
- // +-------------------------------------------------------------------------------------------------------------------+
- ///
- /// An unstructured collection of bytes, e.g., raw binary image.
- ///
- struct Unstructured_1_0 final
- {
- // +---------------------------------------------------------------------------------------------------------------+
- // | PORT IDENTIFIERS
- // +---------------------------------------------------------------------------------------------------------------+
- /// This type does not have a fixed port-ID. See https://forum.opencyphal.org/t/choosing-message-and-service-ids/889
- static constexpr bool HasFixedPortID = false;
- static constexpr bool IsServiceType = false;
- /// Extent is the minimum amount of memory required to hold any serialized representation of any compatible
- /// version of the data type; or, on other words, it is the the maximum possible size of received objects of this type.
- /// The size is specified in bytes (rather than bits) because by definition, extent is an integer number of bytes long.
- /// When allocating a deserialization (RX) buffer for this data type, it should be at least extent bytes large.
- /// When allocating a serialization (TX) buffer, it is safe to use the size of the largest serialized representation
- /// instead of the extent because it provides a tighter bound of the object size; it is safe because the concrete type
- /// is always known during serialization (unlike deserialization). If not sure, use extent everywhere.
- static constexpr std::size_t EXTENT_BYTES =258UL;
- static constexpr std::size_t SERIALIZATION_BUFFER_SIZE_BYTES =258UL;
- static_assert(EXTENT_BYTES >= SERIALIZATION_BUFFER_SIZE_BYTES, "Internal constraint violation");
- static_assert(EXTENT_BYTES < (std::numeric_limits<std::size_t>::max() /8U), "This message is too large to be handled by current types!");
- // +----------------------------------------------------------------------+
- // | FIELDS
- // +----------------------------------------------------------------------+
- std::vector<std::uint8_t,std::allocator<std::uint8_t>> value;
- nunavut::support::SerializeResult
- serialize(nunavut::support::bitspan out_buffer) const
- {
- const std::size_t capacity_bits = out_buffer.size();
- if ((static_cast<std::size_t>(capacity_bits)) < 2064UL)
- {
- return -nunavut::support::Error::SERIALIZATION_BUFFER_TOO_SMALL;
- }
- // Notice that fields that are not an integer number of bytes long may overrun the space allocated for them
- // in the serialization buffer up to the next byte boundary. This is by design and is guaranteed to be safe.
- NUNAVUT_ASSERT(out_buffer.offset_alings_to_byte());
- { // saturated uint8[<=256] value
- NUNAVUT_ASSERT(out_buffer.offset_alings_to_byte());
- NUNAVUT_ASSERT(2064ULL <= out_buffer.size());
- if (value.size() > 256)
- {
- return -nunavut::support::Error::REPRESENTATION_BAD_ARRAY_LENGTH;
- }
- // Array length prefix: truncated uint16
- const auto _result3_ = out_buffer.setUxx(value.size(), 16U);
- if(not _result3_){
- return -_result3_.error();
- }
- out_buffer.add_offset(16U);
- NUNAVUT_ASSERT(out_buffer.offset_alings_to_byte());
- for (size_t _index2_ = 0U; _index2_ < value.size(); ++_index2_)
- {
- NUNAVUT_ASSERT(out_buffer.offset_alings_to_byte());
- NUNAVUT_ASSERT(8ULL <= out_buffer.size());
- // Saturation code not emitted -- native representation matches the serialized representation.
- const auto _result3_ = out_buffer.setUxx(value[_index2_], 8U);
- if(not _result3_){
- return -_result3_.error();
- }
- out_buffer.add_offset(8U);
- }
- }
- {
- const auto _result0_ = out_buffer.padAndMoveToAlignment(8U);
- if(not _result0_){
- return -_result0_.error();
- }
- }
- // It is assumed that we know the exact type of the serialized entity, hence we expect the size to match.
- NUNAVUT_ASSERT(out_buffer.offset() >= 16ULL);
- NUNAVUT_ASSERT(out_buffer.offset() <= 2064ULL);
- NUNAVUT_ASSERT(out_buffer.offset_alings_to_byte());
- return out_buffer.offset_bytes_ceil();
- }
- nunavut::support::SerializeResult
- deserialize(nunavut::support::const_bitspan in_buffer)
- {
- const auto capacity_bits = in_buffer.size();
- // saturated uint8[<=256] value
- NUNAVUT_ASSERT(in_buffer.offset_alings_to_byte());
- {
- // Array length prefix: truncated uint16
- const std::uint16_t _size0_ = in_buffer.getU16(16U);
- in_buffer.add_offset(16U);
- if ( _size0_ > 256U)
- {
- return -nunavut::support::Error::REPRESENTATION_BAD_ARRAY_LENGTH;
- }
- value.resize(_size0_);
- NUNAVUT_ASSERT(in_buffer.offset_alings_to_byte());
- for (size_t _index5_ = 0U; _index5_ < value.size(); ++_index5_)
- {
- NUNAVUT_ASSERT(in_buffer.offset_alings_to_byte());
- value[_index5_] = in_buffer.getU8(8U);
- in_buffer.add_offset(8U);
- }
- }
- in_buffer.align_offset_to<8U>();
- NUNAVUT_ASSERT(in_buffer.offset_alings_to_byte());
- auto _bits_got_ = std::min<std::size_t>(in_buffer.offset(), capacity_bits);
- NUNAVUT_ASSERT(capacity_bits >= _bits_got_);
- return { static_cast<std::size_t>(_bits_got_ / 8U) };
- }
- };
- } // namespace primitive
- } // namespace uavcan
- #endif // UAVCAN_PRIMITIVE_UNSTRUCTURED_1_0_HPP_INCLUDED
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement