aboutsummaryrefslogtreecommitdiffstats
path: root/searchlib/src/vespa/searchlib/attribute/attributememoryfilewriter.cpp
blob: ac1841bc36a4a0b937a8899283f47504c126226d (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "attributememoryfilewriter.h"
#include "attributememoryfilebufferwriter.h"
#include <vespa/searchlib/util/file_settings.h>
#include <vespa/vespalib/data/databuffer.h>
#include <vespa/vespalib/util/size_literals.h>

namespace search {

AttributeMemoryFileWriter::AttributeMemoryFileWriter()
    : IAttributeFileWriter(),
      _bufs()
{
}


AttributeMemoryFileWriter::~AttributeMemoryFileWriter() = default;


AttributeMemoryFileWriter::Buffer
AttributeMemoryFileWriter::allocBuf(size_t size)
{
    return std::make_unique<BufferBuf>(size, FileSettings::DIRECTIO_ALIGNMENT);
}


void
AttributeMemoryFileWriter::writeBuf(Buffer buf)
{
    _bufs.emplace_back(std::move(buf));
}


void
AttributeMemoryFileWriter::writeTo(IAttributeFileWriter &writer)
{
    for (auto &buf : _bufs) {
        writer.writeBuf(std::move(buf));
    }
    _bufs.clear();
}


std::unique_ptr<BufferWriter>
AttributeMemoryFileWriter::allocBufferWriter()
{
    return std::make_unique<AttributeMemoryFileBufferWriter>(*this);
}


} // namespace search