aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/vespa/storageapi/mbusprot/storagereply.h
blob: 714a3affacb9820ebe6cbe5d33d48f7b6f8dbb27 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#pragma once

#include "storagemessage.h"
#include "storageprotocol.h"
#include <vespa/messagebus/reply.h>
#include <vespa/storageapi/messageapi/storagereply.h>

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;

public:
    using UP = std::unique_ptr<StorageReply>;

    StorageReply(mbus::BlobRef data, const ProtocolSerialization&);
    StorageReply(api::StorageReply::SP reply);
    ~StorageReply();

    const mbus::string& getProtocol() const override { return StorageProtocol::NAME; }

    uint32_t getType() const override { return _mbusType; }

    const api::StorageReply::SP& getReply() { deserialize(); return _reply; }
    api::StorageReply::CSP getReply() const { deserialize(); return _reply; }

    api::StorageMessage::SP getInternalMessage() override { deserialize(); return _reply; }
    api::StorageMessage::CSP getInternalMessage() const override { deserialize(); return _reply; }

    uint8_t priority() const override {
        if (_reply) {
            return _reply->getPriority();
        }
        return 0;
    }

private:
    void deserialize() const;
};

}