UUID.cpp 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  3. * SPDX-License-Identifier: Apache-2.0.
  4. */
  5. #include <aws/crt/UUID.h>
  6. namespace Aws
  7. {
  8. namespace Crt
  9. {
  10. UUID::UUID() noexcept : m_good(false)
  11. {
  12. if (aws_uuid_init(&m_uuid) == AWS_OP_SUCCESS)
  13. {
  14. m_good = true;
  15. }
  16. }
  17. UUID::UUID(const String &str) noexcept : m_good(false)
  18. {
  19. auto strCur = aws_byte_cursor_from_c_str(str.c_str());
  20. if (aws_uuid_init_from_str(&m_uuid, &strCur) == AWS_OP_SUCCESS)
  21. {
  22. m_good = true;
  23. }
  24. }
  25. UUID &UUID::operator=(const String &str) noexcept
  26. {
  27. *this = UUID(str);
  28. return *this;
  29. }
  30. bool UUID::operator==(const UUID &other) noexcept { return aws_uuid_equals(&m_uuid, &other.m_uuid); }
  31. bool UUID::operator!=(const UUID &other) noexcept { return !aws_uuid_equals(&m_uuid, &other.m_uuid); }
  32. String UUID::ToString() const
  33. {
  34. String uuidStr;
  35. uuidStr.resize(AWS_UUID_STR_LEN);
  36. auto outBuf = ByteBufFromEmptyArray(reinterpret_cast<const uint8_t *>(uuidStr.data()), uuidStr.capacity());
  37. aws_uuid_to_str(&m_uuid, &outBuf);
  38. uuidStr.resize(outBuf.len);
  39. return uuidStr;
  40. }
  41. UUID::operator String() const { return ToString(); }
  42. UUID::operator ByteBuf() const noexcept { return ByteBufFromArray(m_uuid.uuid_data, sizeof(m_uuid.uuid_data)); }
  43. int UUID::GetLastError() const noexcept { return aws_last_error(); }
  44. } // namespace Crt
  45. } // namespace Aws