uuid.cpp 1003 B

123456789101112131415161718192021222324252627282930313233
  1. // Copyright 2018 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include <random>
  5. #include <fmt/format.h>
  6. #include "common/uuid.h"
  7. namespace Common {
  8. UUID UUID::Generate() {
  9. std::random_device device;
  10. std::mt19937 gen(device());
  11. std::uniform_int_distribution<u64> distribution(1, std::numeric_limits<u64>::max());
  12. return UUID{distribution(gen), distribution(gen)};
  13. }
  14. std::string UUID::Format() const {
  15. return fmt::format("0x{:016X}{:016X}", uuid[1], uuid[0]);
  16. }
  17. std::string UUID::FormatSwitch() const {
  18. std::array<u8, 16> s{};
  19. std::memcpy(s.data(), uuid.data(), sizeof(u128));
  20. return fmt::format("{:02x}{:02x}{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{:02x}-{:02x}{"
  21. ":02x}{:02x}{:02x}{:02x}{:02x}",
  22. s[0], s[1], s[2], s[3], s[4], s[5], s[6], s[7], s[8], s[9], s[10], s[11],
  23. s[12], s[13], s[14], s[15]);
  24. }
  25. } // namespace Common