Rename UUID -> Uuid (#436)

* Rename UUID -> Uuid
Update header references
This commit is contained in:
Rick Winter 2020-08-11 13:23:14 -07:00 committed by GitHub
parent 302bbf251e
commit 8821aadb80
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 34 deletions

View File

@ -123,7 +123,7 @@ namespace Azure { namespace Core { namespace Http {
Request& request,
NextHttpPolicy nextHttpPolicy) const override
{
auto uuid = UUID::CreateUUID().GetUUIDString();
auto uuid = Uuid::CreateUuid().GetUuidString();
request.AddHeader(RequestIdHeader, uuid);
return nextHttpPolicy.Send(ctx, request);

View File

@ -3,6 +3,7 @@
#pragma once
#include <cstring>
#include <new> // for placement new
#include <random>
#include <string>
@ -10,12 +11,12 @@
namespace Azure { namespace Core {
class UUID {
class Uuid {
private:
static const int UUIDSize = 16;
static const int UuidSize = 16;
uint8_t m_uuid[UUIDSize];
uint8_t m_uuid[UuidSize];
// The UUID reserved variants.
static constexpr uint8_t ReservedNCS = 0x80;
static constexpr uint8_t ReservedRFC4122 = 0x40;
@ -23,14 +24,14 @@ namespace Azure { namespace Core {
static constexpr uint8_t ReservedFuture = 0x00;
private:
UUID(uint8_t const uuid[UUIDSize])
{
memcpy(m_uuid, uuid, UUIDSize);
Uuid(uint8_t const uuid[UuidSize])
{
std::memcpy(m_uuid, uuid, UuidSize);
}
public:
std::string GetUUIDString()
std::string GetUuidString()
{
// Guid is 36 characters
// Add one byte for the \0
@ -60,13 +61,13 @@ namespace Azure { namespace Core {
return std::string(s);
}
static UUID CreateUUID() {
static Uuid CreateUuid() {
std::random_device rd;
std::mt19937 gen(rd());
uint8_t uuid[UUIDSize] = {};
uint8_t uuid[UuidSize] = {};
for (int i = 0; i < UUIDSize; i += 4)
for (int i = 0; i < UuidSize; i += 4)
*reinterpret_cast<uint32_t*>(uuid + i) = gen();
// SetVariant to ReservedRFC4122
@ -76,7 +77,7 @@ namespace Azure { namespace Core {
uuid[6] = (uuid[6] & 0xF) | (version << 4);
return UUID(uuid);
return Uuid(uuid);
}
};
}} // namespace Azure::Core

View File

@ -3,33 +3,14 @@
#include "common/storage_common.hpp"
#include <random>
#include <uuid.hpp>
namespace Azure { namespace Storage {
std::string CreateUniqueLeaseId()
{
// TODO: return UUID provided by Azure Core once they provide one.
static thread_local std::mt19937_64 random_generator(std::random_device{}());
auto getRandomChar = []() {
const char charset[] = "0123456789abcdef";
std::uniform_int_distribution<size_t> distribution(0, sizeof(charset) - 2);
return charset[distribution(random_generator)];
};
std::string result;
result.reserve(37);
for (int i : {8, 4, 4, 4, 12})
{
for (int j = 0; j < i; ++j)
result += getRandomChar();
result += '-';
}
result.pop_back();
return result;
auto uuid = Azure::Core::Uuid::CreateUuid();
return uuid.GetUuidString();
}
}} // namespace Azure::Storage