aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/yson_pull/read_ops.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <arcadia-devtools@yandex-team.ru>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/yson_pull/read_ops.cpp
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/yson_pull/read_ops.cpp')
-rw-r--r--library/cpp/yson_pull/read_ops.cpp66
1 files changed, 66 insertions, 0 deletions
diff --git a/library/cpp/yson_pull/read_ops.cpp b/library/cpp/yson_pull/read_ops.cpp
new file mode 100644
index 0000000000..9d7e6a4a2d
--- /dev/null
+++ b/library/cpp/yson_pull/read_ops.cpp
@@ -0,0 +1,66 @@
+#include "read_ops.h"
+
+using namespace NYsonPull;
+using namespace NYsonPull::NReadOps;
+
+namespace {
+ bool TrySkipValueUntil(EEventType end, TReader& reader) {
+ const auto& event = reader.NextEvent();
+ if (event.Type() == end) {
+ return false;
+ }
+ SkipCurrentValue(event, reader);
+ return true;
+ }
+
+ bool TrySkipKeyValueUntil(EEventType end, TReader& reader) {
+ const auto& event = reader.NextEvent();
+ if (event.Type() == end) {
+ return false;
+ }
+ Expect(event, EEventType::Key);
+ SkipValue(reader);
+ return true;
+ }
+}
+
+void NYsonPull::NReadOps::SkipCurrentValue(const TEvent& event, TReader& reader) {
+ switch (event.Type()) {
+ case EEventType::BeginList:
+ while (TrySkipValueUntil(EEventType::EndList, reader)) {
+ }
+ return;
+
+ case EEventType::BeginMap:
+ while (TrySkipKeyValueUntil(EEventType::EndMap, reader)) {
+ }
+ return;
+
+ case EEventType::BeginAttributes:
+ while (TrySkipKeyValueUntil(EEventType::EndAttributes, reader)) {
+ }
+ // attributes after attributes are disallowed in TReader
+ SkipValue(reader);
+ return;
+
+ case EEventType::Scalar:
+ return;
+
+ default:
+ throw yexception() << "Unexpected event: " << event;
+ }
+}
+
+void NYsonPull::NReadOps::SkipValue(TReader& reader) {
+ const auto& event = reader.NextEvent();
+ SkipCurrentValue(event, reader);
+}
+
+void NYsonPull::NReadOps::SkipControlRecords(TReader& reader) {
+ const auto* event = &reader.LastEvent();
+ while (event->Type() == EEventType::BeginAttributes) {
+ SkipCurrentValue(*event, reader);
+ event = &reader.NextEvent();
+ }
+ Expect(*event, EEventType::BeginMap);
+}