diff options
author | Billy Donahue <billy.donahue@mongodb.com> | 2020-09-09 21:32:04 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-09-15 00:42:05 +0000 |
commit | 58828b0ce9556ee9cb38c484d1226663a0dcd993 (patch) | |
tree | dfea448799d9bd4328114199a9767dd18d045be3 /src/mongo/bson/oid.cpp | |
parent | 22a77301a5b63b9bb7ef6dd73eabb4865c63a921 (diff) | |
download | mongo-58828b0ce9556ee9cb38c484d1226663a0dcd993.tar.gz |
SERVER-43909 clarify and repair util/hex.h API
- hexblob namespace
- Throwy hexblob::decode (nee fromHex)
- StringData overloads of hex codec ops
- add unsignedHex<T> and zeroPaddedHex<T>
Diffstat (limited to 'src/mongo/bson/oid.cpp')
-rw-r--r-- | src/mongo/bson/oid.cpp | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/src/mongo/bson/oid.cpp b/src/mongo/bson/oid.cpp index ebceefa04fa..70c8b056a70 100644 --- a/src/mongo/bson/oid.cpp +++ b/src/mongo/bson/oid.cpp @@ -36,6 +36,7 @@ #include <memory> #include "mongo/base/init.h" +#include "mongo/base/string_data.h" #include "mongo/bson/bsonobjbuilder.h" #include "mongo/platform/atomic_word.h" #include "mongo/platform/random.h" @@ -149,11 +150,8 @@ void OID::initFromTermNumber(int64_t term) { void OID::init(const std::string& s) { verify(s.size() == 24); - const char* p = s.c_str(); - for (std::size_t i = 0; i < kOIDSize; i++) { - _data[i] = uassertStatusOK(fromHex(p)); - p += 2; - } + std::string blob = hexblob::decode(StringData(s).substr(0, 2 * kOIDSize)); + std::copy(blob.begin(), blob.end(), _data); } void OID::init(Date_t date, bool max) { @@ -167,11 +165,11 @@ time_t OID::asTimeT() const { } std::string OID::toString() const { - return toHexLower(_data, kOIDSize); + return hexblob::encodeLower(_data, kOIDSize); } std::string OID::toIncString() const { - return toHexLower(getIncrement().bytes, kIncrementSize); + return hexblob::encodeLower(getIncrement().bytes, kIncrementSize); } } // namespace mongo |