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

#pragma once

#include "chunkformat.h"

namespace search {

class ChunkFormatV1 : public ChunkFormat
{
public:
    enum {VERSION=0};
    ChunkFormatV1(vespalib::nbostream & is, uint32_t expectedCrc);
    ChunkFormatV1(size_t maxSize);
private:
    bool includeSerializedSize() const override { return false; }
    uint8_t getVersion() const override { return VERSION; }
    size_t getHeaderSize() const override { return 0; }
    uint32_t computeCrc(const void * buf, size_t sz) const override;
    void writeHeader(vespalib::DataBuffer & buf) const override {
        (void) buf;
    }
};

class ChunkFormatV2 : public ChunkFormat
{
public:
    enum {VERSION=1, MAGIC=0x5ba32de7};
    ChunkFormatV2(vespalib::nbostream & is, uint32_t expectedCrc);
    ChunkFormatV2(size_t maxSize);
private:
    bool includeSerializedSize() const override { return true; }
    size_t getHeaderSize() const override {
        // MAGIC
        return 4;
    }
    uint8_t getVersion() const override { return VERSION; }
    uint32_t computeCrc(const void * buf, size_t sz) const override;
    void writeHeader(vespalib::DataBuffer & buf) const override {
        buf.writeInt32(MAGIC);
    }
    void verifyMagic(vespalib::nbostream & is) const;
};

} // namespace search