Skip to content

Commit

Permalink
Merge b8aa5f9 into 8adf99d
Browse files Browse the repository at this point in the history
  • Loading branch information
Enjection authored Feb 8, 2024
2 parents 8adf99d + b8aa5f9 commit 8109914
Show file tree
Hide file tree
Showing 7 changed files with 446 additions and 0 deletions.
335 changes: 335 additions & 0 deletions ydb/core/config/ut/main.cpp

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions ydb/core/config/ut/ya.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
UNITTEST()

SRCS(
main.cpp
)

PEERDIR(
ydb/core/config/utils
library/cpp/testing/unittest
)

END()
59 changes: 59 additions & 0 deletions ydb/core/config/utils/config_traverse.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#include "config_traverse.h"

#include <ydb/core/protos/config.pb.h>

#include <contrib/libs/protobuf/src/google/protobuf/descriptor.h>

#include <util/generic/deque.h>
#include <util/generic/map.h>
#include <util/generic/set.h>
#include <util/generic/string.h>
#include <util/generic/vector.h>
#include <util/system/compiler.h>

namespace NKikimr::NConfig {

ssize_t FindLoop(TDeque<const Descriptor*>& typePath, const Descriptor* child) {
for (ssize_t i = 0; i < (ssize_t)typePath.size(); ++i) {
if (typePath[i] == child) {
return i;
}
}
return -1;
}

void Traverse(const Descriptor* d, TDeque<const Descriptor*>& typePath, TDeque<const FieldDescriptor*>& fieldPath, const FieldDescriptor* field, TOnEntryFn onEntry) {
ssize_t loop = FindLoop(typePath, d);

Y_ABORT_IF(!d && !field, "Either field or descriptor must be defined");

onEntry(d, typePath, fieldPath, field, loop);

if (!d || loop != -1) {
return;
}

typePath.push_back(d);

for (int i = 0; i < d->field_count(); ++i) {
const FieldDescriptor* fieldDescriptor = d->field(i);
fieldPath.push_back(fieldDescriptor);
Traverse(fieldDescriptor->message_type(), typePath, fieldPath, fieldDescriptor, onEntry);
fieldPath.pop_back();
}

typePath.pop_back();
}

void Traverse(TOnEntryFn onEntry) {
auto& inst = NKikimrConfig::TAppConfig::default_instance();
const Descriptor* descriptor = inst.GetDescriptor();

TDeque<const Descriptor*> typePath;
TDeque<const FieldDescriptor*> fieldPath;
fieldPath.push_back(nullptr);
Traverse(descriptor, typePath, fieldPath, nullptr, onEntry);
fieldPath.pop_back();
}

} // namespace NKikimr::NConfig
20 changes: 20 additions & 0 deletions ydb/core/config/utils/config_traverse.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#include <util/generic/deque.h>

#include <functional>

namespace google::protobuf {
class Descriptor;
class FieldDescriptor;
}

namespace NKikimr::NConfig {

using namespace google::protobuf;

using TOnEntryFn = std::function<void(const Descriptor*, const TDeque<const Descriptor*>&, const TDeque<const FieldDescriptor*>&, const FieldDescriptor*, ssize_t)>;

void Traverse(TOnEntryFn onEntry);

} // namespace NKikimr::NConfig
12 changes: 12 additions & 0 deletions ydb/core/config/utils/ya.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
LIBRARY()

SRCS(
config_traverse.cpp
)

PEERDIR(
ydb/core/protos
library/cpp/protobuf/json
)

END()
7 changes: 7 additions & 0 deletions ydb/core/config/ya.make
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
RECURSE(
utils
)

RECURSE_FOR_TESTS(
ut
)
1 change: 1 addition & 0 deletions ydb/core/ya.make
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RECURSE(
client
cms
control
config
debug
debug_tools
discovery
Expand Down

0 comments on commit 8109914

Please sign in to comment.