aboutsummaryrefslogtreecommitdiffstats
path: root/util/stream/walk.h
blob: 7e62cb44dc94cef26936e5c89038741169fb4205 (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
#pragma once

#include "zerocopy.h"

/**
 * Zero-copy stream that simplifies implementation of derived classes.
 *
 * Derived classes must implement `DoUnboundedNext` method.
 */
class IWalkInput: public IZeroCopyInputFastReadTo {
public:
    IWalkInput()
        : Buf_(nullptr)
        , Len_(0)
    {
    }

protected:
    void DoUndo(size_t len) override;
    size_t DoNext(const void** ptr, size_t len) override;

    /**
     * Returns the next data chunk from this input stream. There are no
     * restrictions on the size of the data chunk.
     *
     * @param ptr[out]                  Pointer to the start of the data chunk.
     * @returns                         Size of the returned data chunk, in bytes.
     *                                  Return value of zero signals end of stream.
     */
    virtual size_t DoUnboundedNext(const void** ptr) = 0;

private:
    const void* Buf_;
    size_t Len_;
};