aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/data/lz4_input_decoder.h
blob: 114813a2845f7cb9081b43eb7f55e7989655ae78 (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#pragma once

#include "input.h"
#include <vector>

struct LZ4F_dctx_s;

namespace vespalib {

/**
 * Input filter decompressing data stored in framed lz4 format.
 **/
class Lz4InputDecoder : public Input
{
private:
    Input            &_input;
    std::vector<char> _buffer;
    size_t            _used;
    size_t            _pos;
    bool              _eof;
    bool              _failed;
    vespalib::string  _reason;
    LZ4F_dctx_s      *_ctx;

    void fail(const char *reason);
    void decode_more();
public:
    Lz4InputDecoder(Input &input, size_t buffer_size);
    ~Lz4InputDecoder();
    Memory obtain() override;
    Input &evict(size_t bytes) override;
    bool failed() const { return _failed; }
    const vespalib::string &reason() const { return _reason; }
};

} // namespace vespalib