aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/util/simple_reflection.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/simple_reflection.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/simple_reflection.cpp')
-rw-r--r--library/cpp/protobuf/util/simple_reflection.cpp108
1 files changed, 54 insertions, 54 deletions
diff --git a/library/cpp/protobuf/util/simple_reflection.cpp b/library/cpp/protobuf/util/simple_reflection.cpp
index 913a011028..d842e9ee44 100644
--- a/library/cpp/protobuf/util/simple_reflection.cpp
+++ b/library/cpp/protobuf/util/simple_reflection.cpp
@@ -1,70 +1,70 @@
#include "simple_reflection.h"
namespace NProtoBuf {
- const Message* GetMessageHelper(const TConstField& curField, bool) {
- return curField.HasValue() && curField.IsMessage() ? curField.Get<Message>() : nullptr;
- }
+ const Message* GetMessageHelper(const TConstField& curField, bool) {
+ return curField.HasValue() && curField.IsMessage() ? curField.Get<Message>() : nullptr;
+ }
- Message* GetMessageHelper(TMutableField& curField, bool createPath) {
- if (curField.IsMessage()) {
- if (!curField.HasValue()) {
- if (createPath)
- return curField.Field()->is_repeated() ? curField.AddMessage() : curField.MutableMessage();
- } else {
- return curField.MutableMessage();
- }
+ Message* GetMessageHelper(TMutableField& curField, bool createPath) {
+ if (curField.IsMessage()) {
+ if (!curField.HasValue()) {
+ if (createPath)
+ return curField.Field()->is_repeated() ? curField.AddMessage() : curField.MutableMessage();
+ } else {
+ return curField.MutableMessage();
+ }
}
- return nullptr;
+ return nullptr;
}
- template <class TField, class TMsg>
- TMaybe<TField> ByPathImpl(TMsg& msg, const TVector<const FieldDescriptor*>& fieldsPath, bool createPath) {
- if (fieldsPath.empty())
+ template <class TField, class TMsg>
+ TMaybe<TField> ByPathImpl(TMsg& msg, const TVector<const FieldDescriptor*>& fieldsPath, bool createPath) {
+ if (fieldsPath.empty())
+ return TMaybe<TField>();
+ TMsg* curParent = &msg;
+ for (size_t i = 0, size = fieldsPath.size(); i < size; ++i) {
+ const FieldDescriptor* field = fieldsPath[i];
+ if (!curParent)
+ return TMaybe<TField>();
+ TField curField(*curParent, field);
+ if (size - i == 1) // last element in path
+ return curField;
+ curParent = GetMessageHelper(curField, createPath);
+ }
+ if (curParent)
+ return TField(*curParent, fieldsPath.back());
+ else
return TMaybe<TField>();
- TMsg* curParent = &msg;
- for (size_t i = 0, size = fieldsPath.size(); i < size; ++i) {
- const FieldDescriptor* field = fieldsPath[i];
- if (!curParent)
- return TMaybe<TField>();
- TField curField(*curParent, field);
- if (size - i == 1) // last element in path
- return curField;
- curParent = GetMessageHelper(curField, createPath);
- }
- if (curParent)
- return TField(*curParent, fieldsPath.back());
- else
- return TMaybe<TField>();
}
- TMaybe<TConstField> TConstField::ByPath(const Message& msg, const TVector<const FieldDescriptor*>& fieldsPath) {
- return ByPathImpl<TConstField, const Message>(msg, fieldsPath, false);
- }
+ TMaybe<TConstField> TConstField::ByPath(const Message& msg, const TVector<const FieldDescriptor*>& fieldsPath) {
+ return ByPathImpl<TConstField, const Message>(msg, fieldsPath, false);
+ }
+
+ TMaybe<TConstField> TConstField::ByPath(const Message& msg, const TStringBuf& path) {
+ TFieldPath fieldPath;
+ if (!fieldPath.InitUnsafe(msg.GetDescriptor(), path))
+ return TMaybe<TConstField>();
+ return ByPathImpl<TConstField, const Message>(msg, fieldPath.Fields(), false);
+ }
- TMaybe<TConstField> TConstField::ByPath(const Message& msg, const TStringBuf& path) {
- TFieldPath fieldPath;
- if (!fieldPath.InitUnsafe(msg.GetDescriptor(), path))
- return TMaybe<TConstField>();
- return ByPathImpl<TConstField, const Message>(msg, fieldPath.Fields(), false);
- }
+ TMaybe<TConstField> TConstField::ByPath(const Message& msg, const TFieldPath& path) {
+ return ByPathImpl<TConstField, const Message>(msg, path.Fields(), false);
+ }
- TMaybe<TConstField> TConstField::ByPath(const Message& msg, const TFieldPath& path) {
- return ByPathImpl<TConstField, const Message>(msg, path.Fields(), false);
- }
+ TMaybe<TMutableField> TMutableField::ByPath(Message& msg, const TVector<const FieldDescriptor*>& fieldsPath, bool createPath) {
+ return ByPathImpl<TMutableField, Message>(msg, fieldsPath, createPath);
+ }
- TMaybe<TMutableField> TMutableField::ByPath(Message& msg, const TVector<const FieldDescriptor*>& fieldsPath, bool createPath) {
- return ByPathImpl<TMutableField, Message>(msg, fieldsPath, createPath);
- }
+ TMaybe<TMutableField> TMutableField::ByPath(Message& msg, const TStringBuf& path, bool createPath) {
+ TFieldPath fieldPath;
+ if (!fieldPath.InitUnsafe(msg.GetDescriptor(), path))
+ return TMaybe<TMutableField>();
+ return ByPathImpl<TMutableField, Message>(msg, fieldPath.Fields(), createPath);
+ }
- TMaybe<TMutableField> TMutableField::ByPath(Message& msg, const TStringBuf& path, bool createPath) {
- TFieldPath fieldPath;
- if (!fieldPath.InitUnsafe(msg.GetDescriptor(), path))
- return TMaybe<TMutableField>();
- return ByPathImpl<TMutableField, Message>(msg, fieldPath.Fields(), createPath);
- }
+ TMaybe<TMutableField> TMutableField::ByPath(Message& msg, const TFieldPath& path, bool createPath) {
+ return ByPathImpl<TMutableField, Message>(msg, path.Fields(), createPath);
+ }
- TMaybe<TMutableField> TMutableField::ByPath(Message& msg, const TFieldPath& path, bool createPath) {
- return ByPathImpl<TMutableField, Message>(msg, path.Fields(), createPath);
- }
-
}