diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2017-09-25 13:35:56 +0200 |
---|---|---|
committer | Henning Baldersheim <balder@yahoo-inc.com> | 2017-09-25 13:35:56 +0200 |
commit | 763ad59caa0cc8a565328e7d852b77c12804f25d (patch) | |
tree | 4be1422d1e8b8c7da267b8ffbdbde142d904664c /storageapi | |
parent | 835d135a7c4ac42d7c4d6017c0da6a6684908d9d (diff) |
Do not copy more than you have.
Diffstat (limited to 'storageapi')
10 files changed, 28 insertions, 50 deletions
diff --git a/storageapi/src/vespa/storageapi/mbusprot/storagecommand.cpp b/storageapi/src/vespa/storageapi/mbusprot/storagecommand.cpp index 08fecfab666..8aa44a0d7bf 100644 --- a/storageapi/src/vespa/storageapi/mbusprot/storagecommand.cpp +++ b/storageapi/src/vespa/storageapi/mbusprot/storagecommand.cpp @@ -1,13 +1,11 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "storagecommand.h" -namespace storage { -namespace mbusprot { +namespace storage::mbusprot { StorageCommand::StorageCommand(const storage::api::StorageCommand::SP& cmd) : mbus::Message(), _cmd(cmd) { } -} // mbusprot -} // storage +} diff --git a/storageapi/src/vespa/storageapi/mbusprot/storagecommand.h b/storageapi/src/vespa/storageapi/mbusprot/storagecommand.h index bf5174f8f62..651336b39e5 100644 --- a/storageapi/src/vespa/storageapi/mbusprot/storagecommand.h +++ b/storageapi/src/vespa/storageapi/mbusprot/storagecommand.h @@ -6,8 +6,7 @@ #include <vespa/messagebus/message.h> #include <vespa/storageapi/messageapi/storagecommand.h> -namespace storage { -namespace mbusprot { +namespace storage::mbusprot { class StorageCommand : public mbus::Message, public StorageMessage { public: @@ -30,5 +29,4 @@ private: api::StorageCommand::SP _cmd; }; -} // mbusprot -} // storage +} diff --git a/storageapi/src/vespa/storageapi/mbusprot/storagemessage.h b/storageapi/src/vespa/storageapi/mbusprot/storagemessage.h index 551388345de..c63271a8956 100644 --- a/storageapi/src/vespa/storageapi/mbusprot/storagemessage.h +++ b/storageapi/src/vespa/storageapi/mbusprot/storagemessage.h @@ -3,8 +3,7 @@ #include <vespa/storageapi/messageapi/storagemessage.h> -namespace storage { -namespace mbusprot { +namespace storage::mbusprot { class StorageMessage { public: @@ -17,6 +16,5 @@ public: }; -} // protocol -} // storage +} diff --git a/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.h b/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.h index f8e698e1dc3..699f1c4c239 100644 --- a/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.h +++ b/storageapi/src/vespa/storageapi/mbusprot/storageprotocol.h @@ -4,8 +4,7 @@ #include "protocolserialization5_2.h" #include <vespa/messagebus/iprotocol.h> -namespace storage { -namespace mbusprot { +namespace storage::mbusprot { class StorageProtocol : public mbus::IProtocol { @@ -28,5 +27,4 @@ private: ProtocolSerialization5_2 _serializer5_2; }; -} // mbusprot -} // storage +} diff --git a/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp b/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp index 0c2fa022948..7a21a1bbb27 100644 --- a/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp +++ b/storageapi/src/vespa/storageapi/mbusprot/storagereply.cpp @@ -7,23 +7,23 @@ using vespalib::alloc::Alloc; using vespalib::IllegalStateException; -namespace storage { -namespace mbusprot { +namespace storage::mbusprot { -StorageReply::StorageReply(const mbus::BlobRef& data, - const ProtocolSerialization& serializer) +StorageReply::StorageReply(mbus::BlobRef data, const ProtocolSerialization& serializer) : _serializer(&serializer), - _buffer(Alloc::alloc(data.size())), + _sz(data.size()), + _buffer(Alloc::alloc(_sz)), _mbusType(0), _reply() { - memcpy(_buffer.get(), data.data(), _buffer.size()); - document::ByteBuffer buf(data.data(), data.size()); + memcpy(_buffer.get(), data.data(), _sz); + document::ByteBuffer buf(data.data(), _sz); buf.getIntNetwork(reinterpret_cast<int32_t&>(_mbusType)); } StorageReply::StorageReply(const api::StorageReply::SP& reply) : _serializer(0), + _sz(0), _buffer(), _mbusType(reply->getType().getId()), _reply(reply) @@ -48,10 +48,9 @@ StorageReply::deserialize() const if (cmd == 0) { throw IllegalStateException("Storage reply get message did not return a storage command", VESPA_STRLOC); } - mbus::BlobRef blobRef(static_cast<char *>(_buffer.get()), _buffer.size()); + mbus::BlobRef blobRef(static_cast<char *>(_buffer.get()), _sz); _reply = _serializer->decodeReply(blobRef, *cmd->getCommand())->getReply(); Alloc().swap(_buffer); } -} // mbusprot -} // storage +} diff --git a/storageapi/src/vespa/storageapi/mbusprot/storagereply.h b/storageapi/src/vespa/storageapi/mbusprot/storagereply.h index 0000c98f7db..2fd6be2dc14 100644 --- a/storageapi/src/vespa/storageapi/mbusprot/storagereply.h +++ b/storageapi/src/vespa/storageapi/mbusprot/storagereply.h @@ -6,11 +6,11 @@ #include <vespa/messagebus/reply.h> #include <vespa/storageapi/messageapi/storagereply.h> -namespace storage { -namespace mbusprot { +namespace storage::mbusprot { class StorageReply : public mbus::Reply, public StorageMessage { const ProtocolSerialization* _serializer; + size_t _sz; mutable vespalib::alloc::Alloc _buffer; uint32_t _mbusType; mutable api::StorageReply::SP _reply; @@ -18,7 +18,7 @@ class StorageReply : public mbus::Reply, public StorageMessage { public: typedef std::unique_ptr<StorageReply> UP; - StorageReply(const mbus::BlobRef& data, const ProtocolSerialization&); + StorageReply(mbus::BlobRef data, const ProtocolSerialization&); StorageReply(const api::StorageReply::SP& reply); ~StorageReply(); @@ -40,9 +40,7 @@ public: } private: - void deserialize() const; }; -} // mbusprot -} // storage +} diff --git a/storageapi/src/vespa/storageapi/messageapi/storagecommand.cpp b/storageapi/src/vespa/storageapi/messageapi/storagecommand.cpp index 7c113228a35..0028de9924a 100644 --- a/storageapi/src/vespa/storageapi/messageapi/storagecommand.cpp +++ b/storageapi/src/vespa/storageapi/messageapi/storagecommand.cpp @@ -5,8 +5,7 @@ #include <vespa/vespalib/util/exceptions.h> #include <ostream> -namespace storage { -namespace api { +namespace storage::api { StorageCommand::StorageCommand(const StorageCommand& other) : StorageMessage(other, generateMsgId()), @@ -49,5 +48,4 @@ StorageCommand::createCopyToForward(const document::BucketId&, uint64_t) const VESPA_STRLOC); } -} // api -} // storage +} diff --git a/storageapi/src/vespa/storageapi/messageapi/storagecommand.h b/storageapi/src/vespa/storageapi/messageapi/storagecommand.h index 73412807d66..5667c5c10f4 100644 --- a/storageapi/src/vespa/storageapi/messageapi/storagecommand.h +++ b/storageapi/src/vespa/storageapi/messageapi/storagecommand.h @@ -14,8 +14,7 @@ #include "storagemessage.h" -namespace storage { -namespace api { +namespace storage::api { class StorageReply; @@ -65,6 +64,4 @@ public: }; -} // api -} // storage - +} diff --git a/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp b/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp index be384f253c0..d9eecf36a03 100644 --- a/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp +++ b/storageapi/src/vespa/storageapi/messageapi/storagemessage.cpp @@ -381,4 +381,3 @@ StorageMessage::getSummary() const { } } - diff --git a/storageapi/src/vespa/storageapi/messageapi/storagemessage.h b/storageapi/src/vespa/storageapi/messageapi/storagemessage.h index 5b74d88fc68..20697c4be72 100644 --- a/storageapi/src/vespa/storageapi/messageapi/storagemessage.h +++ b/storageapi/src/vespa/storageapi/messageapi/storagemessage.h @@ -68,9 +68,7 @@ public: \ return std::unique_ptr<storage::api::StorageReply>(new reply(*this)); \ } -namespace storage { - -namespace api { +namespace storage::api { /** * @class MessageType @@ -404,8 +402,7 @@ public: * This method is overloaded in subclasses and will call the correct * method in the MessageHandler interface. */ - virtual bool callHandler(MessageHandler&, - const StorageMessage::SP&) const = 0; + virtual bool callHandler(MessageHandler&, const StorageMessage::SP&) const = 0; const documentapi::LoadType& getLoadType() const { return _loadType; } void setLoadType(const documentapi::LoadType& type) { _loadType = type; } @@ -427,6 +424,4 @@ public: virtual bool hasSingleBucketId() const { return false; } }; -} // api -} // storage - +} |