-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ulid generator is generating invalid value: 0001KPJAMH0000000000…
…000000 (#1822) Signed-off-by: James <[email protected]>
- Loading branch information
Showing
4 changed files
with
26 additions
and
12 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
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
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
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,19 @@ | ||
#pragma once | ||
|
||
#include <string> | ||
#include "utils/ulid/ulid.hh" | ||
|
||
namespace ulid { | ||
inline std::string GenerateUlid() { | ||
auto millisecs = std::chrono::duration_cast<std::chrono::milliseconds>( | ||
std::chrono::system_clock::now().time_since_epoch()) | ||
.count(); | ||
|
||
std::random_device rd; | ||
std::mt19937_64 gen(rd()); | ||
std::uniform_int_distribution<unsigned int> dis(0, 255); | ||
auto ulid = ulid::Create( | ||
millisecs, [&dis, &gen]() { return static_cast<uint8_t>(dis(gen)); }); | ||
return ulid::Marshal(ulid); | ||
} | ||
} // namespace ulid |