forked from vesoft-inc/nebula
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
3 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,4 +8,9 @@ nebula_add_library( | |
Snowflake.cpp | ||
) | ||
|
||
nebula_add_library( | ||
uuid_obj OBJECT | ||
UUID.cpp | ||
) | ||
|
||
nebula_add_subdirectory(test) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#include "common/id/UUID.h" | ||
|
||
namespace nebula { | ||
|
||
boost::uuids::uuid UUIDV4::getId() { | ||
boost::uuids::uuid uuid = boost::uuids::random_generator()(); | ||
return uuid; | ||
} | ||
|
||
std::string UUIDV4::getIdStr() { | ||
boost::uuids::uuid uuid = getId(); | ||
return boost::uuids::to_string(uuid); | ||
} | ||
|
||
} // namespace nebula |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* Copyright (c) 2021 vesoft inc. All rights reserved. | ||
* | ||
* This source code is licensed under Apache 2.0 License. | ||
*/ | ||
|
||
#include <boost/uuid/uuid.hpp> | ||
#include <boost/uuid/uuid_generators.hpp> | ||
#include <boost/uuid/uuid_io.hpp> | ||
|
||
/* | ||
* UUID v1: time-based and mac-based | ||
* UUID v2: DCE security | ||
* UUID v3: name-based MD5 | ||
* UUID v4: random | ||
* UUID v5: name-based SHA-1 | ||
* boost implements uuid v4 and v5(is deprecated due to security concerns) | ||
*/ | ||
namespace nebula { | ||
|
||
// the probability to find a duplicate within version-4 UUIDs is one in a billion. | ||
// the computed is in: https://en.wikipedia.org/wiki/Universally_unique_identifier | ||
class UUIDV4 { | ||
public: | ||
static boost::uuids::uuid getId(); | ||
|
||
static std::string getIdStr(); | ||
}; | ||
} // namespace nebula |