blob: df03933a50222e01cdcdec38331b98fab844011d (
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
|
#pragma once
#include "consumer.h"
#include "event.h"
#include "writer.h"
namespace NYsonPull {
//! \brief Connect YSON stream producer and consumer.
//!
//! Useful for writing YSON stream filters.
//! \p Producer must have a \p next_event() method (like \p NYsonPull::reader).
//! \p Consumer must be like \p NYsonPull::consumer interface.
template <typename Producer, typename Consumer>
inline void Bridge(Producer&& producer, Consumer&& consumer) {
for (;;) {
auto& event = producer.NextEvent();
consumer.OnEvent(event);
if (event.Type() == EEventType::EndStream) {
break;
}
}
}
template <typename Producer>
inline void Bridge(Producer&& producer, TWriter& writer_) {
Bridge(std::forward<Producer>(producer), writer_.GetConsumer());
}
template <typename Producer>
inline void Bridge(Producer&& producer, TWriter&& writer_) {
Bridge(std::forward<Producer>(producer), writer_.GetConsumer());
}
}
|