5#include <userver/formats/json/parser/base_parser.hpp>
6#include <userver/utils/assert.hpp>
15 virtual ~Subscriber() =
default;
17 virtual void OnSend(T&&) = 0;
21class SubscriberSink
final :
public Subscriber<T> {
23 SubscriberSink(T& data) : data_(data) {}
25 void OnSend(T&& value)
override { data_ = std::move(value); }
32class SubscriberSinkOptional
final :
public Subscriber<T>,
35 SubscriberSinkOptional(std::optional<T>& data) : data_(data) {}
37 void OnSend(T&& value)
override { data_ = std::move(value); }
39 void OnSend(std::optional<T>&& value)
override { data_ = std::move(value); }
42 std::optional<T>& data_;
132 void Subscribe(
Subscriber<T>& subscriber) { subscriber_ = &subscriber; }
134 using ResultType = T;
140 virtual void Reset() {}
148 void SetResult(T&& value) {
149 parser_state_->PopMe(*
this);
150 if (subscriber_) subscriber_->OnSend(std::move(value));
157template <
typename T,
typename Parser>
158T ParseToType(std::string_view input) {
162 SubscriberSink<T> sink(result);
163 parser.Subscribe(sink);
166 state.PushParser(parser);
167 state.ProcessInput(input);