summaryrefslogtreecommitdiff
path: root/src/mongo/bson/bsonelement.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/bson/bsonelement.h')
-rw-r--r--src/mongo/bson/bsonelement.h26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/mongo/bson/bsonelement.h b/src/mongo/bson/bsonelement.h
index 2d815383b2c..dd68d333f63 100644
--- a/src/mongo/bson/bsonelement.h
+++ b/src/mongo/bson/bsonelement.h
@@ -35,6 +35,7 @@
#include <string>
#include <vector>
+#include "mongo/base/data_range.h"
#include "mongo/base/data_type_endian.h"
#include "mongo/base/data_view.h"
#include "mongo/base/string_data_comparator_interface.h"
@@ -468,6 +469,19 @@ public:
return (BinDataType)c;
}
+ std::vector<uint8_t> _binDataVector() const {
+ if (binDataType() != ByteArrayDeprecated) {
+ return std::vector<uint8_t>(reinterpret_cast<const uint8_t*>(value()) + 5,
+ reinterpret_cast<const uint8_t*>(value()) + 5 +
+ valuestrsize());
+ } else {
+ // Skip the extra int32 size
+ return std::vector<uint8_t>(reinterpret_cast<const uint8_t*>(value()) + 4,
+ reinterpret_cast<const uint8_t*>(value()) + 4 +
+ valuestrsize() - 4);
+ }
+ }
+
/** Retrieve the regex std::string for a Regex element */
const char* regex() const {
verify(type() == RegEx);
@@ -592,6 +606,18 @@ public:
return result;
}
+ const std::array<unsigned char, 16> md5() const {
+ int len = 0;
+ const char* data = nullptr;
+ if (type() == BinData && binDataType() == BinDataType::MD5Type)
+ data = binData(len);
+ uassert(550418, "md5 must be a 16-byte binary field with MD5 (5) subtype", len == 16);
+ std::array<unsigned char, 16> result;
+ memcpy(&result, data, len);
+ return result;
+ }
+
+
Date_t timestampTime() const {
unsigned long long t = ConstDataView(value() + 4).read<LittleEndian<unsigned int>>();
return Date_t::fromMillisSinceEpoch(t * 1000);