aboutsummaryrefslogtreecommitdiffstats
path: root/documentapi/src/vespa/documentapi/messagebus/routablefactories51.cpp
blob: 01d0c5b6c0e5a71ac93ae73ca1bcd974ba66da83 (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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "routablefactories51.h"
#include <vespa/document/bucket/fixed_bucket_spaces.h>
#include <vespa/document/document.h>
#include <vespa/documentapi/documentapi.h>
#include <vespa/documentapi/loadtypes/loadtypeset.h>
#include <vespa/vespalib/objects/nbostream.h>

using document::FixedBucketSpaces;
using vespalib::nbostream;

namespace documentapi {

DocumentMessage::UP
RoutableFactories51::CreateVisitorMessageFactory::doDecode(document::ByteBuffer &buf) const
{
    DocumentMessage::UP ret(new CreateVisitorMessage());
    CreateVisitorMessage &msg = static_cast<CreateVisitorMessage&>(*ret);

    msg.setLibraryName(decodeString(buf));
    msg.setInstanceId(decodeString(buf));
    msg.setControlDestination(decodeString(buf));
    msg.setDataDestination(decodeString(buf));
    msg.setDocumentSelection(decodeString(buf));
    msg.setMaximumPendingReplyCount(decodeInt(buf));

    int32_t len = decodeInt(buf);
    msg.getBuckets().reserve(len);
    for (int32_t i = 0; i < len; i++) {
        int64_t val;
        buf.getLong(val); // NOT using getLongNetwork
        msg.getBuckets().push_back(document::BucketId(val));
    }

    msg.setFromTimestamp(decodeLong(buf));
    msg.setToTimestamp(decodeLong(buf));
    msg.setVisitRemoves(decodeBoolean(buf));
    msg.setFieldSet(decodeString(buf));
    msg.setVisitInconsistentBuckets(decodeBoolean(buf));
    msg.getParameters().deserialize(_repo, buf);
    msg.setVisitorDispatcherVersion(50);
    msg.setVisitorOrdering((document::OrderingSpecification::Order)decodeInt(buf));
    msg.setMaxBucketsPerVisitor(decodeInt(buf));
    msg.setBucketSpace(decodeBucketSpace(buf));

    return ret;
}

bool
RoutableFactories51::CreateVisitorMessageFactory::doEncode(const DocumentMessage &obj, vespalib::GrowableByteBuffer &buf) const
{
    const CreateVisitorMessage &msg = static_cast<const CreateVisitorMessage&>(obj);

    buf.putString(msg.getLibraryName());
    buf.putString(msg.getInstanceId());
    buf.putString(msg.getControlDestination());
    buf.putString(msg.getDataDestination());
    buf.putString(msg.getDocumentSelection());
    buf.putInt(msg.getMaximumPendingReplyCount());
    buf.putInt(msg.getBuckets().size());

    const std::vector<document::BucketId> &buckets = msg.getBuckets();
    for (std::vector<document::BucketId>::const_iterator it = buckets.begin();
         it != buckets.end(); ++it)
    {
        uint64_t val = it->getRawId();
        buf.putBytes((const char*)&val, 8);
    }

    buf.putLong(msg.getFromTimestamp());
    buf.putLong(msg.getToTimestamp());
    buf.putBoolean(msg.visitRemoves());
    buf.putString(msg.getFieldSet());
    buf.putBoolean(msg.visitInconsistentBuckets());

    int len = msg.getParameters().getSerializedSize();
    char *tmp = buf.allocate(len);
    document::ByteBuffer dbuf(tmp, len);
    msg.getParameters().serialize(dbuf);

    buf.putInt(msg.getVisitorOrdering());
    buf.putInt(msg.getMaxBucketsPerVisitor());
    return encodeBucketSpace(msg.getBucketSpace(), buf);
}

bool RoutableFactories51::CreateVisitorMessageFactory::encodeBucketSpace(
        vespalib::stringref bucketSpace,
        vespalib::GrowableByteBuffer& buf) const {
    (void) buf;
    return (bucketSpace == FixedBucketSpaces::default_space_name());
}

string RoutableFactories51::CreateVisitorMessageFactory::decodeBucketSpace(document::ByteBuffer&) const {
    return FixedBucketSpaces::default_space_name();
}

DocumentMessage::UP
RoutableFactories51::GetDocumentMessageFactory::doDecode(document::ByteBuffer &buf) const
{
    return DocumentMessage::UP(
            new GetDocumentMessage(decodeDocumentId(buf),
                                   decodeString(buf)));
}

bool
RoutableFactories51::GetDocumentMessageFactory::doEncode(const DocumentMessage &obj,
                                                         vespalib::GrowableByteBuffer &buf) const
{
    const GetDocumentMessage &msg = static_cast<const GetDocumentMessage&>(obj);

    encodeDocumentId(msg.getDocumentId(), buf);
    buf.putString(msg.getFieldSet());
    return true;
}

DocumentReply::UP
RoutableFactories51::DocumentIgnoredReplyFactory::doDecode(document::ByteBuffer& buf) const
{
    (void) buf;
    return DocumentReply::UP(new DocumentIgnoredReply());
}

bool
RoutableFactories51::DocumentIgnoredReplyFactory::doEncode(
        const DocumentReply& obj,
        vespalib::GrowableByteBuffer& buf) const
{
    (void) obj;
    (void) buf;
    return true;
}

}