29 #if defined(_WIN32) || defined(_WIN64)
33 #define strcasecmp _stricmp
36 #include <mongo/bson/bson.h>
37 #include <unordered_map>
39 #include "../../../lib/repo_log.h"
40 #include "../../../repo_bouncer_global.h"
41 #include "../repo_model_global.h"
42 #include "../repo_node_utils.h"
43 #include "repo_bson_element.h"
45 #define REPO_BSON_MAX_BYTE_SIZE 16770000 //max size is 16MB,but leave a bit for buffer
53 class REPO_API_EXPORT
RepoBSON :
public mongo::BSONObj
67 const std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>> &binMapping =
68 std::unordered_map<std::string, std::pair<std::string, std::vector<uint8_t>>>());
74 RepoBSON(mongo::BSONObjBuilder &builder) : mongo::BSONObj(builder.obj()) {}
80 RepoBSON(
const std::vector<char> &rawData) : mongo::BSONObj(rawData.data()) {}
90 static RepoBSON fromJSON(
const std::string &json);
106 mongo::BSONObj::swap(otherCopy);
107 bigFiles = otherCopy.bigFiles;
113 static int64_t getCurrentTimestamp();
133 const std::string &field,
134 std::vector<T> &vec)
const
137 bool success =
false;
139 if (!hasField(field) || getField(field).type() == ElementType::STRING)
142 std::vector<uint8_t> bin = getBigBinary(field);
145 vec.resize(bin.size() /
sizeof(T));
146 memcpy(vec.data(), &bin[0], bin.size());
151 repoError <<
"Trying to retrieve binary from a field that doesn't exist(" << field <<
")";
157 if (bse.
type() == ElementType::BINARY && bse.binDataType() == mongo::BinDataGeneral)
161 const char *binData = bse.binData(length);
164 vec.resize(length /
sizeof(T));
165 memcpy(vec.data(), binData, length);
169 repoError <<
"RepoBSON::getBinaryFieldAsVector : "
170 <<
"size of binary data (" << length <<
") Unable to copy 0 bytes!";
174 repoError <<
"RepoBSON::getBinaryFieldAsVector : bson element type is not BinDataGeneral!";
186 repoUUID getUUIDField(
const std::string &label)
const;
193 std::vector<repoUUID> getUUIDFieldArray(
const std::string &label)
const;
200 std::vector<float> getFloatArray(
const std::string &label)
const;
207 std::vector<std::string> getStringArray(
const std::string &label)
const;
214 int64_t getTimeStampField(
const std::string &label)
const;
225 std::list<std::pair<std::string, std::string> > getListStringPairField(
226 const std::string &arrLabel,
227 const std::string &fstLabel,
228 const std::string &sndLabel)
const;
231 double getEmbeddedDouble(
232 const std::string &embeddedObjName,
233 const std::string &fieldName,
234 const double &defaultValue = 0)
const;
237 bool hasEmbeddedField(
238 const std::string &embeddedObjName,
239 const std::string &fieldName)
const;
250 return hasField(label) || bigFiles.find(label) != bigFiles.end();
269 std::vector<uint8_t> getBigBinary(
const std::string &key)
const;
276 std::vector<std::pair<std::string, std::string>> getFileList()
const;
282 std::unordered_map< std::string, std::pair<std::string, std::vector<uint8_t> > >
getFilesMapping()
const
293 return bigFiles.size() > 0;
298 std::unordered_map< std::string, std::pair<std::string, std::vector<uint8_t> > > bigFiles;
bool hasOversizeFiles() const
Definition: repo_bson.h:291
Definition: repo_bson_element.h:41
RepoBSON(mongo::BSONObjBuilder &builder)
Definition: repo_bson.h:74
RepoBSONElement getField(const std::string &label) const
Definition: repo_bson.h:120
RepoBSON()
Definition: repo_bson.h:60
Definition: repo_connection_pool_mongo.h:32
std::unordered_map< std::string, std::pair< std::string, std::vector< uint8_t > > > getFilesMapping() const
Definition: repo_bson.h:282
virtual ~RepoBSON()
Definition: repo_bson.h:85
void swap(RepoBSON otherCopy)
Definition: repo_bson.h:104
RepoBSON(const std::vector< char > &rawData)
Definition: repo_bson.h:80
Definition: repo_bson.h:53
RepoBSON & operator=(RepoBSON otherCopy)
Definition: repo_bson.h:96
ElementType type() const
Definition: repo_bson_element.cpp:9
bool getBinaryFieldAsVector(const std::string &field, std::vector< T > &vec) const
Definition: repo_bson.h:132
bool hasBinField(const std::string &label) const
Definition: repo_bson.h:248