aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/util/path.cpp
diff options
context:
space:
mode:
authorAnton Samokhvalov <pg83@yandex.ru>2022-02-10 16:45:17 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:45:17 +0300
commitd3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch)
treedd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/protobuf/util/path.cpp
parent72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff)
downloadydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/protobuf/util/path.cpp')
-rw-r--r--library/cpp/protobuf/util/path.cpp98
1 files changed, 49 insertions, 49 deletions
diff --git a/library/cpp/protobuf/util/path.cpp b/library/cpp/protobuf/util/path.cpp
index aeb9b52b71..efa2a42c8a 100644
--- a/library/cpp/protobuf/util/path.cpp
+++ b/library/cpp/protobuf/util/path.cpp
@@ -3,59 +3,59 @@
#include <util/generic/yexception.h>
namespace NProtoBuf {
- TFieldPath::TFieldPath() {
- }
-
- TFieldPath::TFieldPath(const Descriptor* msgType, const TStringBuf& path) {
- Init(msgType, path);
- }
-
- TFieldPath::TFieldPath(const TVector<const FieldDescriptor*>& path)
- : Path(path)
- {
- }
-
- bool TFieldPath::InitUnsafe(const Descriptor* msgType, TStringBuf path) {
- Path.clear();
- while (path) {
- TStringBuf next;
- while (!next && path)
- next = path.NextTok('/');
- if (!next)
- return true;
-
- if (!msgType) // need field but no message type
- return false;
-
- TString nextStr(next);
- const FieldDescriptor* field = msgType->FindFieldByName(nextStr);
- if (!field) {
- // Try to find extension field by FindAllExtensions()
- const DescriptorPool* pool = msgType->file()->pool();
- Y_ASSERT(pool); // never NULL by protobuf docs
- TVector<const FieldDescriptor*> extensions;
- pool->FindAllExtensions(msgType, &extensions); // find all extensions of this extendee
- for (const FieldDescriptor* ext : extensions) {
- if (ext->full_name() == nextStr || ext->name() == nextStr) {
- if (field)
- return false; // ambiguity
- field = ext;
- }
+ TFieldPath::TFieldPath() {
+ }
+
+ TFieldPath::TFieldPath(const Descriptor* msgType, const TStringBuf& path) {
+ Init(msgType, path);
+ }
+
+ TFieldPath::TFieldPath(const TVector<const FieldDescriptor*>& path)
+ : Path(path)
+ {
+ }
+
+ bool TFieldPath::InitUnsafe(const Descriptor* msgType, TStringBuf path) {
+ Path.clear();
+ while (path) {
+ TStringBuf next;
+ while (!next && path)
+ next = path.NextTok('/');
+ if (!next)
+ return true;
+
+ if (!msgType) // need field but no message type
+ return false;
+
+ TString nextStr(next);
+ const FieldDescriptor* field = msgType->FindFieldByName(nextStr);
+ if (!field) {
+ // Try to find extension field by FindAllExtensions()
+ const DescriptorPool* pool = msgType->file()->pool();
+ Y_ASSERT(pool); // never NULL by protobuf docs
+ TVector<const FieldDescriptor*> extensions;
+ pool->FindAllExtensions(msgType, &extensions); // find all extensions of this extendee
+ for (const FieldDescriptor* ext : extensions) {
+ if (ext->full_name() == nextStr || ext->name() == nextStr) {
+ if (field)
+ return false; // ambiguity
+ field = ext;
+ }
}
}
- if (!field)
- return false;
+ if (!field)
+ return false;
+
+ Path.push_back(field);
+ msgType = field->type() == FieldDescriptor::TYPE_MESSAGE ? field->message_type() : nullptr;
+ }
+ return true;
+ }
- Path.push_back(field);
- msgType = field->type() == FieldDescriptor::TYPE_MESSAGE ? field->message_type() : nullptr;
- }
- return true;
+ void TFieldPath::Init(const Descriptor* msgType, const TStringBuf& path) {
+ if (!InitUnsafe(msgType, path))
+ ythrow yexception() << "Failed to resolve path \"" << path << "\" relative to " << msgType->full_name();
}
- void TFieldPath::Init(const Descriptor* msgType, const TStringBuf& path) {
- if (!InitUnsafe(msgType, path))
- ythrow yexception() << "Failed to resolve path \"" << path << "\" relative to " << msgType->full_name();
- }
-
}