aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/feedoperation/putoperation.cpp
blob: af4df0bea363eadea92282b8d9084732369a4dd0 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "putoperation.h"
#include <vespa/document/fieldvalue/document.h>

using document::BucketId;
using document::Document;
using document::DocumentTypeRepo;
using vespalib::make_string;

namespace proton {

PutOperation::PutOperation()
    : DocumentOperation(FeedOperation::PUT),
      _doc()
{ }


PutOperation::PutOperation(BucketId bucketId, Timestamp timestamp, Document::SP doc)
    : DocumentOperation(FeedOperation::PUT, bucketId, timestamp),
      _doc(std::move(doc))
{ }

PutOperation::~PutOperation() = default;

void
PutOperation::serialize(vespalib::nbostream &os) const
{
    assertValidBucketId(_doc->getId());
    DocumentOperation::serialize(os);
    size_t oldSize = os.size();
    _doc->serialize(os);
    _serializedDocSize = os.size() - oldSize;
}


void
PutOperation::deserialize(vespalib::nbostream &is, const DocumentTypeRepo &repo)
{
    DocumentOperation::deserialize(is, repo);
    size_t oldSize = is.size();
    _doc.reset(new Document(repo, is));
    _serializedDocSize = oldSize - is.size();
}

void
PutOperation::deserializeDocument(const DocumentTypeRepo &repo)
{
    vespalib::nbostream stream;
    _doc->serialize(stream);
    auto fixedDoc = std::make_shared<Document>(repo, stream);
    _doc = std::move(fixedDoc);
}

vespalib::string
PutOperation::toString() const
{
    return make_string("Put(%s, %s)",
                       _doc.get() ?
                       _doc->getId().getScheme().toString().c_str() : "NULL",
                       docArgsToString().c_str());
}

void
PutOperation::assertValid() const
{
    assertValidBucketId(_doc->getId());
}

} // namespace proton