From 95eb8d262ca2d10e9c3db59ba26f44b86b9d7846 Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Fri, 15 Jul 2016 14:19:58 -0400 Subject: SERVER-25069 added Timestamp::toBSON() (cherry picked from commit 31d1c5473e1c5e21646267bd81cb1afbab677672) --- src/mongo/bson/timestamp.cpp | 8 ++++++++ src/mongo/bson/timestamp.h | 3 +++ 2 files changed, 11 insertions(+) (limited to 'src') diff --git a/src/mongo/bson/timestamp.cpp b/src/mongo/bson/timestamp.cpp index 2abd3a8990a..232aff04128 100644 --- a/src/mongo/bson/timestamp.cpp +++ b/src/mongo/bson/timestamp.cpp @@ -34,6 +34,7 @@ #include #include +#include "mongo/bson/bsonobjbuilder.h" #include "mongo/util/time_support.h" namespace mongo { @@ -70,4 +71,11 @@ std::string Timestamp::toString() const { ss << std::hex << secs << ':' << i; return ss.str(); } + + +BSONObj Timestamp::toBSON() const { + BSONObjBuilder bldr; + bldr.append("", *this); + return bldr.obj(); +} } diff --git a/src/mongo/bson/timestamp.h b/src/mongo/bson/timestamp.h index 1dc04973efb..39c0eb572a8 100644 --- a/src/mongo/bson/timestamp.h +++ b/src/mongo/bson/timestamp.h @@ -34,6 +34,8 @@ namespace mongo { +class BSONObj; + /** * Timestamp: A combination of a count of seconds since the POSIX epoch plus an ordinal value. */ @@ -112,6 +114,7 @@ public: // Append the BSON representation of this Timestamp to the given BufBuilder with the given // name. This lives here because Timestamp manages its own serialization format. void append(BufBuilder& builder, const StringData& fieldName) const; + BSONObj toBSON() const; private: std::tuple tie() const { -- cgit v1.2.1