8000 updated vpack library · thurt/arangodb@e58a63f · GitHub
[go: up one dir, main page]

Skip to content

Commit e58a63f

Browse files
committed
updated vpack library
1 parent 50947df commit e58a63f

File tree

2 files changed

+71
-7
lines changed

2 files changed

+71
-7
lines changed

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

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@
4545

4646
namespace arangodb {
4747
namespace velocypack {
48+
class ArrayIterator;
49+
class ObjectIterator;
4850

4951
class Builder {
5052
friend class Parser; // The parser needs access to internals.
@@ -289,7 +291,12 @@ class Builder {
289291
}
290292

291293
// Return a Slice of the result:
292-
Slice slice() const { return Slice(start(), options); }
294+
Slice slice() const {
295+
if (isEmpty()) {
296+
return Slice();
297+
}
298+
return Slice(start(), options);
299+
}
293300

294301
// Compute the actual size here, but only when sealed
295302
ValueLength size() const {
@@ -327,6 +334,11 @@ class Builder {
327334

328335
// Add a subvalue into an object from a ValuePair:
329336
uint8_t* add(std::string const& attrName, ValuePair const& sub);
337+
338+
// Add all subkeys and subvalues into an object from an ObjectIterator
339+
// and leaves open the object intentionally
340+
uint8_t* add(ObjectIterator& sub);
341+
uint8_t* add(ObjectIterator&& sub);
330342

331343
// Add a subvalue into an array from a Value:
332344
uint8_t* add(Value const& sub);
@@ -336,9 +348,14 @@ class Builder {
336348

337349
// Add a subvalue into an array from a ValuePair:
338350
uint8_t* add(ValuePair const& sub);
351+
352+
// Add all subvalues into an array from an ArrayIterator
353+
// and leaves open the array intentionally
354+
uint8_t* add(ArrayIterator& sub);
355+
uint8_t* add(ArrayIterator&& sub);
339356

340357
// Seal the innermost array or object:
341-
void close();
358+
Builder& close();
342359

343360
// Remove last subvalue written to an (unclosed) object or array:
344361
// Throws if an error occurs.
@@ -607,7 +624,6 @@ class Builder {
607624
}
608625
throw;
609626
}
610-
611627
}
612628

613629
uint8_t* set(Value const& item);

3rdParty/velocypack/src/Builder.cpp

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "velocypack/velocypack-common.h"
3030
#include "velocypack/Builder.h"
3131
#include "velocypack/Dumper.h"
32+
#include "velocypack/Iterator.h"
3233
#include "velocypack/Sink.h"
3334

3435
using namespace arangodb::velocypack;
@@ -168,7 +169,7 @@ void Builder::removeLast() {
168169
index.pop_back();
169170
}
170171

171-
void Builder::close() {
172+
Builder& Builder::close() {
172173
if (isClosed()) {
173174
throw Exception(Exception::BuilderNeedOpenCompound);
174175
}
@@ -188,7 +189,7 @@ void Builder::close() {
188189
_pos -= 8; // no bytelength and number subvalues needed
189190
_stack.pop_back();
190191
// Intentionally leave _index[depth] intact to avoid future allocs!
191-
return;
192+
return *this;
192193
}
193194

194195
// From now on index.size() > 0
@@ -237,7 +238,7 @@ void Builder::close() {
237238
_pos += nLen + bLen;
238239

239240
_stack.pop_back();
240-
return;
241+
return *this;
241242
}
242243
}
243244

@@ -379,6 +380,7 @@ void Builder::close() {
379380
// off the _stack:
380381
_stack.pop_back();
381382
// Intentionally leave _index[depth] intact to avoid future allocs!
383+
return *this;
382384
}
383385

384386
// checks whether an Object value has a specific key attribute
@@ -675,7 +677,6 @@ uint8_t* Builder::set(Value const& item) {
675677
}
676678

677679
uint8_t* Builder::set(Slice const& item) {
678-
679680
checkKeyIsString(item.isString());
680681

681682
ValueLength const l = item.byteSize();
@@ -788,6 +789,31 @@ uint8_t* Builder::add(std::string const& attrName, ValuePair const& sub) {
788789
uint8_t* Builder::add(std::string const& attrName, Slice const& sub) {
789790
return addInternal<Slice>(attrName, sub);
790791
}
792+
793+
// Add all subkeys and subvalues into an object from an ObjectIterator
794+
// and leaves open the object intentionally
795+
uint8_t* Builder::add(ObjectIterator& sub) {
796+
return add(std::move(sub));
797+
}
798+
799+
uint8_t* Builder::add(ObjectIterator&& sub) {
800+
if (_stack.empty()) {
801+
throw Exception(Exception::BuilderNeedOpenObject);
802+
}
803+
ValueLength& tos = _stack.back();
804+
if (_start[tos] != 0x0b && _start[tos] != 0x14) {
805+
throw Exception(Exception::BuilderNeedOpenObject);
806+
}
807+
if (_keyWritten) {
808+
throw Exception(Exception::BuilderKeyAlreadyWritten);
809+
}
810+
auto const oldPos = _start + _pos;
811+
while (sub.valid()) {
812+
add(sub.key().copyString(), sub.value());
813+
sub.next();
814+
}
815+
return oldPos;
816+
}
791817

792818
uint8_t* Builder::add(Value const& sub) { return addInternal<Value>(sub); }
793819

@@ -797,4 +823,26 @@ uint8_t* Builder::add(ValuePair const& sub) {
797823

798824
uint8_t* Builder::add(Slice const& sub) { return addInternal<Slice>(sub); }
799825

826+
// Add all subkeys and subvalues into an object from an ArrayIterator
827+
// and leaves open the array intentionally
828+
uint8_t* Builder::add(ArrayIterator& sub) {
829+
return add(std::move(sub));
830+
}
831+
832+
uint8_t* Builder::add(ArrayIterator&& sub) {
833+
if (_stack.empty()) {
834+
throw Exception(Exception::BuilderNeedOpenArray);
835+
}
836+
ValueLength& tos = _stack.back();
837+
if (_start[tos] != 0x06 && _start[tos] != 0x13) {
838+
throw Exception(Exception::BuilderNeedOpenArray);
839+
}
840+
auto const oldPos = _start + _pos;
841+
while (sub.valid()) {
842+
add(sub.value());
843+
sub.next();
844+
}
845+
return oldPos;
846+
}
847+
800848
static_assert(sizeof(double) == 8, "double is not 8 bytes");

0 commit comments

Comments
 (0)
0