2020-12-31 12:38:12 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2020, Liav A. <liavalb@hotmail.co.il>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-12-31 12:38:12 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Array.h>
|
|
|
|
#include <AK/ByteBuffer.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <AK/Types.h>
|
|
|
|
|
2022-02-15 21:55:53 +03:00
|
|
|
#ifdef KERNEL
|
2023-02-24 21:10:59 +03:00
|
|
|
# include <Kernel/Library/KString.h>
|
2022-02-15 21:55:53 +03:00
|
|
|
#else
|
2022-12-19 01:24:02 +03:00
|
|
|
# include <AK/String.h>
|
2022-02-15 21:55:53 +03:00
|
|
|
#endif
|
|
|
|
|
2020-12-31 12:38:12 +03:00
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
class UUID {
|
|
|
|
public:
|
2022-01-28 21:21:40 +03:00
|
|
|
enum class Endianness {
|
|
|
|
Mixed,
|
|
|
|
Little
|
|
|
|
};
|
|
|
|
|
2021-09-16 09:20:31 +03:00
|
|
|
UUID() = default;
|
2020-12-31 12:38:12 +03:00
|
|
|
UUID(Array<u8, 16> uuid_buffer);
|
2022-01-28 21:21:40 +03:00
|
|
|
UUID(StringView, Endianness endianness = Endianness::Little);
|
2021-01-11 02:29:28 +03:00
|
|
|
~UUID() = default;
|
2020-12-31 12:38:12 +03:00
|
|
|
|
2022-10-21 16:53:20 +03:00
|
|
|
bool operator==(const UUID&) const = default;
|
2020-12-31 12:38:12 +03:00
|
|
|
|
2022-02-15 21:55:53 +03:00
|
|
|
#ifdef KERNEL
|
|
|
|
ErrorOr<NonnullOwnPtr<Kernel::KString>> to_string() const;
|
|
|
|
#else
|
2022-12-19 01:24:02 +03:00
|
|
|
ErrorOr<String> to_string() const;
|
2022-02-15 21:55:53 +03:00
|
|
|
#endif
|
2020-12-31 12:38:12 +03:00
|
|
|
bool is_zero() const;
|
|
|
|
|
|
|
|
private:
|
2022-01-28 21:21:40 +03:00
|
|
|
void convert_string_view_to_little_endian_uuid(StringView);
|
|
|
|
void convert_string_view_to_mixed_endian_uuid(StringView);
|
2020-12-31 12:38:12 +03:00
|
|
|
|
|
|
|
Array<u8, 16> m_uuid_buffer {};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-11-26 14:18:30 +03:00
|
|
|
#if USING_AK_GLOBALLY
|
2020-12-31 12:38:12 +03:00
|
|
|
using AK::UUID;
|
2022-11-26 14:18:30 +03:00
|
|
|
#endif
|