//----------------------------------------------------------------------------- // ___ __ _ _ // / _ \__ _ _ __ ___ ___ / /(_)_ __ | | __ // / /_)/ _` | '__/ __|/ _ \/ / | | '_ \| |/ / // / ___/ (_| | | \__ \ __/ /__| | | | | < // \/ \__,_|_| |___/\___\____/_|_| |_|_|\_\ . // //----------------------------------------------------------------------------- // Author: Kurt Sassenrath // Module: proto // // Session ID. Used as a handle to access an existing user session, which can // also be used to share parse data without any linking of users. // // Copyright (c) 2023 Kurt Sassenrath. // // License TBD. //----------------------------------------------------------------------------- #ifndef session_id_6598f9bae1cbb501 #define session_id_6598f9bae1cbb501 #include #include #include namespace parselink { namespace proto { struct session_id { public: session_id() noexcept; // Not the intended way to build a session id. Ideally, they'll be randomly // generated. explicit constexpr session_id(std::array const& v) noexcept { std::copy(v.begin(), v.end(), bytes_.begin()); } [[nodiscard]] constexpr auto operator<=>( session_id const& other) const noexcept { return bytes_ <=> other.bytes_; } [[nodiscard]] constexpr auto operator==( session_id const& other) const noexcept { return bytes_ == other.bytes_; } [[nodiscard]] constexpr auto operator<=>( std::span other) const noexcept { return std::lexicographical_compare_three_way(bytes_.begin(), bytes_.end(), other.begin(), other.end(), std::compare_three_way()); } [[nodiscard]] constexpr auto operator==( std::span other) const noexcept { return std::equal(bytes_.begin(), bytes_.end(), other.begin(), other.end()); } constexpr std::span raw() const noexcept { return bytes_; } private: std::array bytes_; }; } // namespace proto } // namespace parselink #endif // session_id_6598f9bae1cbb501