1
0
Fork 0

Port a velocypack fix.

This commit is contained in:
Max Neunhoeffer 2016-03-14 12:12:54 +01:00
parent 50514610fc
commit c074f47f4e
1 changed files with 11 additions and 8 deletions

View File

@ -423,7 +423,7 @@ Slice Builder::getKey(std::string const& key) const {
} }
uint8_t* Builder::set(Value const& item) { uint8_t* Builder::set(Value const& item) {
auto const oldPos = _start + _pos; auto const oldPos = _pos;
auto ctype = item.cType(); auto ctype = item.cType();
checkKeyIsString(item.valueType() == ValueType::String); checkKeyIsString(item.valueType() == ValueType::String);
@ -668,7 +668,7 @@ uint8_t* Builder::set(Value const& item) {
"Cannot set a ValueType::Custom with this method"); "Cannot set a ValueType::Custom with this method");
} }
} }
return oldPos; return _start + oldPos;
} }
uint8_t* Builder::set(Slice const& item) { uint8_t* Builder::set(Slice const& item) {
@ -687,6 +687,8 @@ uint8_t* Builder::set(ValuePair const& pair) {
// ValueType::Binary, or ValueType::Custom, which can be built // ValueType::Binary, or ValueType::Custom, which can be built
// with two pieces of information // with two pieces of information
auto const oldPos = _pos;
checkKeyIsString(pair.valueType() == ValueType::String); checkKeyIsString(pair.valueType() == ValueType::String);
if (pair.valueType() == ValueType::Binary) { if (pair.valueType() == ValueType::Binary) {
@ -694,7 +696,7 @@ uint8_t* Builder::set(ValuePair const& pair) {
appendUInt(v, 0xbf); appendUInt(v, 0xbf);
memcpy(_start + _pos, pair.getStart(), checkOverflow(v)); memcpy(_start + _pos, pair.getStart(), checkOverflow(v));
_pos += v; _pos += v;
return nullptr; // unused here return _start + oldPos;
} else if (pair.valueType() == ValueType::String) { } else if (pair.valueType() == ValueType::String) {
uint64_t size = pair.getSize(); uint64_t size = pair.getSize();
if (size > 126) { if (size > 126) {
@ -802,12 +804,13 @@ uint8_t* Builder::add(ObjectIterator&& sub) {
if (_keyWritten) { if (_keyWritten) {
throw Exception(Exception::BuilderKeyAlreadyWritten); throw Exception(Exception::BuilderKeyAlreadyWritten);
} }
auto const oldPos = _start + _pos; auto const oldPos = _pos;
while (sub.valid()) { while (sub.valid()) {
add(sub.key().copyString(), sub.value()); add(sub.key());
add(sub.value());
sub.next(); sub.next();
} }
return oldPos; return _start + oldPos;
} }
uint8_t* Builder::add(Value const& sub) { return addInternal<Value>(sub); } uint8_t* Builder::add(Value const& sub) { return addInternal<Value>(sub); }
@ -832,12 +835,12 @@ uint8_t* Builder::add(ArrayIterator&& sub) {
if (_start[tos] != 0x06 && _start[tos] != 0x13) { if (_start[tos] != 0x06 && _start[tos] != 0x13) {
throw Exception(Exception::BuilderNeedOpenArray); throw Exception(Exception::BuilderNeedOpenArray);
} }
auto const oldPos = _start + _pos; auto const oldPos = _pos;
while (sub.valid()) { while (sub.valid()) {
add(sub.value()); add(sub.value());
sub.next(); sub.next();
} }
return oldPos; return _start + oldPos;
} }
static_assert(sizeof(double) == 8, "double is not 8 bytes"); static_assert(sizeof(double) == 8, "double is not 8 bytes");