-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: encode timestamps correctly in cpp implementation (#7)
- Loading branch information
Showing
7 changed files
with
95 additions
and
19 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,27 +1,25 @@ | ||
#include "ulid.hh" | ||
#include "ulid_wrapper.h" | ||
#include <chrono> | ||
#include "ulid.hh" | ||
|
||
using namespace std; | ||
|
||
|
||
std::string _cpp_ulid() { | ||
ulid::ULID ulid; | ||
ulid::EncodeNowRand(ulid); | ||
return ulid::Marshal(ulid); | ||
ulid::ULID ulid; | ||
ulid::EncodeNowRand(ulid); | ||
return ulid::Marshal(ulid); | ||
} | ||
|
||
std::string _cpp_ulid_at_time(double timestamp) { | ||
const auto encoded_time = chrono::system_clock::to_time_t(chrono::system_clock::time_point(chrono::duration_cast<chrono::seconds>(chrono::duration<double>(timestamp)))); | ||
ulid::ULID ulid; | ||
ulid::EncodeTime(encoded_time, ulid); | ||
ulid::EncodeEntropyRand(ulid); | ||
return ulid::Marshal(ulid); | ||
std::string _cpp_ulid_at_time(double epoch_time) { | ||
time_t encoded_time = static_cast<time_t>(epoch_time*1000); | ||
ulid::ULID ulid; | ||
ulid::EncodeTime(encoded_time, ulid); | ||
ulid::EncodeEntropyRand(ulid); | ||
return ulid::Marshal(ulid); | ||
} | ||
|
||
std::string _cpp_ulid_to_bytes(std::string ulid_string) { | ||
ulid::ULID ulid = ulid::Unmarshal(ulid_string.c_str()); | ||
std::vector<uint8_t> data = ulid::MarshalBinary(ulid); | ||
std::string str(reinterpret_cast<char*>(data.data()), data.size()); | ||
return str; | ||
ulid::ULID ulid = ulid::Unmarshal(ulid_string.c_str()); | ||
std::vector<uint8_t> data = ulid::MarshalBinary(ulid); | ||
std::string str(reinterpret_cast<char *>(data.data()), data.size()); | ||
return str; | ||
} |
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