Skip to content

Commit

Permalink
Make Message operator== inline
Browse files Browse the repository at this point in the history
  • Loading branch information
tuokri committed Nov 21, 2023
1 parent 64d1c15 commit 57b99e7
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions include/umb/message.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class Message
*
* @return Serialized message bytes.
*/
[[nodiscard]] virtual std::vector<byte> to_bytes() const = 0;
[[nodiscard]] virtual std::vector <byte> to_bytes() const = 0;

/**
* Serialize message to UMB wire format. \bytes should be
Expand All @@ -50,7 +50,7 @@ class Message
* @return true if \bytes contains valid UMB wire format
* bytes of this message.
*/
[[nodiscard]] virtual bool to_bytes(std::span<byte> bytes) const = 0;
[[nodiscard]] virtual bool to_bytes(std::span <byte> bytes) const = 0;

/**
* Initialize message from \bytes span containing valid
Expand All @@ -73,15 +73,19 @@ class Message
[[nodiscard]] virtual size_t serialized_size() const = 0;

// TODO: reconsider this API.
[[nodiscard]] constexpr virtual uint16_t type() const noexcept = 0;
[[nodiscard]] constexpr virtual uint16_t

type() const

noexcept = 0;

protected:
[[nodiscard]] virtual bool is_equal(const Message& msg) const = 0;

friend bool operator==(const Message&, const Message&);
friend inline bool operator==(const Message&, const Message&);
};

bool operator==(const Message& lhs, const Message& rhs)
inline bool operator==(const Message& lhs, const Message& rhs)
{
return typeid(lhs) == typeid(rhs) && lhs.is_equal(rhs);
}
Expand Down

0 comments on commit 57b99e7

Please sign in to comment.