diff options
author | Henning Baldersheim <balder@oath.com> | 2018-06-13 23:02:39 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@oath.com> | 2018-06-14 09:41:08 +0200 |
commit | 23583227b115e1160e4149ba43d4f6f3efbdd728 (patch) | |
tree | 098849ff31d414d6b75df29649b3f5151b76304c /document | |
parent | b058a774308940118640b4026f55e6ea4a0bb881 (diff) |
ByteBuffer -> nbostream
Diffstat (limited to 'document')
9 files changed, 30 insertions, 36 deletions
diff --git a/document/src/vespa/document/update/addfieldpathupdate.cpp b/document/src/vespa/document/update/addfieldpathupdate.cpp index c92bd499796..ab719de38d4 100644 --- a/document/src/vespa/document/update/addfieldpathupdate.cpp +++ b/document/src/vespa/document/update/addfieldpathupdate.cpp @@ -5,7 +5,6 @@ #include <vespa/document/fieldvalue/arrayfieldvalue.h> #include <vespa/document/fieldvalue/document.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 <ostream> @@ -89,9 +88,9 @@ AddFieldPathUpdate::print(std::ostream& out, bool verbose, const std::string& in } void -AddFieldPathUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer) +AddFieldPathUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream) { - FieldPathUpdate::deserialize(repo, type, buffer); + FieldPathUpdate::deserialize(repo, type, stream); FieldPath path; type.buildFieldPath(path, getOriginalFieldPath()); @@ -99,10 +98,8 @@ AddFieldPathUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& ty assert(fieldType.inherits(ArrayDataType::classId)); FieldValue::UP val = fieldType.createFieldValue(); _values.reset(static_cast<ArrayFieldValue*>(val.release())); - nbostream stream(buffer.getBufferAtPos(), buffer.getRemaining()); VespaDocumentDeserializer deserializer(repo, stream, Document::getNewestSerializationVersion()); deserializer.read(*_values); - buffer.incPos(buffer.getRemaining() - stream.size()); } std::unique_ptr<IteratorHandler> diff --git a/document/src/vespa/document/update/addfieldpathupdate.h b/document/src/vespa/document/update/addfieldpathupdate.h index d7dbfc0e91e..692a30e3a73 100644 --- a/document/src/vespa/document/update/addfieldpathupdate.h +++ b/document/src/vespa/document/update/addfieldpathupdate.h @@ -26,7 +26,7 @@ public: private: uint8_t getSerializedType() const override { return AddMagic; } - void deserialize(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer) override; + void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream) override; std::unique_ptr<fieldvalue::IteratorHandler> getIteratorHandler(Document &, const DocumentTypeRepo &) const override; diff --git a/document/src/vespa/document/update/assignfieldpathupdate.cpp b/document/src/vespa/document/update/assignfieldpathupdate.cpp index f33f2928743..bec717874dc 100644 --- a/document/src/vespa/document/update/assignfieldpathupdate.cpp +++ b/document/src/vespa/document/update/assignfieldpathupdate.cpp @@ -6,7 +6,6 @@ #include <vespa/document/select/parser.h> #include <vespa/document/select/variablemap.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 <boost/numeric/conversion/cast.hpp> @@ -218,26 +217,24 @@ AssignFieldPathUpdate::print(std::ostream& out, bool verbose, const std::string& } void -AssignFieldPathUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer) +AssignFieldPathUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream) { - FieldPathUpdate::deserialize(repo, type, buffer); + FieldPathUpdate::deserialize(repo, type, stream); uint8_t flags = 0x00; - buffer.getByte(flags); + stream >> flags; _removeIfZero = (flags & REMOVE_IF_ZERO) != 0; _createMissingPath = (flags & CREATE_MISSING_PATH) != 0; if (flags & ARITHMETIC_EXPRESSION) { - _expression = getString(buffer); + _expression = getString(stream); } else { FieldPath path; type.buildFieldPath(path, getOriginalFieldPath()); _newValue.reset(getResultingDataType(path).createFieldValue().release()); - nbostream stream(buffer.getBufferAtPos(), buffer.getRemaining()); VespaDocumentDeserializer deserializer(repo, stream, Document::getNewestSerializationVersion()); deserializer.read(*_newValue); - buffer.incPos(buffer.getRemaining() - stream.size()); } } diff --git a/document/src/vespa/document/update/assignfieldpathupdate.h b/document/src/vespa/document/update/assignfieldpathupdate.h index 40452d4d6fb..494da69792d 100644 --- a/document/src/vespa/document/update/assignfieldpathupdate.h +++ b/document/src/vespa/document/update/assignfieldpathupdate.h @@ -44,7 +44,7 @@ public: private: uint8_t getSerializedType() const override { return AssignMagic; } - void deserialize(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer) override; + void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream) override; std::unique_ptr<fieldvalue::IteratorHandler> getIteratorHandler(Document& doc, const DocumentTypeRepo & repo) const override; diff --git a/document/src/vespa/document/update/documentupdate.cpp b/document/src/vespa/document/update/documentupdate.cpp index 21cd9b17e82..f57baa22f14 100644 --- a/document/src/vespa/document/update/documentupdate.cpp +++ b/document/src/vespa/document/update/documentupdate.cpp @@ -373,11 +373,9 @@ DocumentUpdate::deserializeHEAD(const DocumentTypeRepo &repo, vespalib::nbostrea stream >> sizeAndFlags; int numUpdates = deserializeFlags(sizeAndFlags); _fieldPathUpdates.reserve(numUpdates); - ByteBuffer buffer(stream.peek(), stream.size()); for (int i = 0; i < numUpdates; ++i) { - _fieldPathUpdates.emplace_back(FieldPathUpdate::createInstance(repo, *_type, buffer).release()); + _fieldPathUpdates.emplace_back(FieldPathUpdate::createInstance(repo, *_type, stream).release()); } - stream.adjustReadPos(buffer.getPos()); } catch (const DeserializeException &) { stream.rp(pos); throw; diff --git a/document/src/vespa/document/update/fieldpathupdate.cpp b/document/src/vespa/document/update/fieldpathupdate.cpp index e172b14a846..e7d5824b6e0 100644 --- a/document/src/vespa/document/update/fieldpathupdate.cpp +++ b/document/src/vespa/document/update/fieldpathupdate.cpp @@ -5,7 +5,7 @@ #include <vespa/document/fieldvalue/iteratorhandler.h> #include <vespa/document/select/parser.h> #include <vespa/document/util/serializableexceptions.h> -#include <vespa/document/util/bytebuffer.h> +#include <vespa/vespalib/objects/nbostream.h> #include <ostream> #include <vespa/log/log.h> @@ -106,28 +106,29 @@ FieldPathUpdate::getResultingDataType(const FieldPath & path) const return path.back().getDataType(); } -vespalib::string -FieldPathUpdate::getString(ByteBuffer& buffer) +vespalib::stringref +FieldPathUpdate::getString(nbostream & stream) { - int32_t length = 0; - buffer.getIntNetwork(length); - vespalib::string s(buffer.getBufferAtPos()); - buffer.incPos(length); + uint32_t sz(0); + stream >> sz; + + vespalib::stringref s(stream.peek(), sz - 1); + stream.adjustReadPos(sz); return s; } void -FieldPathUpdate::deserialize(const DocumentTypeRepo&, const DataType&, ByteBuffer& buffer) +FieldPathUpdate::deserialize(const DocumentTypeRepo&, const DataType&, nbostream & stream) { - _originalFieldPath = getString(buffer); - _originalWhereClause = getString(buffer); + _originalFieldPath = getString(stream); + _originalWhereClause = getString(stream); } std::unique_ptr<FieldPathUpdate> -FieldPathUpdate::createInstance(const DocumentTypeRepo& repo, const DataType &type, ByteBuffer& buffer) +FieldPathUpdate::createInstance(const DocumentTypeRepo& repo, const DataType &type, nbostream& stream) { unsigned char updateType = 0; - buffer.getByte(updateType); + stream >> updateType; std::unique_ptr<FieldPathUpdate> update; switch (updateType) { @@ -143,7 +144,7 @@ FieldPathUpdate::createInstance(const DocumentTypeRepo& repo, const DataType &ty default: throw DeserializeException(make_string("Unknown fieldpath update type: %d", updateType), VESPA_STRLOC); } - update->deserialize(repo, type, buffer); + update->deserialize(repo, type, stream); return update; } diff --git a/document/src/vespa/document/update/fieldpathupdate.h b/document/src/vespa/document/update/fieldpathupdate.h index bd2a70743cb..1f820bb661f 100644 --- a/document/src/vespa/document/update/fieldpathupdate.h +++ b/document/src/vespa/document/update/fieldpathupdate.h @@ -23,13 +23,14 @@ class FieldPathUpdate : public vespalib::Cloneable, public vespalib::Identifiable { protected: + using nbostream = vespalib::nbostream; using stringref = vespalib::stringref; /** To be used for deserialization */ FieldPathUpdate(); FieldPathUpdate(const FieldPathUpdate &); FieldPathUpdate & operator =(const FieldPathUpdate &); - static vespalib::string getString(ByteBuffer& buffer); + static stringref getString(nbostream & stream); public: using SP = std::shared_ptr<FieldPathUpdate>; using CP = vespalib::CloneablePtr<FieldPathUpdate>; @@ -71,7 +72,7 @@ public: /** Deserializes and creates a new FieldPathUpdate instance. * Requires type id to be not yet read. */ - static std::unique_ptr<FieldPathUpdate> createInstance(const DocumentTypeRepo& repo, const DataType &type, ByteBuffer& buffer); + static std::unique_ptr<FieldPathUpdate> createInstance(const DocumentTypeRepo& repo, const DataType &type, nbostream & stream); protected: FieldPathUpdate(stringref fieldPath, stringref whereClause = stringref()); @@ -84,7 +85,7 @@ protected: * @param buffer The byte buffer that contains the serialized object. * @param version The serialization version of the object to deserialize. */ - virtual void deserialize(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer); + virtual void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream); /** @return the datatype of the last path element in the field path */ const DataType& getResultingDataType(const FieldPath & path) const; diff --git a/document/src/vespa/document/update/removefieldpathupdate.cpp b/document/src/vespa/document/update/removefieldpathupdate.cpp index 709a5b37793..57832055001 100644 --- a/document/src/vespa/document/update/removefieldpathupdate.cpp +++ b/document/src/vespa/document/update/removefieldpathupdate.cpp @@ -36,9 +36,9 @@ RemoveFieldPathUpdate::print(std::ostream& out, bool verbose, const std::string& } void -RemoveFieldPathUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer) +RemoveFieldPathUpdate::deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & stream) { - FieldPathUpdate::deserialize(repo, type, buffer); + FieldPathUpdate::deserialize(repo, type, stream); } namespace { diff --git a/document/src/vespa/document/update/removefieldpathupdate.h b/document/src/vespa/document/update/removefieldpathupdate.h index d53a7787ea5..2a336985909 100644 --- a/document/src/vespa/document/update/removefieldpathupdate.h +++ b/document/src/vespa/document/update/removefieldpathupdate.h @@ -23,7 +23,7 @@ public: private: uint8_t getSerializedType() const override { return RemoveMagic; } - void deserialize(const DocumentTypeRepo& repo, const DataType& type, ByteBuffer& buffer) override; + void deserialize(const DocumentTypeRepo& repo, const DataType& type, nbostream & buffer) override; std::unique_ptr<fieldvalue::IteratorHandler> getIteratorHandler(Document &, const DocumentTypeRepo &) const override; }; |