aboutsummaryrefslogtreecommitdiffstats
path: root/yt/yt/core/yson/async_consumer.h
blob: 8a0a2d92763865082d3d36678d4bea362d3261c4 (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
53
54
55
56
57
#pragma once

#include "public.h"
#include "string.h"
#include "consumer.h"

#include <yt/yt/core/actions/future.h>

namespace NYT::NYson {

////////////////////////////////////////////////////////////////////////////////

//! Extends IYsonConsumer by enabling asynchronously constructed
//! segments to be injected into the stream.
struct IAsyncYsonConsumer
    : public IYsonConsumer
{
    using IYsonConsumer::OnRaw;
    virtual void OnRaw(TFuture<TYsonString> asyncStr) = 0;
};

////////////////////////////////////////////////////////////////////////////////

//! Turns IYsonConsumer into IAsyncConsumer. No asynchronous calls are allowed.
class TAsyncYsonConsumerAdapter
    : public IAsyncYsonConsumer
{
public:
    explicit TAsyncYsonConsumerAdapter(IYsonConsumer* underlyingConsumer);

    void OnStringScalar(TStringBuf value) override;
    void OnInt64Scalar(i64 value) override;
    void OnUint64Scalar(ui64 value) override;
    void OnDoubleScalar(double value) override;
    void OnBooleanScalar(bool value) override;
    void OnEntity() override;
    void OnBeginList() override;
    void OnListItem() override;
    void OnEndList() override;
    void OnBeginMap() override;
    void OnKeyedItem(TStringBuf key) override;
    void OnEndMap() override;
    void OnBeginAttributes() override;
    void OnEndAttributes() override;
    using IYsonConsumer::OnRaw;
    void OnRaw(TStringBuf yson, EYsonType type) override;
    void OnRaw(TFuture<TYsonString> asyncStr) override;

private:
    IYsonConsumer* const UnderlyingConsumer_;

};

////////////////////////////////////////////////////////////////////////////////

} // namespace NYT::NYson