本文整理汇总了C++中Document::ObjectEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ Document::ObjectEmpty方法的具体用法?C++ Document::ObjectEmpty怎么用?C++ Document::ObjectEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document::ObjectEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: parseEntity
/* ****************************************************************************
*
* parseEntity -
*
* This function is used to parse two slightly different payloads:
* - POST /v2/entities
* - POST /v2/entities/<eid>
*
* In the latter case, "id" CANNOT be in the payload, while in the former case,
* "id" MUST be in the payload.
*
* In the case of /v2/entities/<eid>, the entityId of 'Entity* eP' is set in
* the service routine postEntity.
*
* Also, if the URI param 'options' includes the value 'keyValues', then the
* parse changes for compound values of attributes. If the value is a JSON object
* then there is no looking inside to find the 'value' field, but the attribute is
* always treated as a compound attribute.
*
*/
std::string parseEntity(ConnectionInfo* ciP, Entity* eP, bool eidInURL)
{
Document document;
document.Parse(ciP->payload);
if (document.HasParseError())
{
alarmMgr.badInput(clientIp, "JSON parse error");
eP->oe.fill(SccBadRequest, "Errors found in incoming JSON buffer", ERROR_STRING_PARSERROR);
ciP->httpStatusCode = SccBadRequest;
return eP->render(ciP, EntitiesRequest);
}
if (!document.IsObject())
{
alarmMgr.badInput(clientIp, "JSON Parse Error");
eP->oe.fill(SccBadRequest, "Errors found in incoming JSON buffer", ERROR_STRING_PARSERROR);
ciP->httpStatusCode = SccBadRequest;
return eP->render(ciP, EntitiesRequest);
}
if (eidInURL == false)
{
if (!document.HasMember("id"))
{
alarmMgr.badInput(clientIp, "No entity id specified");
eP->oe.fill(SccBadRequest, "no entity id specified", "BadRequest");
ciP->httpStatusCode = SccBadRequest;;
return eP->render(ciP, EntitiesRequest);
}
}
if (eidInURL == true)
{
if (document.HasMember("id"))
{
alarmMgr.badInput(clientIp, "entity id specified in payload");
eP->oe.fill(SccBadRequest, "entity id specified in payload", "BadRequest");
ciP->httpStatusCode = SccBadRequest;;
return eP->render(ciP, EntitiesRequest);
}
if (document.HasMember("type"))
{
alarmMgr.badInput(clientIp, "entity type specified in payload");
eP->oe.fill(SccBadRequest, "entity type specified in payload", "BadRequest");
ciP->httpStatusCode = SccBadRequest;;
return eP->render(ciP, EntitiesRequest);
}
}
else if (document.ObjectEmpty())
{
//
// Initially we used the method "Empty". As the broker crashed inside that method, some
// research was made and "ObjectEmpty" was found. As the broker stopped crashing and complaints
// about crashes with small docs and "Empty()" were found on the internet, we opted to use ObjectEmpty
//
alarmMgr.badInput(clientIp, "Empty payload");
eP->oe.fill(SccBadRequest, "empty payload", "BadRequest");
ciP->httpStatusCode = SccBadRequest;
return eP->render(ciP, EntitiesRequest);
}
int membersFound = 0;
for (Value::ConstMemberIterator iter = document.MemberBegin(); iter != document.MemberEnd(); ++iter)
{
std::string name = iter->name.GetString();
std::string type = jsonParseTypeNames[iter->value.GetType()];
++membersFound;
if (name == "id")
//.........这里部分代码省略.........
示例2: parseBatchUpdate
/* ****************************************************************************
*
* parseBatchUpdate -
*/
std::string parseBatchUpdate(ConnectionInfo* ciP, BatchUpdate* burP)
{
Document document;
document.Parse(ciP->payload);
if (document.HasParseError())
{
ErrorCode ec;
alarmMgr.badInput(clientIp, "JSON Parse Error");
ec.fill(ERROR_STRING_PARSERROR, "Errors found in incoming JSON buffer");
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
if (!document.IsObject())
{
ErrorCode ec;
alarmMgr.badInput(clientIp, "JSON Parse Error");
ec.fill("BadRequest", "JSON Parse Error");
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
else if (document.ObjectEmpty())
{
ErrorCode ec;
alarmMgr.badInput(clientIp, "Empty JSON payload");
ec.fill("BadRequest", "empty payload");
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
else if (!document.HasMember("entities"))
{
ErrorCode ec;
std::string details = "Invalid JSON payload, mandatory field /entities/ not found";
alarmMgr.badInput(clientIp, details);
ec.fill("BadRequest", details);
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
else if (!document.HasMember("actionType"))
{
ErrorCode ec;
std::string details = "Invalid JSON payload, mandatory field /actionType/ not found";
alarmMgr.badInput(clientIp, details);
ec.fill("BadRequest", details);
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
for (Value::ConstMemberIterator iter = document.MemberBegin(); iter != document.MemberEnd(); ++iter)
{
std::string name = iter->name.GetString();
std::string type = jsonParseTypeNames[iter->value.GetType()];
if (name == "entities")
{
std::string r = parseEntityVector(ciP, iter, &burP->entities, true); // param 4: attributes are allowed in payload
if (r != "OK")
{
ErrorCode ec("BadRequest", r);
alarmMgr.badInput(clientIp, r);
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
}
else if (name == "actionType")
{
burP->updateActionType.set(iter->value.GetString());
}
else
{
std::string description = std::string("Unrecognized field in JSON payload: /") + name + "/";
ErrorCode ec("BadRequest", description);
alarmMgr.badInput(clientIp, description);
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
}
return "OK";
}
示例3: parseBatchQuery
/* ****************************************************************************
*
* parseBatchQuery -
*/
std::string parseBatchQuery(ConnectionInfo* ciP, BatchQuery* bqrP)
{
Document document;
document.Parse(ciP->payload);
if (document.HasParseError())
{
ErrorCode ec;
alarmMgr.badInput(clientIp, "JSON Parse Error");
ec.fill(ERROR_STRING_PARSERROR, "Errors found in incoming JSON buffer");
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
if (!document.IsObject())
{
ErrorCode ec;
alarmMgr.badInput(clientIp, "JSON Parse Error");
ec.fill("BadRequest", "JSON Parse Error");
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
else if (document.ObjectEmpty())
{
ErrorCode ec;
alarmMgr.badInput(clientIp, "Empty JSON payload");
ec.fill("BadRequest", "empty payload");
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
else if (!document.HasMember("entities") && !document.HasMember("attributes") && !document.HasMember("scopes"))
{
ErrorCode ec;
alarmMgr.badInput(clientIp, "Invalid JSON payload, no relevant fields found");
ec.fill("BadRequest", "Invalid JSON payload, no relevant fields found");
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
for (Value::ConstMemberIterator iter = document.MemberBegin(); iter != document.MemberEnd(); ++iter)
{
std::string name = iter->name.GetString();
std::string type = jsonParseTypeNames[iter->value.GetType()];
if (name == "entities")
{
std::string r = parseEntityVector(ciP, iter, &bqrP->entities, false); // param 4: attributes are NOT allowed in payload
if (r != "OK")
{
ErrorCode ec("BadRequest", r);
alarmMgr.badInput(clientIp, r);
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
}
else if (name == "attributes")
{
std::string r = parseAttributeList(ciP, iter, &bqrP->attributeV);
if (r != "OK")
{
ErrorCode ec("BadRequest", r);
alarmMgr.badInput(clientIp, r);
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
}
else if (name == "scopes")
{
std::string r = parseScopeVector(ciP, iter, &bqrP->scopeV);
if (r != "OK")
{
ErrorCode ec("BadRequest", r);
alarmMgr.badInput(clientIp, r);
ciP->httpStatusCode = SccBadRequest;
return ec.toJson(true);
}
}
else
{
std::string description = std::string("Unrecognizedfield in JSON payload: /") + name + "/";
ErrorCode ec("BadRequest", description);
//.........这里部分代码省略.........