Skip to content

Commit

Permalink
make report selector endianness-invariant
Browse files Browse the repository at this point in the history
  • Loading branch information
benedekkupper committed Nov 17, 2023
1 parent 2a8d1d5 commit e0ddde7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions hid-rp/hid/report.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#ifndef __HID_REPORT_HPP_
#define __HID_REPORT_HPP_

#include <cstdint>
#include <array>
#include <limits>
#include <type_traits>
#include <variant>
Expand Down Expand Up @@ -59,23 +59,23 @@ namespace hid
{
public:
constexpr selector(report::type t, report::id i = 0)
: storage_((static_cast<std::uint16_t>(t) << 8) | static_cast<std::uint16_t>(i))
: storage_{ static_cast<std::uint8_t>(i), static_cast<std::uint8_t>(t) }
{}
constexpr explicit selector(std::uint16_t raw)
: storage_(raw)
: storage_{ static_cast<std::uint8_t>(raw), static_cast<std::uint8_t>(raw >> 8) }
{}
constexpr selector()
{}
constexpr report::type type() const { return static_cast<report::type>(storage_ >> 8); }
constexpr report::id id() const { return report::id(storage_); }
constexpr bool valid() const { return static_cast<std::uint8_t>(type()) > 0; }
constexpr report::type type() const { return static_cast<report::type>(storage_[1]); }
constexpr report::id id() const { return report::id(storage_[0]); }
constexpr bool valid() const { return storage_[1] > 0; }
constexpr void clear() { *this = selector(); }

constexpr bool operator ==(const selector& rhs) const = default;
constexpr bool operator !=(const selector& rhs) const = default;

private:
std::uint16_t storage_ = 0;
std::array<std::uint8_t, 2> storage_;
};

struct id_base
Expand Down

0 comments on commit e0ddde7

Please sign in to comment.