aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/util/walk.h
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/protobuf/util/walk.h
downloadydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/protobuf/util/walk.h')
-rw-r--r--library/cpp/protobuf/util/walk.h33
1 files changed, 33 insertions, 0 deletions
diff --git a/library/cpp/protobuf/util/walk.h b/library/cpp/protobuf/util/walk.h
new file mode 100644
index 0000000000..d15d76562d
--- /dev/null
+++ b/library/cpp/protobuf/util/walk.h
@@ -0,0 +1,33 @@
+#pragma once
+
+#include "simple_reflection.h"
+
+#include <google/protobuf/message.h>
+#include <google/protobuf/descriptor.h>
+
+#include <functional>
+
+namespace NProtoBuf {
+ // Apply @onField processor to each field in @msg (even empty)
+ // Do not walk deeper the field if the field is an empty message
+ // Returned bool defines if we should walk down deeper to current node children (true), or not (false)
+ void WalkReflection(Message& msg,
+ std::function<bool(Message&, const FieldDescriptor*)> onField);
+ void WalkReflection(const Message& msg,
+ std::function<bool(const Message&, const FieldDescriptor*)> onField);
+
+ template <typename TOnField>
+ inline void WalkReflection(Message& msg, TOnField& onField) { // is used when TOnField is a callable class instance
+ WalkReflection(msg, std::function<bool(Message&, const FieldDescriptor*)>(std::ref(onField)));
+ }
+ template <typename TOnField>
+ inline void WalkReflection(const Message& msg, TOnField& onField) {
+ WalkReflection(msg, std::function<bool(const Message&, const FieldDescriptor*)>(std::ref(onField)));
+ }
+
+ // Apply @onField processor to each descriptor of a field
+ // Walk every field including nested messages. Avoid cyclic fields pointing to themselves
+ // Returned bool defines if we should walk down deeper to current node children (true), or not (false)
+ void WalkSchema(const Descriptor* descriptor,
+ std::function<bool(const FieldDescriptor*)> onField);
+}