diff options
author | Geert Bosch <geert@mongodb.com> | 2017-05-12 18:38:22 -0400 |
---|---|---|
committer | Geert Bosch <geert@mongodb.com> | 2017-06-09 16:50:41 -0400 |
commit | 6fe725018db0d9a8e580faabe762bb5a153f4ae8 (patch) | |
tree | 8e117673254a45cbcefbe15637e2c7340737d876 /src/mongo/util | |
parent | 1b8c7d24d7a44c1b6784705c9770768743c71943 (diff) | |
download | mongo-6fe725018db0d9a8e580faabe762bb5a153f4ae8.tar.gz |
SERVER-29154 Have mongo shell display and accept UUID as such instead of BinData(4, ...)
Diffstat (limited to 'src/mongo/util')
-rw-r--r-- | src/mongo/util/uuid.cpp | 2 | ||||
-rw-r--r-- | src/mongo/util/uuid.h | 7 | ||||
-rw-r--r-- | src/mongo/util/uuid_test.cpp | 11 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/mongo/util/uuid.cpp b/src/mongo/util/uuid.cpp index ca84906eab2..e3326b718bf 100644 --- a/src/mongo/util/uuid.cpp +++ b/src/mongo/util/uuid.cpp @@ -60,7 +60,7 @@ StatusWith<UUID> UUID::parse(BSONElement from) { StatusWith<UUID> UUID::parse(const std::string& s) { if (!isUUIDString(s)) { - return {ErrorCodes::InvalidUUID, "Invalid uuid string"}; + return {ErrorCodes::InvalidUUID, "Invalid UUID string: " + s}; } UUIDStorage uuid; diff --git a/src/mongo/util/uuid.h b/src/mongo/util/uuid.h index 4f86e26aa7c..9e1caa88b6c 100644 --- a/src/mongo/util/uuid.h +++ b/src/mongo/util/uuid.h @@ -87,6 +87,13 @@ public: */ static UUID parse(const BSONObj& obj); + static UUID fromCDR(ConstDataRange cdr) { + UUID uuid; + invariant(cdr.length() == uuid._uuid.size()); + memcpy(uuid._uuid.data(), cdr.data(), uuid._uuid.size()); + return uuid; + } + /** * Returns whether this string represents a valid UUID. */ diff --git a/src/mongo/util/uuid_test.cpp b/src/mongo/util/uuid_test.cpp index b0a5d12dada..c6b0388ef06 100644 --- a/src/mongo/util/uuid_test.cpp +++ b/src/mongo/util/uuid_test.cpp @@ -141,7 +141,14 @@ TEST(UUIDTest, toAndFromString) { ASSERT_EQUALS(ErrorCodes::InvalidUUID, UUID::parse("samsamsa-sams-4sam-8sam-samsamsamsam")); } -TEST(UUIDTest, toAndFromBSONTest) { +TEST(UUIDTest, toAndFromCDR) { + UUID uuid = UUID::gen(); + ConstDataRange cdr = uuid.toCDR(); + UUID roundtripped = UUID::fromCDR(cdr); + ASSERT_EQUALS(roundtripped, uuid); +} + +TEST(UUIDTest, toAndFromBSON) { // UUID -> BSON -> UUID UUID uuid = UUID::gen(); auto uuidBSON = uuid.toBSON(); @@ -170,7 +177,7 @@ TEST(UUIDTest, toAndFromBSONTest) { ASSERT_EQUALS(ErrorCodes::InvalidUUID, UUID::parse(bson4.getField("uuid"))); } -TEST(UUIDTest, toBSONUsingBSONMacroTest) { +TEST(UUIDTest, toBSONUsingBSONMacro) { auto uuid = UUID::gen(); auto bson = BSON("myuuid" << uuid); |