mirror of https://gitee.com/bigwinds/arangodb
update velocypack version (#9379)
This commit is contained in:
parent
12775c27bc
commit
2f90f5ec49
|
@ -40,6 +40,7 @@
|
|||
#include "velocypack/Buffer.h"
|
||||
#include "velocypack/Exception.h"
|
||||
#include "velocypack/Options.h"
|
||||
#include "velocypack/Serializable.h"
|
||||
#include "velocypack/Slice.h"
|
||||
#include "velocypack/StringRef.h"
|
||||
#include "velocypack/Value.h"
|
||||
|
@ -280,6 +281,20 @@ class Builder {
|
|||
return addInternal<ValuePair>(attrName, attrLength, sub);
|
||||
}
|
||||
|
||||
// Add a subvalue into an object from a Serializable:
|
||||
inline uint8_t* add(std::string const& attrName, Serialize const& sub) {
|
||||
return addInternal<Serializable>(attrName, sub._sable);
|
||||
}
|
||||
inline uint8_t* add(StringRef const& attrName, Serialize const& sub) {
|
||||
return addInternal<Serializable>(attrName, sub._sable);
|
||||
}
|
||||
inline uint8_t* add(char const* attrName, Serialize const& sub) {
|
||||
return addInternal<Serializable>(attrName, sub._sable);
|
||||
}
|
||||
inline uint8_t* add(char const* attrName, std::size_t attrLength, Serialize const& sub) {
|
||||
return addInternal<Serializable>(attrName, attrLength, sub._sable);
|
||||
}
|
||||
|
||||
// Add a subvalue into an array from a Value:
|
||||
inline uint8_t* add(Value const& sub) {
|
||||
return addInternal<Value>(sub);
|
||||
|
@ -295,6 +310,11 @@ class Builder {
|
|||
return addInternal<ValuePair>(sub);
|
||||
}
|
||||
|
||||
// Add a subvalue into an array from a Serializable:
|
||||
inline uint8_t* add(Serialize const& sub) {
|
||||
return addInternal<Serializable>(sub._sable);
|
||||
}
|
||||
|
||||
// Add an External slice to an array
|
||||
uint8_t* addExternal(uint8_t const* sub) {
|
||||
if (options->disallowExternals) {
|
||||
|
@ -445,18 +465,23 @@ class Builder {
|
|||
|
||||
void addInt(int64_t v) {
|
||||
if (v >= 0 && v <= 9) {
|
||||
// SmallInt
|
||||
appendByte(static_cast<uint8_t>(0x30 + v));
|
||||
} else if (v < 0 && v >= -6) {
|
||||
// SmallInt
|
||||
appendByte(static_cast<uint8_t>(0x40 + v));
|
||||
} else {
|
||||
// regular int
|
||||
appendInt(v, 0x1f);
|
||||
}
|
||||
}
|
||||
|
||||
void addUInt(uint64_t v) {
|
||||
if (v <= 9) {
|
||||
// SmallInt
|
||||
appendByte(static_cast<uint8_t>(0x30 + v));
|
||||
} else {
|
||||
// regular UInt
|
||||
appendUInt(v, 0x27);
|
||||
}
|
||||
}
|
||||
|
@ -624,6 +649,12 @@ class Builder {
|
|||
|
||||
uint8_t* set(Slice const& item);
|
||||
|
||||
uint8_t* set(Serializable const& sable) {
|
||||
auto const oldPos = _pos;
|
||||
sable.toVelocyPack(*this);
|
||||
return _start + oldPos;
|
||||
}
|
||||
|
||||
void cleanupAdd() noexcept {
|
||||
std::size_t depth = _stack.size() - 1;
|
||||
VELOCYPACK_ASSERT(!_index[depth].empty());
|
||||
|
|
|
@ -28,119 +28,60 @@
|
|||
#define VELOCYPACK_COMPARE_H 1
|
||||
|
||||
#include "velocypack/velocypack-common.h"
|
||||
#include "velocypack/Collection.h"
|
||||
#include "velocypack/Exception.h"
|
||||
#include "velocypack/Iterator.h"
|
||||
#include "velocypack/Slice.h"
|
||||
#include "velocypack/ValueType.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace arangodb {
|
||||
namespace velocypack {
|
||||
struct Options;
|
||||
class Slice;
|
||||
|
||||
// helper struct for comparing VelocyPack Slices on a binary level
|
||||
struct BinaryCompare {
|
||||
// returns true if the two Slices are identical on the binary level
|
||||
static bool equals(Slice lhs, Slice rhs);
|
||||
|
||||
struct Hash {
|
||||
size_t operator()(arangodb::velocypack::Slice const&) const;
|
||||
};
|
||||
|
||||
struct Equal {
|
||||
arangodb::velocypack::Options const* _options;
|
||||
|
||||
Equal() : _options(nullptr) {}
|
||||
explicit Equal(arangodb::velocypack::Options const* opts)
|
||||
: _options(opts) {}
|
||||
|
||||
bool operator()(arangodb::velocypack::Slice const&,
|
||||
arangodb::velocypack::Slice const&) const;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
// helper struct for comparing VelocyPack Slices in a normalized way
|
||||
struct NormalizedCompare {
|
||||
|
||||
static bool equalsNumbers(Slice lhs, Slice rhs) {
|
||||
auto lhsType = lhs.type();
|
||||
if (lhsType == rhs.type()) {
|
||||
// both types are equal
|
||||
if (lhsType == ValueType::Int || lhsType == ValueType::SmallInt) {
|
||||
// use exact comparisons. no need to cast to double
|
||||
return (lhs.getIntUnchecked() == rhs.getIntUnchecked());
|
||||
}
|
||||
// function to compare two numeric values
|
||||
static bool equalsNumbers(Slice lhs, Slice rhs);
|
||||
|
||||
if (lhsType == ValueType::UInt) {
|
||||
// use exact comparisons. no need to cast to double
|
||||
return (lhs.getUIntUnchecked() == rhs.getUIntUnchecked());
|
||||
}
|
||||
// fallthrough to double comparison
|
||||
}
|
||||
// function to compare two string values
|
||||
static bool equalsStrings(Slice lhs, Slice rhs);
|
||||
|
||||
return (lhs.getNumericValue<double>() == rhs.getNumericValue<double>());
|
||||
}
|
||||
// function to compare two arbitrary Slices
|
||||
static bool equals(Slice lhs, Slice rhs);
|
||||
|
||||
static bool equalsStrings(Slice lhs, Slice rhs) {
|
||||
ValueLength nl;
|
||||
char const* left = lhs.getString(nl);
|
||||
VELOCYPACK_ASSERT(left != nullptr);
|
||||
ValueLength nr;
|
||||
char const* right = rhs.getString(nr);
|
||||
VELOCYPACK_ASSERT(right != nullptr);
|
||||
return (nl == nr && (memcmp(left, right, nl) == 0));
|
||||
}
|
||||
struct Hash {
|
||||
size_t operator()(arangodb::velocypack::Slice const&) const;
|
||||
};
|
||||
|
||||
static bool equals(Slice lhs, Slice rhs) {
|
||||
lhs = lhs.resolveExternals();
|
||||
rhs = rhs.resolveExternals();
|
||||
ValueType lhsType = valueTypeGroup(lhs.type());
|
||||
ValueType rhsType = valueTypeGroup(rhs.type());
|
||||
struct Equal {
|
||||
arangodb::velocypack::Options const* _options;
|
||||
|
||||
if (lhsType != rhsType) {
|
||||
// unequal types => not equal
|
||||
return false;
|
||||
}
|
||||
Equal() : _options(nullptr) {}
|
||||
explicit Equal(arangodb::velocypack::Options const* opts)
|
||||
: _options(opts) {}
|
||||
|
||||
switch (lhsType) {
|
||||
case ValueType::Illegal:
|
||||
case ValueType::None:
|
||||
case ValueType::Null:
|
||||
// Null equals Null
|
||||
case ValueType::MinKey:
|
||||
case ValueType::MaxKey: {
|
||||
return true;
|
||||
}
|
||||
case ValueType::Bool: {
|
||||
return (lhs.getBoolean() == rhs.getBoolean());
|
||||
}
|
||||
case ValueType::Double:
|
||||
case ValueType::Int:
|
||||
case ValueType::UInt:
|
||||
case ValueType::SmallInt: {
|
||||
return equalsNumbers(lhs, rhs);
|
||||
}
|
||||
case ValueType::String: {
|
||||
return equalsStrings(lhs, rhs);
|
||||
}
|
||||
case ValueType::Array: {
|
||||
ArrayIterator lhsValue(lhs);
|
||||
ArrayIterator rhsValue(rhs);
|
||||
|
||||
ValueLength const n = lhsValue.size();
|
||||
if (n != rhsValue.size()) {
|
||||
// unequal array lengths
|
||||
return false;
|
||||
}
|
||||
for (ValueLength i = 0; i < n; ++i) {
|
||||
// recurse
|
||||
if (!equals(lhsValue.value(), rhsValue.value())) {
|
||||
return false;
|
||||
}
|
||||
lhsValue.next();
|
||||
rhsValue.next();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case ValueType::Object: {
|
||||
std::set<std::string> keys;
|
||||
// get all keys and bring them in order
|
||||
Collection::unorderedKeys(lhs, keys);
|
||||
Collection::unorderedKeys(rhs, keys);
|
||||
for (auto const& key : keys) {
|
||||
// recurse
|
||||
if (!equals(lhs.get(key), rhs.get(key))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case ValueType::Custom: {
|
||||
throw Exception(Exception::NotImplemented, "equals comparison for Custom type is not implemented");
|
||||
}
|
||||
default: {
|
||||
throw Exception(Exception::InternalError, "invalid value type for equals comparison");
|
||||
}
|
||||
}
|
||||
}
|
||||
bool operator()(arangodb::velocypack::Slice const&,
|
||||
arangodb::velocypack::Slice const&) const;
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Library to build up VPack documents.
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2015 ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Copyright 2015, ArangoDB GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef VELOCYPACK_SERIALIZABLE_H
|
||||
#define VELOCYPACK_SERIALIZABLE_H 1
|
||||
|
||||
#include <memory>
|
||||
|
||||
#include "velocypack/velocypack-common.h"
|
||||
|
||||
namespace arangodb {
|
||||
namespace velocypack {
|
||||
class Builder;
|
||||
|
||||
class Serializable {
|
||||
public:
|
||||
virtual void toVelocyPack(Builder&) const = 0;
|
||||
|
||||
// convenience method
|
||||
std::shared_ptr<Builder> toVelocyPack() const;
|
||||
};
|
||||
|
||||
struct Serialize {
|
||||
Serialize(Serializable const& sable) : _sable(sable) {}
|
||||
Serializable const& _sable;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -135,6 +135,14 @@ using VPackParser = arangodb::velocypack::Parser;
|
|||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef VELOCYPACK_SERIALIZABLE_H
|
||||
#ifndef VELOCYPACK_ALIAS_SERIALIZABLE
|
||||
#define VELOCYPACK_ALIAS_SERIALIZABLE
|
||||
using VPackSerializable = arangodb::velocypack::Serializable;
|
||||
using VPackSerialize = arangodb::velocypack::Serialize;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef VELOCYPACK_SLICE_H
|
||||
#ifndef VELOCYPACK_ALIAS_SLICE
|
||||
#define VELOCYPACK_ALIAS_SLICE
|
||||
|
|
|
@ -0,0 +1,161 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Library to build up VPack documents.
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2015 ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Max Neunhoeffer
|
||||
/// @author Jan Steemann
|
||||
/// @author Copyright 2015, ArangoDB GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "velocypack/Compare.h"
|
||||
#include "velocypack/Collection.h"
|
||||
#include "velocypack/Exception.h"
|
||||
#include "velocypack/Iterator.h"
|
||||
#include "velocypack/Options.h"
|
||||
#include "velocypack/Slice.h"
|
||||
#include "velocypack/ValueType.h"
|
||||
|
||||
#include <set>
|
||||
|
||||
using namespace arangodb::velocypack;
|
||||
|
||||
bool BinaryCompare::equals(Slice lhs, Slice rhs) {
|
||||
return lhs.binaryEquals(rhs);
|
||||
}
|
||||
|
||||
size_t BinaryCompare::Hash::operator()(arangodb::velocypack::Slice const& slice) const {
|
||||
return static_cast<size_t>(slice.hash());
|
||||
}
|
||||
|
||||
bool BinaryCompare::Equal::operator()(arangodb::velocypack::Slice const& lhs,
|
||||
arangodb::velocypack::Slice const& rhs) const {
|
||||
return lhs.binaryEquals(rhs);
|
||||
}
|
||||
|
||||
bool NormalizedCompare::equalsNumbers(Slice lhs, Slice rhs) {
|
||||
auto lhsType = lhs.type();
|
||||
if (lhsType == rhs.type()) {
|
||||
// both types are equal
|
||||
if (lhsType == ValueType::Int || lhsType == ValueType::SmallInt) {
|
||||
// use exact comparisons. no need to cast to double
|
||||
return (lhs.getIntUnchecked() == rhs.getIntUnchecked());
|
||||
}
|
||||
|
||||
if (lhsType == ValueType::UInt) {
|
||||
// use exact comparisons. no need to cast to double
|
||||
return (lhs.getUIntUnchecked() == rhs.getUIntUnchecked());
|
||||
}
|
||||
// fallthrough to double comparison
|
||||
}
|
||||
|
||||
return (lhs.getNumericValue<double>() == rhs.getNumericValue<double>());
|
||||
}
|
||||
|
||||
bool NormalizedCompare::equalsStrings(Slice lhs, Slice rhs) {
|
||||
ValueLength nl;
|
||||
char const* left = lhs.getString(nl);
|
||||
VELOCYPACK_ASSERT(left != nullptr);
|
||||
ValueLength nr;
|
||||
char const* right = rhs.getString(nr);
|
||||
VELOCYPACK_ASSERT(right != nullptr);
|
||||
return (nl == nr && (memcmp(left, right, nl) == 0));
|
||||
}
|
||||
|
||||
bool NormalizedCompare::equals(Slice lhs, Slice rhs) {
|
||||
lhs = lhs.resolveExternals();
|
||||
rhs = rhs.resolveExternals();
|
||||
ValueType lhsType = valueTypeGroup(lhs.type());
|
||||
ValueType rhsType = valueTypeGroup(rhs.type());
|
||||
|
||||
if (lhsType != rhsType) {
|
||||
// unequal types => not equal
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (lhsType) {
|
||||
case ValueType::Illegal:
|
||||
case ValueType::None:
|
||||
case ValueType::Null:
|
||||
// Null equals Null
|
||||
case ValueType::MinKey:
|
||||
case ValueType::MaxKey: {
|
||||
return true;
|
||||
}
|
||||
case ValueType::Bool: {
|
||||
return (lhs.getBoolean() == rhs.getBoolean());
|
||||
}
|
||||
case ValueType::Double:
|
||||
case ValueType::Int:
|
||||
case ValueType::UInt:
|
||||
case ValueType::SmallInt: {
|
||||
return equalsNumbers(lhs, rhs);
|
||||
}
|
||||
case ValueType::String: {
|
||||
return equalsStrings(lhs, rhs);
|
||||
}
|
||||
case ValueType::Array: {
|
||||
ArrayIterator lhsValue(lhs);
|
||||
ArrayIterator rhsValue(rhs);
|
||||
|
||||
ValueLength const n = lhsValue.size();
|
||||
if (n != rhsValue.size()) {
|
||||
// unequal array lengths
|
||||
return false;
|
||||
}
|
||||
for (ValueLength i = 0; i < n; ++i) {
|
||||
// recurse
|
||||
if (!equals(lhsValue.value(), rhsValue.value())) {
|
||||
return false;
|
||||
}
|
||||
lhsValue.next();
|
||||
rhsValue.next();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case ValueType::Object: {
|
||||
std::set<std::string> keys;
|
||||
// get all keys and bring them in order
|
||||
Collection::unorderedKeys(lhs, keys);
|
||||
Collection::unorderedKeys(rhs, keys);
|
||||
for (auto const& key : keys) {
|
||||
// recurse
|
||||
if (!equals(lhs.get(key), rhs.get(key))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
case ValueType::Custom: {
|
||||
throw Exception(Exception::NotImplemented, "equals comparison for Custom type is not implemented");
|
||||
}
|
||||
default: {
|
||||
throw Exception(Exception::InternalError, "invalid value type for equals comparison");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
size_t NormalizedCompare::Hash::operator()(arangodb::velocypack::Slice const& slice) const {
|
||||
return static_cast<size_t>(slice.normalizedHash());
|
||||
}
|
||||
|
||||
bool NormalizedCompare::Equal::operator()(arangodb::velocypack::Slice const& lhs,
|
||||
arangodb::velocypack::Slice const& rhs) const {
|
||||
return NormalizedCompare::equals(lhs, rhs);
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
////////////////////////////////////////////////////////////////////////////////
|
||||
/// @brief Library to build up VPack documents.
|
||||
///
|
||||
/// DISCLAIMER
|
||||
///
|
||||
/// Copyright 2015 ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
/// you may not use this file except in compliance with the License.
|
||||
/// You may obtain a copy of the License at
|
||||
///
|
||||
/// http://www.apache.org/licenses/LICENSE-2.0
|
||||
///
|
||||
/// Unless required by applicable law or agreed to in writing, software
|
||||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
/// See the License for the specific language governing permissions and
|
||||
/// limitations under the License.
|
||||
///
|
||||
/// Copyright holder is ArangoDB GmbH, Cologne, Germany
|
||||
///
|
||||
/// @author Copyright 2015, ArangoDB GmbH, Cologne, Germany
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include "velocypack/velocypack-common.h"
|
||||
#include "velocypack/Serializable.h"
|
||||
#include "velocypack/Builder.h"
|
||||
|
||||
using namespace arangodb::velocypack;
|
||||
|
||||
// convenience method
|
||||
std::shared_ptr<Builder> Serializable::toVelocyPack() const {
|
||||
auto builder = std::make_shared<Builder>();
|
||||
this->toVelocyPack(*builder);
|
||||
return builder;
|
||||
}
|
|
@ -34,6 +34,9 @@
|
|||
#include "Scheduler/SchedulerFeature.h"
|
||||
#include "VocBase/LogicalCollection.h"
|
||||
|
||||
#include <velocypack/Collection.h>
|
||||
#include <velocypack/velocypack-aliases.h>
|
||||
|
||||
using namespace arangodb;
|
||||
using namespace arangodb::basics;
|
||||
using namespace arangodb::rest;
|
||||
|
|
|
@ -68,12 +68,14 @@ set(LIB_ARANGO_VPACK
|
|||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/AttributeTranslator.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/Builder.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/Collection.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/Compare.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/Dumper.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/Exception.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/HexDump.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/Iterator.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/Options.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/Parser.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/Serializable.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/Slice.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/SliceStaticData.cpp
|
||||
${PROJECT_SOURCE_DIR}/3rdParty/velocypack/src/StringRef.cpp
|
||||
|
|
Loading…
Reference in New Issue