summaryrefslogtreecommitdiffstats
path: root/document
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@oath.com>2018-06-13 13:39:39 +0200
committerHenning Baldersheim <balder@oath.com>2018-06-14 09:41:07 +0200
commit555b143ec639c9a635d043a6b8d4923c0890d0ac (patch)
tree7ee4d6af04e18c9942156f324731a2779a8c555c /document
parent3302fb4a790925ad0437d2bd7b4747c4d02a971b (diff)
ByteBuffer -> nbostream
Diffstat (limited to 'document')
-rw-r--r--document/src/tests/documentupdatetestcase.cpp23
-rw-r--r--document/src/vespa/document/update/addvalueupdate.cpp39
-rw-r--r--document/src/vespa/document/update/addvalueupdate.h5
-rw-r--r--document/src/vespa/document/update/arithmeticvalueupdate.cpp9
-rw-r--r--document/src/vespa/document/update/arithmeticvalueupdate.h4
-rw-r--r--document/src/vespa/document/update/assignvalueupdate.cpp9
-rw-r--r--document/src/vespa/document/update/assignvalueupdate.h6
-rw-r--r--document/src/vespa/document/update/clearvalueupdate.cpp11
-rw-r--r--document/src/vespa/document/update/clearvalueupdate.h2
-rw-r--r--document/src/vespa/document/update/documentupdate.cpp8
-rw-r--r--document/src/vespa/document/update/fieldupdate.cpp26
-rw-r--r--document/src/vespa/document/update/fieldupdate.h7
-rw-r--r--document/src/vespa/document/update/mapvalueupdate.cpp10
-rw-r--r--document/src/vespa/document/update/mapvalueupdate.h2
-rw-r--r--document/src/vespa/document/update/removevalueupdate.cpp5
-rw-r--r--document/src/vespa/document/update/removevalueupdate.h2
-rw-r--r--document/src/vespa/document/update/valueupdate.cpp8
-rw-r--r--document/src/vespa/document/update/valueupdate.h16
18 files changed, 72 insertions, 120 deletions
diff --git a/document/src/tests/documentupdatetestcase.cpp b/document/src/tests/documentupdatetestcase.cpp
index 2a77d610420..1f12e5d03f8 100644
--- a/document/src/tests/documentupdatetestcase.cpp
+++ b/document/src/tests/documentupdatetestcase.cpp
@@ -119,35 +119,29 @@ ByteBuffer::UP serialize42(const DocumentUpdate & update)
return retVal;
}
-ByteBuffer::UP serialize(const ValueUpdate & update)
+nbostream serialize(const ValueUpdate & update)
{
nbostream stream;
VespaDocumentSerializer serializer(stream);
serializer.write(update);
- ByteBuffer::UP retVal(new ByteBuffer(stream.size()));
- retVal->putBytes(stream.peek(), stream.size());
- return retVal;
+ return stream;
}
-ByteBuffer::UP serialize(const FieldUpdate & update)
+nbostream serialize(const FieldUpdate & update)
{
nbostream stream;
VespaDocumentSerializer serializer(stream);
serializer.write(update);
- ByteBuffer::UP retVal(new ByteBuffer(stream.size()));
- retVal->putBytes(stream.peek(), stream.size());
- return retVal;
+ return stream;
}
template<typename UpdateType>
void testValueUpdate(const UpdateType& update, const DataType &type) {
try{
DocumentTypeRepo repo;
- ByteBuffer::UP buf = serialize(update);
- buf->flip();
+ nbostream stream = serialize(update);
typename UpdateType::UP copy(dynamic_cast<UpdateType*>(
- ValueUpdate::createInstance(repo, type, *buf,
- Document::getNewestSerializationVersion())
+ ValueUpdate::createInstance(repo, type, stream, Document::getNewestSerializationVersion())
.release()));
CPPUNIT_ASSERT_EQUAL(update, *copy);
} catch (std::exception& e) {
@@ -189,9 +183,8 @@ DocumentUpdateTest::testSimpleUsage() {
FieldUpdate fieldUpdate(docType->getField("intf"));
fieldUpdate.addUpdate(AssignValueUpdate(IntFieldValue(1)));
- ByteBuffer::UP fieldBuf = serialize(fieldUpdate);
- fieldBuf->flip();
- FieldUpdate fieldUpdateCopy(repo, *docType, *fieldBuf, Document::getNewestSerializationVersion());
+ nbostream stream = serialize(fieldUpdate);
+ FieldUpdate fieldUpdateCopy(repo, *docType, stream, Document::getNewestSerializationVersion());
CPPUNIT_ASSERT_EQUAL(fieldUpdate, fieldUpdateCopy);
// Test that a document update can be serialized
diff --git a/document/src/vespa/document/update/addvalueupdate.cpp b/document/src/vespa/document/update/addvalueupdate.cpp
index 8ac1ee301eb..2ea328003fc 100644
--- a/document/src/vespa/document/update/addvalueupdate.cpp
+++ b/document/src/vespa/document/update/addvalueupdate.cpp
@@ -9,10 +9,10 @@
#include <vespa/vespalib/objects/nbostream.h>
#include <vespa/vespalib/util/xmlstream.h>
-
using vespalib::IllegalArgumentException;
using vespalib::IllegalStateException;
using vespalib::nbostream;
+using vespalib::make_string;
using namespace vespalib::xml;
namespace document {
@@ -25,7 +25,7 @@ AddValueUpdate:: AddValueUpdate(const FieldValue& value, int weight)
_weight(weight)
{}
-AddValueUpdate::~AddValueUpdate() { }
+AddValueUpdate::~AddValueUpdate() = default;
bool
AddValueUpdate::operator==(const ValueUpdate& other) const
{
@@ -41,19 +41,14 @@ void
AddValueUpdate::checkCompatibility(const Field& field) const
{
if (field.getDataType().inherits(CollectionDataType::classId)) {
- const CollectionDataType& type(
- static_cast<const CollectionDataType&>(field.getDataType()));
+ const CollectionDataType& type(static_cast<const CollectionDataType&>(field.getDataType()));
if (!type.getNestedType().isValueType(*_value)) {
- throw IllegalArgumentException(
- "Cannot add value of type "
- + _value->getDataType()->toString() + " to field "
- + field.getName().c_str() + " of container type "
- + field.getDataType().toString(), VESPA_STRLOC);
+ throw IllegalArgumentException("Cannot add value of type " + _value->getDataType()->toString() +
+ " to field " + field.getName().c_str() + " of container type " +
+ field.getDataType().toString(), VESPA_STRLOC);
}
} else {
- throw IllegalArgumentException(
- "Can not add a value to field of type"
- + field.getDataType().toString(), VESPA_STRLOC);
+ throw IllegalArgumentException("Can not add a value to field of type" + field.getDataType().toString(), VESPA_STRLOC);
}
}
@@ -75,9 +70,7 @@ AddValueUpdate::applyTo(FieldValue& value) const
WeightedSetFieldValue& doc(static_cast<WeightedSetFieldValue&>(value));
doc.add(*_value, _weight);
} else {
- std::string err = vespalib::make_string(
- "Unable to add a value to a \"%s\" field value.",
- value.getClass().name());
+ std::string err = make_string("Unable to add a value to a \"%s\" field value.", value.getClass().name());
throw IllegalStateException(err, VESPA_STRLOC);
}
return true;
@@ -93,23 +86,17 @@ AddValueUpdate::printXml(XmlOutputStream& xos) const
// Deserialize this update from the given buffer.
void
-AddValueUpdate::deserialize(const DocumentTypeRepo& repo,
- const DataType& type,
- ByteBuffer& buffer, uint16_t version)
+AddValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type,
+ nbostream& stream, uint16_t version)
{
- const CollectionDataType* ctype =
- Identifiable::cast<const CollectionDataType*>(&type);
+ const CollectionDataType* ctype = Identifiable::cast<const CollectionDataType*>(&type);
if (ctype == NULL) {
- throw DeserializeException("Can not perform add operation on "
- "non-collection type.");
+ throw DeserializeException("Can not perform add operation on non-collection type.");
}
_value.reset(ctype->getNestedType().createFieldValue().release());
- nbostream stream(buffer.getBufferAtPos(), buffer.getRemaining());
VespaDocumentDeserializer deserializer(repo, stream, version);
deserializer.read(*_value);
- buffer.incPos(buffer.getRemaining() - stream.size());
- buffer.getIntNetwork(_weight);
+ stream >> _weight;
}
}
-
diff --git a/document/src/vespa/document/update/addvalueupdate.h b/document/src/vespa/document/update/addvalueupdate.h
index 439263c5089..ba4dfaaaefa 100644
--- a/document/src/vespa/document/update/addvalueupdate.h
+++ b/document/src/vespa/document/update/addvalueupdate.h
@@ -7,8 +7,8 @@
*/
#pragma once
+#include "valueupdate.h"
#include <vespa/document/fieldvalue/fieldvalue.h>
-#include <vespa/document/update/valueupdate.h>
namespace document {
@@ -68,7 +68,7 @@ public:
void printXml(XmlOutputStream& xos) const override;
void print(std::ostream& out, bool verbose, const std::string& indent) const override;
void deserialize(const DocumentTypeRepo& repo, const DataType& type,
- ByteBuffer& buffer, uint16_t version) override;
+ nbostream & buffer, uint16_t version) override;
AddValueUpdate* clone() const override { return new AddValueUpdate(*this); }
DECLARE_IDENTIFIABLE(AddValueUpdate);
@@ -76,4 +76,3 @@ public:
};
} // document
-
diff --git a/document/src/vespa/document/update/arithmeticvalueupdate.cpp b/document/src/vespa/document/update/arithmeticvalueupdate.cpp
index b84dbe0f366..44470c7b541 100644
--- a/document/src/vespa/document/update/arithmeticvalueupdate.cpp
+++ b/document/src/vespa/document/update/arithmeticvalueupdate.cpp
@@ -2,7 +2,7 @@
#include "arithmeticvalueupdate.h"
#include <vespa/document/base/field.h>
#include <vespa/document/fieldvalue/fieldvalues.h>
-#include <vespa/document/util/bytebuffer.h>
+#include <vespa/vespalib/objects/nbostream.h>
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/util/xmlstream.h>
@@ -127,14 +127,11 @@ ArithmeticValueUpdate::printXml(XmlOutputStream& xos) const
// Deserialize this update from the given buffer.
void
-ArithmeticValueUpdate::deserialize(
- const DocumentTypeRepo&, const DataType&,
- ByteBuffer& buffer, uint16_t)
+ArithmeticValueUpdate::deserialize(const DocumentTypeRepo&, const DataType&, nbostream & stream, uint16_t)
{
int32_t opt;
- buffer.getIntNetwork(opt);
+ stream >> opt >>_operand;
_operator = static_cast<ArithmeticValueUpdate::Operator>(opt);
- buffer.getDoubleNetwork(_operand);
}
} // document
diff --git a/document/src/vespa/document/update/arithmeticvalueupdate.h b/document/src/vespa/document/update/arithmeticvalueupdate.h
index 60718f8ad1f..4990cf3962e 100644
--- a/document/src/vespa/document/update/arithmeticvalueupdate.h
+++ b/document/src/vespa/document/update/arithmeticvalueupdate.h
@@ -8,7 +8,7 @@
*/
#pragma once
-#include <vespa/document/update/valueupdate.h>
+#include "valueupdate.h"
namespace document {
@@ -93,7 +93,7 @@ public:
void printXml(XmlOutputStream& xos) const override;
void print(std::ostream& out, bool verbose, const std::string& indent) const override;
void deserialize(const DocumentTypeRepo& repo, const DataType& type,
- ByteBuffer& buffer, uint16_t version) override;
+ nbostream & buffer, uint16_t version) override;
ArithmeticValueUpdate* clone() const override { return new ArithmeticValueUpdate(*this); }
DECLARE_IDENTIFIABLE(ArithmeticValueUpdate);
diff --git a/document/src/vespa/document/update/assignvalueupdate.cpp b/document/src/vespa/document/update/assignvalueupdate.cpp
index fb38a78690b..3da63e8a5aa 100644
--- a/document/src/vespa/document/update/assignvalueupdate.cpp
+++ b/document/src/vespa/document/update/assignvalueupdate.cpp
@@ -4,7 +4,6 @@
#include <vespa/document/base/field.h>
#include <vespa/document/fieldvalue/fieldvalues.h>
#include <vespa/document/serialization/vespadocumentdeserializer.h>
-#include <vespa/document/util/bytebuffer.h>
#include <vespa/vespalib/objects/nbostream.h>
#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/util/xmlstream.h>
@@ -90,19 +89,17 @@ AssignValueUpdate::printXml(XmlOutputStream& xos) const
// Deserialize this update from the given buffer.
void
-AssignValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer, uint16_t version)
+AssignValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream, uint16_t version)
{
// Read content bit vector.
- unsigned char content = 0x00;
- buffer.getByte(content);
+ uint8_t content = 0x00;
+ stream >> content;
// Read field value, if any.
if (content & CONTENT_HASVALUE) {
_value.reset(type.createFieldValue().release());
- nbostream stream(buffer.getBufferAtPos(), buffer.getRemaining());
VespaDocumentDeserializer deserializer(repo, stream, version);
deserializer.read(*_value);
- buffer.incPos(buffer.getRemaining() - stream.size());
}
}
diff --git a/document/src/vespa/document/update/assignvalueupdate.h b/document/src/vespa/document/update/assignvalueupdate.h
index 05802857f65..661a9ed783c 100644
--- a/document/src/vespa/document/update/assignvalueupdate.h
+++ b/document/src/vespa/document/update/assignvalueupdate.h
@@ -26,7 +26,7 @@ public:
AssignValueUpdate();
AssignValueUpdate(const FieldValue& value);
- ~AssignValueUpdate();
+ ~AssignValueUpdate() override;
bool operator==(const ValueUpdate& other) const override;
@@ -50,10 +50,10 @@ public:
void printXml(XmlOutputStream& xos) const override;
void print(std::ostream& out, bool verbose, const std::string& indent) const override;
void deserialize(const DocumentTypeRepo& repo, const DataType& type,
- ByteBuffer& buffer, uint16_t version) override;
+ nbostream & buffer, uint16_t version) override;
AssignValueUpdate* clone() const override { return new AssignValueUpdate(*this); }
DECLARE_IDENTIFIABLE(AssignValueUpdate);
};
-} // document
+}
diff --git a/document/src/vespa/document/update/clearvalueupdate.cpp b/document/src/vespa/document/update/clearvalueupdate.cpp
index 0a69881181a..7335844dadf 100644
--- a/document/src/vespa/document/update/clearvalueupdate.cpp
+++ b/document/src/vespa/document/update/clearvalueupdate.cpp
@@ -1,14 +1,9 @@
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "clearvalueupdate.h"
-#include <vespa/document/base/field.h>
-#include <vespa/document/fieldvalue/document.h>
-#include <vespa/vespalib/util/exceptions.h>
#include <vespa/vespalib/util/xmlstream.h>
#include <ostream>
-using vespalib::IllegalArgumentException;
-using vespalib::IllegalStateException;
using namespace vespalib::xml;
namespace document {
@@ -29,9 +24,8 @@ ClearValueUpdate::checkCompatibility(const Field&) const
// Apply this update to the given document.
bool
-ClearValueUpdate::applyTo(FieldValue& value) const
+ClearValueUpdate::applyTo(FieldValue& ) const
{
- (void) value;
return false;
}
@@ -50,8 +44,7 @@ ClearValueUpdate::print(std::ostream& out, bool, const std::string&) const
// Deserialize this update from the given buffer.
void
-ClearValueUpdate::deserialize(const DocumentTypeRepo&, const DataType&,
- ByteBuffer&, uint16_t)
+ClearValueUpdate::deserialize(const DocumentTypeRepo&, const DataType&, nbostream &, uint16_t)
{
}
diff --git a/document/src/vespa/document/update/clearvalueupdate.h b/document/src/vespa/document/update/clearvalueupdate.h
index 12f2b888ea1..f58c6cccf1b 100644
--- a/document/src/vespa/document/update/clearvalueupdate.h
+++ b/document/src/vespa/document/update/clearvalueupdate.h
@@ -25,7 +25,7 @@ public:
void printXml(XmlOutputStream& xos) const override;
void print(std::ostream& out, bool verbose, const std::string& indent) const override;
void deserialize(const DocumentTypeRepo& repo, const DataType& type,
- ByteBuffer& buffer, uint16_t version) override;
+ nbostream& buffer, uint16_t version) override;
ClearValueUpdate* clone() const override { return new ClearValueUpdate(*this); }
DECLARE_IDENTIFIABLE(ClearValueUpdate);
diff --git a/document/src/vespa/document/update/documentupdate.cpp b/document/src/vespa/document/update/documentupdate.cpp
index cb0beff6a15..e3aee2f3188 100644
--- a/document/src/vespa/document/update/documentupdate.cpp
+++ b/document/src/vespa/document/update/documentupdate.cpp
@@ -311,11 +311,9 @@ DocumentUpdate::deserialize42(const DocumentTypeRepo& repo, vespalib::nbostream
stream >> sizeAndFlags;
int numUpdates = deserializeFlags(sizeAndFlags);
_updates.reserve(numUpdates);
- ByteBuffer buffer(stream.peek(), stream.size());
for (int i = 0; i < numUpdates; i++) {
- _updates.emplace_back(repo, *typeAndId.first, buffer, _version);
+ _updates.emplace_back(repo, *typeAndId.first, stream, _version);
}
- stream.adjustReadPos(buffer.getPos());
}
} catch (const DeserializeException &) {
stream.rp(pos);
@@ -368,11 +366,9 @@ DocumentUpdate::deserializeHEAD(const DocumentTypeRepo &repo, vespalib::nbostrea
int32_t numUpdates = 0;
stream >> numUpdates;
_updates.reserve(numUpdates);
- ByteBuffer buffer(stream.peek(), stream.size());
for (int i = 0; i < numUpdates; i++) {
- _updates.emplace_back(repo, *docType, buffer, _version);
+ _updates.emplace_back(repo, *docType, stream, _version);
}
- stream.adjustReadPos(buffer.getPos());
}
// Read fieldpath updates, if any
int32_t sizeAndFlags = 0;
diff --git a/document/src/vespa/document/update/fieldupdate.cpp b/document/src/vespa/document/update/fieldupdate.cpp
index 4644ae1f340..a4ef3765570 100644
--- a/document/src/vespa/document/update/fieldupdate.cpp
+++ b/document/src/vespa/document/update/fieldupdate.cpp
@@ -4,11 +4,11 @@
#include <vespa/document/base/exceptions.h>
#include <vespa/document/fieldvalue/document.h>
#include <vespa/document/datatype/documenttype.h>
-#include <vespa/document/util/bytebuffer.h>
+#include <vespa/vespalib/objects/nbostream.h>
namespace document {
-typedef std::vector<ValueUpdate::CP> ValueUpdateList;
+using vespalib::nbostream;
FieldUpdate::FieldUpdate(const Field& field)
: Printable(),
@@ -19,24 +19,24 @@ FieldUpdate::FieldUpdate(const Field& field)
namespace {
-int readInt(ByteBuffer & buffer) {
+int readInt(nbostream & stream) {
int tmp;
- buffer.getIntNetwork(tmp);
+ stream >> tmp;
return tmp;
}
}
-FieldUpdate::FieldUpdate(const DocumentTypeRepo& repo, const DataType & type, ByteBuffer& buffer, int16_t version)
+FieldUpdate::FieldUpdate(const DocumentTypeRepo& repo, const DataType & type, nbostream & stream, int16_t version)
: Printable(),
- _field(type.getField(readInt(buffer))),
+ _field(type.getField(readInt(stream))),
_updates()
{
- int numUpdates = readInt(buffer);
+ int numUpdates = readInt(stream);
_updates.reserve(numUpdates);
const DataType& dataType = _field.getDataType();
for(int i(0); i < numUpdates; i++) {
- _updates.emplace_back(ValueUpdate::createInstance(repo, dataType, buffer, version).release());
+ _updates.emplace_back(ValueUpdate::createInstance(repo, dataType, stream, version).release());
}
}
@@ -105,19 +105,17 @@ FieldUpdate::print(std::ostream& out, bool verbose, const std::string& indent) c
// Deserialize this field update from the given buffer.
void
FieldUpdate::deserialize(const DocumentTypeRepo& repo, const DocumentType& docType,
- ByteBuffer& buffer, int16_t version)
+ nbostream& stream, int16_t version)
{
- int fieldId;
- buffer.getIntNetwork(fieldId);
+ int fieldId = readInt(stream);
_field = docType.getField(fieldId);
const DataType& dataType = _field.getDataType();
- int numUpdates = 0;
- buffer.getIntNetwork(numUpdates);
+ int numUpdates = readInt(stream);
_updates.clear();
_updates.resize(numUpdates);
for(int i = 0; i < numUpdates; i++) {
- _updates[i].reset(ValueUpdate::createInstance(repo, dataType, buffer, version).release());
+ _updates[i].reset(ValueUpdate::createInstance(repo, dataType, stream, version).release());
}
}
diff --git a/document/src/vespa/document/update/fieldupdate.h b/document/src/vespa/document/update/fieldupdate.h
index fa5bac1cca9..0a61ff2de7a 100644
--- a/document/src/vespa/document/update/fieldupdate.h
+++ b/document/src/vespa/document/update/fieldupdate.h
@@ -26,6 +26,7 @@ class FieldUpdate : public vespalib::Identifiable,
{
Field _field;
std::vector<ValueUpdate::CP> _updates;
+ using nbostream = vespalib::nbostream;
public:
typedef vespalib::CloneablePtr<FieldUpdate> CP;
@@ -42,11 +43,11 @@ public:
* a byte buffer by deserializing all its content from the buffer.
*
* @param type A document type that describes the buffer content.
- * @param buffer A byte buffer that contains a serialized field update.
+ * @param stream A stream that contains a serialized field update.
* @param serializationVersion The serialization version the update was serialized with.
*/
FieldUpdate(const DocumentTypeRepo& repo, const DataType & type,
- ByteBuffer& buffer, int16_t version);
+ nbostream & stream, int16_t version);
bool operator==(const FieldUpdate&) const;
bool operator!=(const FieldUpdate & rhs) const { return ! (*this == rhs); }
@@ -94,7 +95,7 @@ public:
* @param serializationVersion The serialization version the update was serialized with.
*/
void deserialize(const DocumentTypeRepo& repo, const DocumentType& type,
- ByteBuffer& buffer, int16_t serializationVersion);
+ nbostream& stream, int16_t serializationVersion);
};
diff --git a/document/src/vespa/document/update/mapvalueupdate.cpp b/document/src/vespa/document/update/mapvalueupdate.cpp
index 568b661e03d..3f5f033452e 100644
--- a/document/src/vespa/document/update/mapvalueupdate.cpp
+++ b/document/src/vespa/document/update/mapvalueupdate.cpp
@@ -5,7 +5,6 @@
#include <vespa/document/fieldvalue/fieldvalues.h>
#include <vespa/document/serialization/vespadocumentdeserializer.h>
#include <vespa/document/util/serializableexceptions.h>
-#include <vespa/document/util/bytebuffer.h>
#include <vespa/vespalib/util/xmlstream.h>
#include <vespa/vespalib/objects/nbostream.h>
@@ -128,18 +127,16 @@ MapValueUpdate::printXml(XmlOutputStream& xos) const
// Deserialize this update from the given buffer.
void
-MapValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer, uint16_t version)
+MapValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream, uint16_t version)
{
- nbostream stream(buffer.getBufferAtPos(), buffer.getRemaining());
VespaDocumentDeserializer deserializer(repo, stream, version);
switch(type.getClass().id()) {
case ArrayDataType::classId:
{
_key.reset(new IntFieldValue);
deserializer.read(*_key);
- buffer.incPos(buffer.getRemaining() - stream.size());
const ArrayDataType& arrayType = static_cast<const ArrayDataType&>(type);
- _update.reset(ValueUpdate::createInstance(repo, arrayType.getNestedType(), buffer, version).release());
+ _update.reset(ValueUpdate::createInstance(repo, arrayType.getNestedType(), stream, version).release());
break;
}
case WeightedSetDataType::classId:
@@ -147,8 +144,7 @@ MapValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type,
const WeightedSetDataType& wset(static_cast<const WeightedSetDataType&>(type));
_key.reset(wset.getNestedType().createFieldValue().release());
deserializer.read(*_key);
- buffer.incPos(buffer.getRemaining() - stream.size());
- _update.reset(ValueUpdate::createInstance(repo, *DataType::INT, buffer, version).release());
+ _update.reset(ValueUpdate::createInstance(repo, *DataType::INT, stream, version).release());
break;
}
default:
diff --git a/document/src/vespa/document/update/mapvalueupdate.h b/document/src/vespa/document/update/mapvalueupdate.h
index 3cfab4fff69..ad1c575bbfe 100644
--- a/document/src/vespa/document/update/mapvalueupdate.h
+++ b/document/src/vespa/document/update/mapvalueupdate.h
@@ -83,7 +83,7 @@ public:
void printXml(XmlOutputStream& xos) const override;
void print(std::ostream& out, bool verbose, const std::string& indent) const override;
void deserialize(const DocumentTypeRepo& repo, const DataType& type,
- ByteBuffer& buffer, uint16_t version) override;
+ nbostream& buffer, uint16_t version) override;
MapValueUpdate* clone() const override { return new MapValueUpdate(*this); }
DECLARE_IDENTIFIABLE(MapValueUpdate);
diff --git a/document/src/vespa/document/update/removevalueupdate.cpp b/document/src/vespa/document/update/removevalueupdate.cpp
index c21e7c93abe..07f7293af0c 100644
--- a/document/src/vespa/document/update/removevalueupdate.cpp
+++ b/document/src/vespa/document/update/removevalueupdate.cpp
@@ -7,7 +7,6 @@
#include <vespa/document/serialization/vespadocumentdeserializer.h>
#include <vespa/vespalib/objects/nbostream.h>
#include <vespa/document/util/serializableexceptions.h>
-#include <vespa/document/util/bytebuffer.h>
#include <vespa/vespalib/util/xmlstream.h>
using vespalib::IllegalArgumentException;
@@ -85,7 +84,7 @@ RemoveValueUpdate::print(std::ostream& out, bool, const std::string&) const
// Deserialize this update from the given buffer.
void
-RemoveValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer, uint16_t version)
+RemoveValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream, uint16_t version)
{
switch(type.getClass().id()) {
case ArrayDataType::classId:
@@ -93,10 +92,8 @@ RemoveValueUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& typ
{
const CollectionDataType& c(static_cast<const CollectionDataType&>(type));
_key.reset(c.getNestedType().createFieldValue().release());
- nbostream stream(buffer.getBufferAtPos(), buffer.getRemaining());
VespaDocumentDeserializer deserializer(repo, stream, version);
deserializer.read(*_key);
- buffer.incPos(buffer.getRemaining() - stream.size());
break;
}
default:
diff --git a/document/src/vespa/document/update/removevalueupdate.h b/document/src/vespa/document/update/removevalueupdate.h
index 6912a6e0bf3..718c30781d8 100644
--- a/document/src/vespa/document/update/removevalueupdate.h
+++ b/document/src/vespa/document/update/removevalueupdate.h
@@ -52,7 +52,7 @@ public:
void printXml(XmlOutputStream& xos) const override;
void print(std::ostream& out, bool verbose, const std::string& indent) const override;
void deserialize(const DocumentTypeRepo& repo, const DataType& type,
- ByteBuffer& buffer, uint16_t version) override;
+ nbostream& buffer, uint16_t version) override;
RemoveValueUpdate* clone() const override { return new RemoveValueUpdate(*this); }
DECLARE_IDENTIFIABLE(RemoveValueUpdate);
diff --git a/document/src/vespa/document/update/valueupdate.cpp b/document/src/vespa/document/update/valueupdate.cpp
index b43f9f7f095..735b637840e 100644
--- a/document/src/vespa/document/update/valueupdate.cpp
+++ b/document/src/vespa/document/update/valueupdate.cpp
@@ -2,7 +2,7 @@
#include "valueupdate.h"
#include <vespa/vespalib/util/stringfmt.h>
-#include <vespa/document/util/bytebuffer.h>
+#include <vespa/vespalib/objects/nbostream.h>
#include <stdexcept>
namespace document {
@@ -11,16 +11,16 @@ IMPLEMENT_IDENTIFIABLE_ABSTRACT(ValueUpdate, Identifiable);
// Create a value update from a byte buffer.
std::unique_ptr<ValueUpdate>
-ValueUpdate::createInstance(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer, int serializationVersion)
+ValueUpdate::createInstance(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream, int serializationVersion)
{
int32_t classId = 0;
- buffer.getIntNetwork(classId);
+ stream >> classId;
const Identifiable::RuntimeClass * rtc(Identifiable::classFromId(classId));
if (rtc != nullptr) {
std::unique_ptr<ValueUpdate> update(static_cast<ValueUpdate*>(rtc->create()));
/// \todo TODO (was warning): Updates are not versioned in serialization format. Will not work without altering it.
- update->deserialize(repo, type, buffer, serializationVersion);
+ update->deserialize(repo, type, stream, serializationVersion);
return update;
} else {
throw std::runtime_error(vespalib::make_string("Could not find a class for classId %d(%x)", classId, classId));
diff --git a/document/src/vespa/document/update/valueupdate.h b/document/src/vespa/document/update/valueupdate.h
index ffa40b1c191..fffa9e2035b 100644
--- a/document/src/vespa/document/update/valueupdate.h
+++ b/document/src/vespa/document/update/valueupdate.h
@@ -24,7 +24,6 @@
namespace document {
-class ByteBuffer;
class DocumentTypeRepo;
class Field;
class FieldValue;
@@ -34,8 +33,10 @@ class ValueUpdate : public vespalib::Identifiable,
public vespalib::Cloneable,
public XmlSerializable
{
+protected:
+ using nbostream = vespalib::nbostream;
public:
- typedef vespalib::CloneablePtr<ValueUpdate> CP;
+ using CP = vespalib::CloneablePtr<ValueUpdate>;
/**
* Create a value update object from the given byte buffer.
@@ -43,9 +44,8 @@ public:
* @param type A data type that describes the content of the buffer.
* @param buffer The byte buffer that containes the serialized update.
*/
- static std::unique_ptr<ValueUpdate> createInstance(
- const DocumentTypeRepo& repo, const DataType& type,
- ByteBuffer& buffer, int serializationVersion);
+ static std::unique_ptr<ValueUpdate> createInstance(const DocumentTypeRepo& repo, const DataType& type,
+ nbostream & buffer, int serializationVersion);
/** Define all types of value updates. */
enum ValueUpdateType {
@@ -90,9 +90,8 @@ public:
* @param buffer The byte buffer that contains the serialized update object.
* @param version The serialization version of the object to deserialize.
*/
- virtual void deserialize(const DocumentTypeRepo& repo,
- const DataType& type,
- ByteBuffer& buffer, uint16_t version) = 0;
+ virtual void deserialize(const DocumentTypeRepo& repo, const DataType& type,
+ nbostream & stream, uint16_t version) = 0;
/** @return The operation type. */
ValueUpdateType getType() const {
@@ -105,7 +104,6 @@ public:
virtual void accept(UpdateVisitor &visitor) const = 0;
DECLARE_IDENTIFIABLE_ABSTRACT(ValueUpdate);
-
};
} // document