8000 update velocypack version (#9379) · arangodb/arangodb@2f90f5e · GitHub
[go: up one dir, main page]

Skip to content

Commit 2f90f5e

Browse files
authored
update velocypack version (#9379)
1 parent 12775c2 commit 2f90f5e

File tree

9 files changed

+359
-125
lines changed

9 files changed

+359
-125
lines changed

3rdParty/velocypack/include/velocypack/Builder.h

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "velocypack/Buffer.h"
4141
#include "velocypack/Exception.h"
4242
#include "velocypack/Options.h"
43+
#include "velocypack/Serializable.h"
4344
#include "velocypack/Slice.h"
4445
#include "velocypack/StringRef.h"
4546
#include "velocypack/Value.h"
@@ -74,7 +75,7 @@ class Builder {
7475
// buffer. Whenever the stack is empty, one can use the start,
7576
// size and slice methods to get out the ready built VPack
7677
// object(s).
77-
78+
7879
private:
7980
std::shared_ptr<Buffer<uint8_t>> _buffer; // Here we collect the result
8081
Buffer<uint8_t>* _bufferPtr; // used for quicker access than shared_ptr
@@ -89,10 +90,10 @@ class Builder {
8990

9091
public:
9192
Options const* options;
92-
93-
// create an empty Builder, using default Options
93+
94+
// create an empty Builder, using default Options
9495
Builder();
95-
96+
9697
explicit Builder(Options const* options);
9798
explicit Builder(std::shared_ptr<Buffer<uint8_t>> const& buffer,
< 8000 /code>
9899
Options const* options = &Options::Defaults);
@@ -208,15 +209,15 @@ class Builder {
208209
ValueLength const tos = _stack.back();
209210
return _start[tos] == 0x0b || _start[tos] == 0x14;
210211
}
211-
212+
212213
inline void openArray(bool unindexed = false) {
213214
openCompoundValue(unindexed ? 0x13 : 0x06);
214215
}
215216

216217
inline void openObject(bool unindexed = false) {
217218
openCompoundValue(unindexed ? 0x14 : 0x0b);
218219
}
219-
220+
220221
template <typename T>
221222
uint8_t* addUnchecked(char const* attrName, std::size_t attrLength, T const& sub) {
222223
bool haveReported = false;
@@ -251,7 +252,7 @@ class Builder {
251252
inline uint8_t* add(char const* attrName, std::size_t attrLength, Value const& sub) {
252253
return addInternal<Value>(attrName, attrLength, sub);
253254
}
254-
255+
255256
// Add a subvalue into an object from a Slice:
256257
inline uint8_t* add(std::string const& attrName, Slice const& sub) {
257258
return addInternal<Slice>(attrName, sub);
@@ -265,7 +266,7 @@ class Builder {
265266
inline uint8_t* add(char const* attrName, std::size_t attrLength, Slice const& sub) {
266267
return addInternal<Slice>(attrName, attrLength, sub);
267268
}
268-
269+
269270
// Add a subvalue into an object from a ValuePair:
270271
inline uint8_t* add(std::string const& attrName, ValuePair const& sub) {
271272
return addInternal<ValuePair>(attrName, sub);
@@ -279,22 +280,41 @@ class Builder {
279280
inline uint8_t* add(char const* attrName, std::size_t attrLength, ValuePair const& sub) {
280281
return addInternal<ValuePair>(attrName, attrLength, sub);
281282
}
282-
283+
284+
// Add a subvalue into an object from a Serializable:
285+
inline uint8_t* add(std::string const& attrName, Serialize const& sub) {
286+
return addInternal<Serializable>(attrName, sub._sable);
287+
}
288+
inline uint8_t* add(StringRef const& attrName, Serialize const& sub) {
289+
return addInternal<Serializable>(attrName, sub._sable);
290+
}
291+
inline uint8_t* add(char const* attrName, Serialize const& sub) {
292+
return addInternal<Serializable>(attrName, sub._sable);
293+
}
294+
inline uint8_t* add(char const* attrName, std::size_t attrLength, Serialize const& sub) {
295+
return addInternal<Serializable>(attrName, attrLength, sub._sable);
296+
}
297+
283298
// Add a subvalue into an array from a Value:
284299
inline uint8_t* add(Value const& sub) {
285-
return addInternal<Value>(sub);
300+
return addInternal<Value>(sub);
286301
}
287-
302+
288303
// Add a slice to an array
289304
inline uint8_t* add(Slice const& sub) {
290-
return addInternal<Slice>(sub);
305+
return addInternal<Slice>(sub);
291306
}
292307

293308
// Add a subvalue into an array from a ValuePair:
294309
inline uint8_t* add(ValuePair const& sub) {
295310
return addInternal<ValuePair>(sub);
296311
}
297312

313+
// Add a subvalue into an array from a Serializable:
314+
inline uint8_t* add(Serialize const& sub) {
315+
return addInternal<Serializable>(sub._sable);
316+
}
317+
298318
// Add an External slice to an array
299319
uint8_t* addExternal(uint8_t const* sub) {
300320
if (options->disallowExternals) {
@@ -327,7 +347,7 @@ class Builder {
327347
throw;
328348
}
329349
}
330-
350+
331351
// Add all subkeys and subvalues into an object from an ObjectIterator
332352
// and leaves open the object intentionally
333353
uint8_t* add(ObjectIterator&& sub);
@@ -445,18 +465,23 @@ class Builder {
445465

446466
void addInt(int64_t v) {
447467
if (v >= 0 && v <= 9) {
468+
// SmallInt
448469
appendByte(static_cast<uint8_t>(0x30 + v));
449470
} else if (v < 0 && v >= -6) {
471+
// SmallInt
450472
appendByte(static_cast<uint8_t>(0x40 + v));
451473
} else {
474+
// regular int
452475
appendInt(v, 0x1f);
453476
}
454477
}
455478

456479
void addUInt(uint64_t v) {
457480
if (v <= 9) {
481+
// SmallInt
458482
appendByte(static_cast<uint8_t>(0x30 + v));
459483
} else {
484+
// regular UInt
460485
appendUInt(v, 0x27);
461486
}
462487
}
@@ -524,7 +549,7 @@ class Builder {
524549
uint8_t* addInternal(std::string const& attrName, T const& sub) {
525550
return addInternal<T>(attrName.data(), attrName.size(), sub);
526551
}
527-
552+
528553
template <typename T>
529554
uint8_t* addInternal(StringRef const& attrName, T const& sub) {
530555
return addInternal<T>(attrName.data(), attrName.size(), sub);
@@ -579,7 +604,7 @@ class Builder {
579604
throw;
580605
}
581606
}
582-
607+
583608
void addCompoundValue(uint8_t type) {
584609
reserve(9);
585610
// an Array or Object is started:
@@ -624,6 +649,12 @@ class Builder {
624649

625650
uint8_t* set(Slice const& item);
626651

652+
uint8_t* set(Serializable const& sable) {
653+
auto const oldPos = _pos;
654+
sable.toVelocyPack(*this);
655+
return _start + oldPos;
656+
}
657+
627658
void cleanupAdd() noexcept {
628659
std::size_t depth = _stack.size() - 1;
629660
VELOCYPACK_ASSERT(!_index[depth].empty());
@@ -640,7 +671,7 @@ class Builder {
640671
reserve(n);
641672
appendLengthUnchecked<n>(v);
642673
}
643-
674+
644675
template <uint64_t n>
645676
void appendLengthUnchecked(ValueLength v) {
646677
for (uint64_t i = 0; i < n; ++i) {
@@ -695,18 +726,18 @@ class Builder {
695726
x >>= 8;
696727
}
697728
}
698-
729+
699730
inline void appendByte(uint8_t value) {
700731
reserve(1);
701732
appendByteUnchecked(value);
702733
}
703-
734+
704735
inline void appendByteUnchecked(uint8_t value) {
705736
_start[_pos++] = value;
706737
VELOCYPACK_ASSERT(_bufferPtr != nullptr);
707738
_bufferPtr->advance();
708739
}
709-
740+
710741
inline void resetTo(std::size_t value) {
711742
_pos = value;
712743
VELOCYPACK_ASSERT(_bufferPtr != nullptr);
@@ -719,7 +750,7 @@ class Builder {
719750
VELOCYPACK_ASSERT(_bufferPtr != nullptr);
720751
_bufferPtr->advance(value);
721752
}
722-
753+
723754
// move byte position x bytes back
724755
inline void rollback(std::size_t value) noexcept {
725756
_pos -= value;

3rdParty/velocypack/include/velocypack/Compare.h

Lines changed: 45 additions & 104 deletions
-
VELOCYPACK_ASSERT(right != nullptr);
Original file line numberDiff line numberDiff line change
@@ -28,122 +28,63 @@
2828
#define VELOCYPACK_COMPARE_H 1
2929

3030
#include "velocypack/velocypack-common.h"
31-
#include "velocypack/Collection.h"
32-
#include "velocypack/Exception.h"
33-
#include "velocypack/Iterator.h"
34-
#include "velocypack/Slice.h"
35-
#include "velocypack/ValueType.h"
36-
37-
#include <set>
3831

3932
namespace arangodb {
4033
namespace velocypack {
34+
struct Options;
35+
class Slice;
36+
37+
// helper struct for comparing VelocyPack Slices on a binary level
38+
struct BinaryCompare {
39+
// returns true if the two Slices are identical on the binary level
40+
static bool equals(Slice lhs, Slice rhs);
41+
42+
struct Hash {
43+
size_t operator()(arangodb::velocypack::Slice const&) const;
44+
};
45+
46+
struct Equal {
47+
arangodb::velocypack::Options const* _options;
48+
49+
Equal() : _options(nullptr) {}
50+
explicit Equal(arangodb::velocypack::Options const* opts)
51+
: _options(opts) {}
52+
53+
bool operator()(arangodb::velocypack::Slice const&,
54+
arangodb::velocypack::Slice const&) const;
55+
};
56+
57+
};
58+
59+
// helper struct for comparing VelocyPack Slices in a normalized way
4160
struct NormalizedCompare {
4261

43-
static bool equalsNumbers(Slice lhs, Slice rhs) {
44-
auto lhsType = lhs.type();
45-
if (lhsType == rhs.type()) {
46-
// both types are equal
47-
if (lhsType == ValueType::Int || lhsType == ValueType::SmallInt) {
48-
// use exact comparisons. no need to cast to double
49-
return (lhs.getIntUnchecked() == rhs.getIntUnchecked());
50-
}
51-
52-
if (lhsType == ValueType::UInt) {
53-
// use exact comparisons. no need to cast to double
54-
return (lhs.getUIntUnchecked() == rhs.getUIntUnchecked());
55-
}
56-
// fallthrough to double comparison
57-
}
58-
59-
return (lhs.getNumericValue<double>() == rhs.getNumericValue<double>());
60-
}
62+
// function to compare two numeric values
63+
static bool equalsNumbers(Slice lhs, Slice rhs);
6164

62-
static bool equalsStrings(Slice lhs, Slice rhs) {
63-
ValueLength nl;
64-
char const* left = lhs.getString(nl);
65-
VELOCYPACK_ASSERT(left != nullptr);
66-
ValueLength nr;
67-
char const* right = rhs.getString(nr);
68
69-
return (nl == nr && (memcmp(left, right, nl) == 0));
70-
}
65+
// function to compare two string values
66+
static bool equalsStrings(Slice lhs, Slice rhs);
7167

72-
static bool equals(Slice lhs, Slice rhs) {
73-
lhs = lhs.resolveExternals();
74-
rhs = rhs.resolveExternals();
75-
ValueType lhsType = valueTypeGroup(lhs.type());
76-
ValueType rhsType = valueTypeGroup(rhs.type());
68+
// function to compare two arbitrary Slices
69+
static bool equals(Slice lhs, Slice rhs);
7770

78-
if (lhsType != rhsType) {
79-
// unequal types => not equal
80-
return false;
81-
}
71+
struct Hash {
72+
size_t operator()(arangodb::velocypack::Slice const&) const;
73+
};
8274

83-
switch (lhsType) {
84-
case ValueType::Illegal:
85-
case ValueType::None:
86-
case ValueType::Null:
87-
// Null equals Null
88-
case ValueType::MinKey:
89-
case ValueType::MaxKey: {
90-
return true;
91-
}
92-
case ValueType::Bool: {
93-
return (lhs.getBoolean() == rhs.getBoolean());
94-
}
95-
case ValueType::Double:
96-
case ValueType::Int:
97-
case ValueType::UInt:
98-
case ValueType::SmallInt: {
99-
return equalsNumbers(lhs, rhs);
100-
}
101-
case ValueType::String: {
102-
return equalsStrings(lhs, rhs);
103-
}
104-
case ValueType::Array: {
105-
ArrayIterator lhsValue(lhs);
106-
ArrayIterator rhsValue(rhs);
107-
108-
ValueLength const n = lhsValue.size();
109-
if (n != rhsValue.size()) {
110-
// unequal array lengths
111-
return false;
112-
}
113-
for (ValueLength i = 0; i < n; ++i) {
114-
// recurse
115-
if (!equals(lhsValue.value(), rhsValue.value())) {
116-
return false;
117-
}
118-
lhsValue.next();
119-
rhsValue.next();
120-
}
121-
return true;
122-
}
123-
case ValueType::Object: {
124-
std::set<std::string> keys;
125-
// get all keys and bring them in order
126-
Collection::unorderedKeys(lhs, keys);
127-
Collection::unorderedKeys(rhs, keys);
128-
for (auto const& key : keys) {
129-
// recurse
130-
if (!equals(lhs.get(key), rhs.get(key))) {
131-
return false;
132-
}
133-
}
134-
return true;
135-
}
136-
case ValueType::Custom: {
137-
throw Exception(Exception::NotImplemented, "equals comparison for Custom type is not implemented");
138-
}
139-
default: {
140-
throw Exception(Exception::InternalError, "invalid value type for equals comparison");
141-
}
142-
}
143-
}
75+
struct Equal {
76+
arangodb::velocypack::Options const* _options;
77+
78+
Equal() : _options(nullptr) {}
79+
explicit Equal(arangodb::velocypack::Options const* opts)
80+
: _options(opts) {}
14481

82+
bool operator()(arangodb::velocypack::Slice const&,
83+
arangodb::velocypack::Slice const&) const;
14584
};
14685

86+
};
87+
14788
}
14889
}
14990

0 commit comments

Comments
 (0)
0