本文整理汇总了C++中VPackBuilder::slice方法的典型用法代码示例。如果您正苦于以下问题:C++ VPackBuilder::slice方法的具体用法?C++ VPackBuilder::slice怎么用?C++ VPackBuilder::slice使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类VPackBuilder
的用法示例。
在下文中一共展示了VPackBuilder::slice方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: createCollection
int Syncer::createCollection(VPackSlice const& slice, arangodb::LogicalCollection** dst) {
if (dst != nullptr) {
*dst = nullptr;
}
if (!slice.isObject()) {
return TRI_ERROR_REPLICATION_INVALID_RESPONSE;
}
std::string const name = VelocyPackHelper::getStringValue(slice, "name", "");
if (name.empty()) {
return TRI_ERROR_REPLICATION_INVALID_RESPONSE;
}
TRI_voc_cid_t const cid = getCid(slice);
if (cid == 0) {
return TRI_ERROR_REPLICATION_INVALID_RESPONSE;
}
TRI_col_type_e const type = static_cast<TRI_col_type_e>(VelocyPackHelper::getNumericValue<int>(
slice, "type", TRI_COL_TYPE_DOCUMENT));
arangodb::LogicalCollection* col = getCollectionByIdOrName(cid, name);
if (col != nullptr && col->type() == type) {
// collection already exists. TODO: compare attributes
return TRI_ERROR_NO_ERROR;
}
// merge in "isSystem" attribute
VPackBuilder s;
s.openObject();
s.add("isSystem", VPackValue(true));
s.close();
VPackBuilder merged = VPackCollection::merge(s.slice(), slice, true);
int res = TRI_ERROR_NO_ERROR;
try {
col = _vocbase->createCollection(merged.slice(), cid, true);
} catch (basics::Exception const& ex) {
res = ex.code();
} catch (...) {
res = TRI_ERROR_INTERNAL;
}
if (res != TRI_ERROR_NO_ERROR) {
return res;
}
TRI_ASSERT(col != nullptr);
if (dst != nullptr) {
*dst = col;
}
return TRI_ERROR_NO_ERROR;
}
示例2: generateJwt
std::string AuthInfo::generateJwt(VPackBuilder const& payload) {
if (!payload.slice().isObject()) {
std::string error = "Need an object to generate a JWT. Got: ";
error += payload.slice().typeName();
throw std::runtime_error(error);
}
bool hasIss = payload.slice().hasKey("iss");
bool hasIat = payload.slice().hasKey("iat");
VPackBuilder bodyBuilder;
if (hasIss && hasIat) {
bodyBuilder = payload;
} else {
VPackObjectBuilder p(&bodyBuilder);
if (!hasIss) {
bodyBuilder.add("iss", VPackValue("arangodb"));
}
if (!hasIat) {
bodyBuilder.add("iat", VPackValue(TRI_microtime() / 1000));
}
for (auto const& obj : VPackObjectIterator(payload.slice())) {
bodyBuilder.add(obj.key.copyString(), obj.value);
}
}
return generateRawJwt(bodyBuilder);
}
示例3: initializeCursor
/// @brief initializeCursor, could be called multiple times
int RemoteBlock::initializeCursor(AqlItemBlock* items, size_t pos) {
DEBUG_BEGIN_BLOCK();
// For every call we simply forward via HTTP
if (!_isResponsibleForInitializeCursor) {
// do nothing...
return TRI_ERROR_NO_ERROR;
}
VPackBuilder builder;
builder.openObject();
if (items == nullptr) {
// first call, items is still a nullptr
builder.add("exhausted", VPackValue(true));
builder.add("error", VPackValue(false));
} else {
builder.add("exhausted", VPackValue(false));
builder.add("error", VPackValue(false));
builder.add("pos", VPackValue(pos));
builder.add(VPackValue("items"));
builder.openObject();
items->toVelocyPack(_engine->getQuery()->trx(), builder);
builder.close();
}
builder.close();
std::string bodyString(builder.slice().toJson());
std::unique_ptr<ClusterCommResult> res = sendRequest(
rest::RequestType::PUT, "/_api/aql/initializeCursor/", bodyString);
throwExceptionAfterBadSyncRequest(res.get(), false);
// If we get here, then res->result is the response which will be
// a serialized AqlItemBlock:
StringBuffer const& responseBodyBuf(res->result->getBody());
{
std::shared_ptr<VPackBuilder> builder = VPackParser::fromJson(
responseBodyBuf.c_str(), responseBodyBuf.length());
VPackSlice slice = builder->slice();
if (slice.hasKey("code")) {
return slice.get("code").getNumericValue<int>();
}
return TRI_ERROR_INTERNAL;
}
// cppcheck-suppress style
DEBUG_END_BLOCK();
}
示例4: execute
HttpHandler::status_t RestVersionHandler::execute() {
try {
VPackBuilder result;
result.add(VPackValue(VPackValueType::Object));
result.add("server", VPackValue("arango"));
result.add("version", VPackValue(ARANGODB_VERSION));
bool found;
std::string const& detailsStr = _request->value("details", found);
if (found && StringUtils::boolean(detailsStr)) {
result.add("details", VPackValue(VPackValueType::Object));
Version::getVPack(result);
if (application_features::ApplicationServer::server != nullptr) {
auto server = application_features::ApplicationServer::server
->getFeature<ServerFeature>("Server");
result.add("mode", VPackValue(server->operationModeString()));
}
result.close();
}
result.close();
generateResult(GeneralResponse::ResponseCode::OK, result.slice());
} catch (...) {
// Ignore this error
}
return status_t(HANDLER_DONE);
}
示例5: operator
void operator()(VPackSlice const& v, std::vector<VPackSlice>& resEdges,
std::vector<VPackSlice>& neighbors) {
int res = TRI_ERROR_NO_ERROR;
for (auto const& edgeCollection : _block->_collectionInfos) {
VPackBuilder result;
TRI_ASSERT(edgeCollection != nullptr);
if (_isReverse) {
res = edgeCollection->getReverseEdgesCoordinator(v, result);
} else {
res = edgeCollection->getEdgesCoordinator(v, result);
}
if (res != TRI_ERROR_NO_ERROR) {
THROW_ARANGO_EXCEPTION(res);
}
VPackSlice edges = result.slice().get("edges");
for (auto const& edge : VPackArrayIterator(edges)) {
VPackSlice from = arangodb::Transaction::extractFromFromDocument(edge);
if (from == v) {
VPackSlice to = arangodb::Transaction::extractToFromDocument(edge);
if (to != v) {
resEdges.emplace_back(edge);
neighbors.emplace_back(to);
}
} else {
resEdges.emplace_back(edge);
neighbors.emplace_back(from);
}
}
// Make sure the data Slices are pointing to is not running out of scope.
// This is not thread-safe!
_block->_coordinatorCache.emplace_back(result.steal());
}
}
示例6: transactions
void RestWalHandler::transactions() {
auto const& info =
arangodb::wal::LogfileManager::instance()->runningTransactions();
VPackBuilder builder;
builder.openObject();
builder.add("runningTransactions", VPackValue(static_cast<double>(std::get<0>(info))));
// lastCollectedId
{
auto value = std::get<1>(info);
if (value == UINT64_MAX) {
builder.add("minLastCollected", VPackValue(VPackValueType::Null));
} else {
builder.add("minLastCollected", VPackValue(value));
}
}
// lastSealedId
{
auto value = std::get<2>(info);
if (value == UINT64_MAX) {
builder.add("minLastSealed", VPackValue(VPackValueType::Null));
} else {
builder.add("minLastSealed", VPackValue(value));
}
}
builder.close();
generateResult(rest::ResponseCode::OK, builder.slice());
}
示例7: generatePreconditionFailed
void RestVocbaseBaseHandler::generatePreconditionFailed(
VPackSlice const& slice) {
createResponse(GeneralResponse::ResponseCode::PRECONDITION_FAILED);
if (slice.isObject()) { // single document case
std::string const rev =
VelocyPackHelper::getStringValue(slice, StaticStrings::RevString, "");
_response->setHeaderNC(StaticStrings::Etag, "\"" + rev + "\"");
}
VPackBuilder builder;
{
VPackObjectBuilder guard(&builder);
builder.add("error", VPackValue(true));
builder.add("code",
VPackValue(static_cast<int32_t>(
GeneralResponse::ResponseCode::PRECONDITION_FAILED)));
builder.add("errorNum", VPackValue(TRI_ERROR_ARANGO_CONFLICT));
builder.add("errorMessage", VPackValue("precondition failed"));
if (slice.isObject()) {
builder.add(StaticStrings::IdString, slice.get(StaticStrings::IdString));
builder.add(StaticStrings::KeyString,
slice.get(StaticStrings::KeyString));
builder.add(StaticStrings::RevString,
slice.get(StaticStrings::RevString));
} else {
builder.add("result", slice);
}
}
auto transactionContext(StandaloneTransactionContext::Create(_vocbase));
writeResult(builder.slice(), *(transactionContext->getVPackOptionsForDump()));
}
示例8: getEdgesForVertexList
bool RestEdgesHandler::getEdgesForVertexList(
VPackSlice const ids,
std::vector<traverser::TraverserExpression*> const& expressions,
TRI_edge_direction_e direction, SingleCollectionTransaction& trx,
VPackBuilder& result, size_t& scannedIndex, size_t& filtered) {
TRI_ASSERT(ids.isArray());
trx.orderDitch(trx.cid()); // will throw when it fails
std::string const collectionName =
trx.resolver()->getCollectionName(trx.cid());
Transaction::IndexHandle indexId = trx.edgeIndexHandle(collectionName);
VPackBuilder searchValueBuilder;
EdgeIndex::buildSearchValueFromArray(direction, ids, searchValueBuilder);
VPackSlice search = searchValueBuilder.slice();
std::unique_ptr<OperationCursor> cursor =
trx.indexScan(collectionName, arangodb::Transaction::CursorType::INDEX,
indexId, search, nullptr, 0, UINT64_MAX, 1000, false);
if (cursor->failed()) {
THROW_ARANGO_EXCEPTION(cursor->code);
}
auto opRes = std::make_shared<OperationResult>(TRI_ERROR_NO_ERROR);
while (cursor->hasMore()) {
cursor->getMore(opRes);
if (opRes->failed()) {
THROW_ARANGO_EXCEPTION(opRes->code);
}
VPackSlice edges = opRes->slice();
TRI_ASSERT(edges.isArray());
// generate result
scannedIndex += static_cast<size_t>(edges.length());
for (auto const& edge : VPackArrayIterator(edges)) {
bool add = true;
if (!expressions.empty()) {
for (auto& exp : expressions) {
if (exp->isEdgeAccess && !exp->matchesCheck(&trx, edge)) {
++filtered;
add = false;
break;
}
}
}
if (add) {
result.add(edge);
}
}
}
return true;
}
示例9: execute
HttpHandler::status_t RestAuthHandler::execute() {
auto const type = _request->requestType();
if (type != GeneralRequest::RequestType::POST) {
generateError(GeneralResponse::ResponseCode::METHOD_NOT_ALLOWED,
TRI_ERROR_HTTP_METHOD_NOT_ALLOWED);
return status_t(HANDLER_DONE);
}
VPackOptions options = VPackOptions::Defaults;
options.checkAttributeUniqueness = true;
bool parseSuccess;
std::shared_ptr<VPackBuilder> parsedBody =
parseVelocyPackBody(&options, parseSuccess);
if (!parseSuccess) {
return badRequest();
}
VPackSlice slice = parsedBody->slice();
if (!slice.isObject()) {
return badRequest();
}
VPackSlice usernameSlice = slice.get("username");
VPackSlice passwordSlice = slice.get("password");
if (!usernameSlice.isString() || !passwordSlice.isString()) {
return badRequest();
}
std::string const username = usernameSlice.copyString();
std::string const password = passwordSlice.copyString();
AuthResult auth = RestServerFeature::AUTH_INFO.checkPassword(username, password);
if (auth._authorized) {
VPackBuilder resultBuilder;
{
VPackObjectBuilder b(&resultBuilder);
std::string jwt = generateJwt(username, password);
resultBuilder.add("jwt", VPackValue(jwt));
resultBuilder.add("must_change_password", VPackValue(auth._mustChange));
}
generateDocument(resultBuilder.slice(), true, &VPackOptions::Defaults);
return status_t(HANDLER_DONE);
} else {
// mop: rfc 2616 10.4.2 (if credentials wrong 401)
generateError(GeneralResponse::ResponseCode::UNAUTHORIZED, TRI_ERROR_HTTP_UNAUTHORIZED,
"Wrong credentials");
return status_t(HANDLER_DONE);
}
}
示例10: execute
RestStatus RestShutdownHandler::execute() {
if (_request->requestType() != rest::RequestType::DELETE_REQ) {
generateError(rest::ResponseCode::METHOD_NOT_ALLOWED, 405);
return RestStatus::DONE;
}
bool removeFromCluster;
std::string const& remove = _request->value("remove_from_cluster", removeFromCluster);
removeFromCluster = removeFromCluster && remove == "1";
bool shutdownClusterFound;
std::string const& shutdownCluster = _request->value("shutdown_cluster", shutdownClusterFound);
if (shutdownClusterFound && shutdownCluster == "1") {
AgencyComm agency;
VPackBuilder builder;
builder.add(VPackValue(true));
AgencyCommResult result = agency.setValue("Shutdown", builder.slice(), 0.0);
if (!result.successful()) {
generateError(rest::ResponseCode::SERVER_ERROR, 500);
return RestStatus::DONE;
}
removeFromCluster = true;
}
if (removeFromCluster) {
ClusterFeature* clusterFeature = ApplicationServer::getFeature<ClusterFeature>("Cluster");
clusterFeature->setUnregisterOnShutdown(true);
}
ApplicationServer::server->beginShutdown();
try {
VPackBuilder result;
result.add(VPackValue("OK"));
generateResult(rest::ResponseCode::OK, result.slice());
} catch (...) {
// Ignore the error
}
return RestStatus::DONE;
}
示例11: skipSome
/// @brief skipSome
size_t RemoteBlock::skipSome(size_t atLeast, size_t atMost) {
DEBUG_BEGIN_BLOCK();
// For every call we simply forward via HTTP
VPackBuilder builder;
builder.openObject();
builder.add("atLeast", VPackValue(atLeast));
builder.add("atMost", VPackValue(atMost));
builder.close();
std::string bodyString(builder.slice().toJson());
std::unique_ptr<ClusterCommResult> res =
sendRequest(rest::RequestType::PUT, "/_api/aql/skipSome/", bodyString);
throwExceptionAfterBadSyncRequest(res.get(), false);
// If we get here, then res->result is the response which will be
// a serialized AqlItemBlock:
StringBuffer const& responseBodyBuf(res->result->getBody());
{
std::shared_ptr<VPackBuilder> builder = VPackParser::fromJson(
responseBodyBuf.c_str(), responseBodyBuf.length());
VPackSlice slice = builder->slice();
if (!slice.hasKey("error") || slice.get("error").getBoolean()) {
THROW_ARANGO_EXCEPTION(TRI_ERROR_CLUSTER_AQL_COMMUNICATION);
}
size_t skipped = 0;
if (slice.hasKey("skipped")) {
skipped = slice.get("skipped").getNumericValue<size_t>();
}
return skipped;
}
// cppcheck-suppress style
DEBUG_END_BLOCK();
}
示例12: insertInitial
void AuthInfo::insertInitial() {
if (!_authInfo.empty()) {
return;
}
try {
VPackBuilder builder;
builder.openArray();
// The only users object
builder.add(VPackValue(VPackValueType::Object));
// username
builder.add("user", VPackValue("root"));
builder.add("authData", VPackValue(VPackValueType::Object));
// simple auth
builder.add("simple", VPackValue(VPackValueType::Object));
builder.add("method", VPackValue("sha256"));
char const* salt = "c776f5f4";
builder.add("salt", VPackValue(salt));
char const* hash =
"ef74bc6fd59ac713bf5929c5ac2f42233e50d4d58748178132ea46dec433bd5b";
builder.add("hash", VPackValue(hash));
builder.close(); // simple
builder.add("active", VPackValue(true));
builder.close(); // authData
builder.add("databases", VPackValue(VPackValueType::Object));
builder.add("*", VPackValue("rw"));
builder.close();
builder.close(); // The user object
builder.close(); // The Array
populate(builder.slice());
} catch (...) {
// No action
}
}
示例13: execute
RestStatus RestAqlFunctionsHandler::execute() {
// extract the sub-request type
auto const type = _request->requestType();
if (type == rest::RequestType::GET) {
VPackBuilder builder;
builder.openObject();
builder.add(VPackValue("functions"));
aql::FunctionDefinitions::toVelocyPack(builder);
builder.close();
generateResult(rest::ResponseCode::OK, builder.slice());
return RestStatus::DONE;
}
generateError(rest::ResponseCode::METHOD_NOT_ALLOWED,
TRI_ERROR_HTTP_METHOD_NOT_ALLOWED);
return RestStatus::DONE;
}
示例14: getSome
/// @brief getSome
AqlItemBlock* RemoteBlock::getSome(size_t atLeast, size_t atMost) {
DEBUG_BEGIN_BLOCK();
// For every call we simply forward via HTTP
traceGetSomeBegin();
VPackBuilder builder;
builder.openObject();
builder.add("atLeast", VPackValue(atLeast));
builder.add("atMost", VPackValue(atMost));
builder.close();
std::string bodyString(builder.slice().toJson());
std::unique_ptr<ClusterCommResult> res =
sendRequest(rest::RequestType::PUT, "/_api/aql/getSome/", bodyString);
throwExceptionAfterBadSyncRequest(res.get(), false);
// If we get here, then res->result is the response which will be
// a serialized AqlItemBlock:
std::shared_ptr<VPackBuilder> responseBodyBuilder =
res->result->getBodyVelocyPack();
VPackSlice responseBody = responseBodyBuilder->slice();
ExecutionStats newStats(responseBody.get("stats"));
_engine->_stats.addDelta(_deltaStats, newStats);
_deltaStats = newStats;
if (VelocyPackHelper::getBooleanValue(responseBody, "exhausted", true)) {
traceGetSomeEnd(nullptr);
return nullptr;
}
auto r = new arangodb::aql::AqlItemBlock(responseBody);
traceGetSomeEnd(r);
return r;
// cppcheck-suppress style
DEBUG_END_BLOCK();
}
示例15: execute
RestStatus RestDebugHandler::execute() {
// extract the sub-request type
auto const type = _request->requestType();
size_t const len = _request->suffix().size();
if (len == 0 || len > 2 || !(_request->suffix()[0] == "failat")) {
generateNotImplemented("ILLEGAL /_admin/debug/failat");
return RestStatus::DONE;
}
std::vector<std::string> const& suffix = _request->suffix();
// execute one of the CRUD methods
switch (type) {
case rest::RequestType::DELETE_REQ:
if (len == 1) {
TRI_ClearFailurePointsDebugging();
} else {
TRI_RemoveFailurePointDebugging(suffix[1].c_str());
}
break;
case rest::RequestType::PUT:
if (len == 2) {
TRI_AddFailurePointDebugging(suffix[1].c_str());
} else {
generateNotImplemented("ILLEGAL /_admin/debug/failat");
}
break;
default:
generateNotImplemented("ILLEGAL /_admin/debug/failat");
return RestStatus::DONE;
}
try {
VPackBuilder result;
result.add(VPackValue(true));
generateResult(rest::ResponseCode::OK, result.slice());
} catch (...) {
// Ignore this error
}
return RestStatus::DONE;
}