diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2017-05-02 09:16:56 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2017-05-02 09:16:56 -0400 |
commit | 49cf0ebd80e8b007a6bcd08d3c956b149afa6f81 (patch) | |
tree | 5426b926fda611d8f956ab05bf987895881c491e /src/mongo/bson | |
parent | 3d06c50d9427ac64785d2b62ca368010890aa9be (diff) | |
download | mongo-49cf0ebd80e8b007a6bcd08d3c956b149afa6f81.tar.gz |
SERVER-28827 BinData for IDL
Diffstat (limited to 'src/mongo/bson')
-rw-r--r-- | src/mongo/bson/bsonelement.h | 26 |
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); |