-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
446 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
RECURSE( | ||
utils | ||
) | ||
|
||
RECURSE_FOR_TESTS( | ||
ut | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ RECURSE( | |
client | ||
cms | ||
control | ||
config | ||
debug | ||
debug_tools | ||
discovery | ||
|