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

#pragma once

#include "iattributefilewriter.h"
#include <vespa/vespalib/stllike/string.h>

class FastOS_FileInterface;

namespace vespalib { class GenericHeader; }

namespace search {

namespace common { class FileHeaderContext; }
namespace attribute { class AttributeHeader; }

class TuneFileAttributes;

/*
 * Class to write to a single attribute vector file. Used by
 * AttributeFileSaveTarget.
 */
class AttributeFileWriter : public IAttributeFileWriter
{
    std::unique_ptr<FastOS_FileInterface> _file;
    const TuneFileAttributes &_tuneFileAttributes;
    const search::common::FileHeaderContext &_fileHeaderContext;
    const attribute::AttributeHeader &_header;
    vespalib::string _desc;
    uint64_t _fileBitSize;

    void addTags(vespalib::GenericHeader &header);

    void writeHeader();
public:
    AttributeFileWriter(const TuneFileAttributes &tuneFileAttributes,
                        const search::common::FileHeaderContext & fileHeaderContext,
                        const attribute::AttributeHeader &header,
                        const vespalib::string &desc);
    ~AttributeFileWriter();
    Buffer allocBuf(size_t size) override;
    void writeBuf(Buffer buf) override;
    std::unique_ptr<BufferWriter> allocBufferWriter() override;
    bool open(const vespalib::string &fileName);
    void close();
};


} // namespace search