Skip to content

Conversation

@HTRamsey
Copy link
Contributor

Or alternatively:

  template <typename T>
  static T deserialize(const std::vector<uint8_t>::const_iterator& backing_start,
                       const std::vector<uint8_t>::const_iterator& backing_end,
                       int offset,
                       int array_offset)
  {
    T v;
    const std::ptrdiff_t total_offset =
        static_cast<std::ptrdiff_t>(offset) +
        (static_cast<std::ptrdiff_t>(array_offset) * sizeof(T));

    if (backing_start > backing_end ||
        backing_end - backing_start < sizeof(v) + total_offset) {
      throw AccessException("Unexpected data type size");
    }

    const uint8_t* src = &*(backing_start + total_offset);
    std::memcpy(&v, src, sizeof(v));

    return v;
  }

Copy link
Member

@bkueng bkueng left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way is fine with me, thanks

@bkueng bkueng merged commit 4153a32 into PX4:main Jun 19, 2025
2 checks passed
@HTRamsey HTRamsey deleted the dev-gcc-warning branch June 19, 2025 09:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants