diff options
author | Egor Kochetov <gluk47@gmail.com> | 2022-02-10 16:50:36 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:36 +0300 |
commit | 40896b241c91572ea1369526ee1e6ae0ba340f34 (patch) | |
tree | cb6d8f482e66c136ec128a42417cd5f858520d12 /library/cpp/protobuf | |
parent | 3889d4c01a589a555fbc33d66279be23e267ab3b (diff) | |
download | ydb-40896b241c91572ea1369526ee1e6ae0ba340f34.tar.gz |
Restoring authorship annotation for Egor Kochetov <gluk47@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/protobuf')
-rw-r--r-- | library/cpp/protobuf/json/json2proto.cpp | 14 | ||||
-rw-r--r-- | library/cpp/protobuf/json/json2proto.h | 16 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/json2proto_ut.cpp | 32 | ||||
-rw-r--r-- | library/cpp/protobuf/util/iterators.h | 104 | ||||
-rw-r--r-- | library/cpp/protobuf/util/iterators_ut.cpp | 94 | ||||
-rw-r--r-- | library/cpp/protobuf/util/ut/ya.make | 2 | ||||
-rw-r--r-- | library/cpp/protobuf/util/ya.make | 2 |
7 files changed, 132 insertions, 132 deletions
diff --git a/library/cpp/protobuf/json/json2proto.cpp b/library/cpp/protobuf/json/json2proto.cpp index 640c10f5a5..94cab335c9 100644 --- a/library/cpp/protobuf/json/json2proto.cpp +++ b/library/cpp/protobuf/json/json2proto.cpp @@ -356,17 +356,17 @@ Json2RepeatedField(const NJson::TJsonValue& json, if (config.ReplaceRepeatedFields) { reflection->ClearField(&proto, &field); } - if (fieldJson.GetType() == NJson::JSON_ARRAY) { - const NJson::TJsonValue::TArray& jsonArray = fieldJson.GetArray(); - for (const NJson::TJsonValue& jsonValue : jsonArray) { - Json2RepeatedFieldValue(jsonValue, proto, field, config, reflection); - } + if (fieldJson.GetType() == NJson::JSON_ARRAY) { + const NJson::TJsonValue::TArray& jsonArray = fieldJson.GetArray(); + for (const NJson::TJsonValue& jsonValue : jsonArray) { + Json2RepeatedFieldValue(jsonValue, proto, field, config, reflection); + } } else if (config.ValueVectorizer) { for (const NJson::TJsonValue& jsonValue : config.ValueVectorizer(fieldJson)) { Json2RepeatedFieldValue(jsonValue, proto, field, config, reflection); } - } else if (config.VectorizeScalars) { - Json2RepeatedFieldValue(fieldJson, proto, field, config, reflection); + } else if (config.VectorizeScalars) { + Json2RepeatedFieldValue(fieldJson, proto, field, config, reflection); } } } diff --git a/library/cpp/protobuf/json/json2proto.h b/library/cpp/protobuf/json/json2proto.h index 4c33498dfa..9667bb5c83 100644 --- a/library/cpp/protobuf/json/json2proto.h +++ b/library/cpp/protobuf/json/json2proto.h @@ -88,11 +88,11 @@ namespace NProtobufJson { return *this; } - TSelf& SetVectorizeScalars(bool vectorizeScalars) { - VectorizeScalars = vectorizeScalars; - return *this; - } - + TSelf& SetVectorizeScalars(bool vectorizeScalars) { + VectorizeScalars = vectorizeScalars; + return *this; + } + TSelf& SetAllowComments(bool value) { AllowComments = value; return *this; @@ -135,9 +135,9 @@ namespace NProtobufJson { /// Enum value parsing mode. EnumValueMode EnumValueMode = EnumCaseSensetive; - - /// Append scalars to repeated fields - bool VectorizeScalars = false; + + /// Append scalars to repeated fields + bool VectorizeScalars = false; /// Custom spliter non array value to repeated fields. TValueVectorizer ValueVectorizer; diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index 0dfe57bc7a..f313968d31 100644 --- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp +++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp @@ -672,24 +672,24 @@ Y_UNIT_TEST(TestCastRobust) { UNIT_ASSERT_PROTOS_EQUAL(proto, expected); } -Y_UNIT_TEST(TestVectorizeScalars) { - NJson::TJsonValue json; -#define DEFINE_FIELD(name, value) \ - json.InsertValue(#name, value); +Y_UNIT_TEST(TestVectorizeScalars) { + NJson::TJsonValue json; +#define DEFINE_FIELD(name, value) \ + json.InsertValue(#name, value); #include <library/cpp/protobuf/json/ut/fields.incl> -#undef DEFINE_FIELD - - TFlatRepeated proto; - TJson2ProtoConfig config; - config.SetVectorizeScalars(true); - Json2Proto(json, proto, config); - -#define DEFINE_FIELD(name, value) \ - UNIT_ASSERT_VALUES_EQUAL(proto.Get ## name(0), value); +#undef DEFINE_FIELD + + TFlatRepeated proto; + TJson2ProtoConfig config; + config.SetVectorizeScalars(true); + Json2Proto(json, proto, config); + +#define DEFINE_FIELD(name, value) \ + UNIT_ASSERT_VALUES_EQUAL(proto.Get ## name(0), value); #include <library/cpp/protobuf/json/ut/fields.incl> -#undef DEFINE_FIELD -} - +#undef DEFINE_FIELD +} + Y_UNIT_TEST(TestValueVectorizer) { { // No ValueVectorizer diff --git a/library/cpp/protobuf/util/iterators.h b/library/cpp/protobuf/util/iterators.h index 6d53ac71b1..7830127d3f 100644 --- a/library/cpp/protobuf/util/iterators.h +++ b/library/cpp/protobuf/util/iterators.h @@ -1,53 +1,53 @@ -#pragma once - +#pragma once + #include <google/protobuf/descriptor.h> - -namespace NProtoBuf { - class TFieldsIterator { - public: - explicit TFieldsIterator(const NProtoBuf::Descriptor* descriptor, int position = 0) - : Descriptor(descriptor) - , Position(position) - { } - - TFieldsIterator& operator++() { - ++Position; - return *this; - } - - TFieldsIterator& operator++(int) { - auto& ret = *this; - ++*this; - return ret; - } - - const NProtoBuf::FieldDescriptor* operator*() const { - return Descriptor->field(Position); - } - - bool operator== (const TFieldsIterator& other) const { - return Position == other.Position && Descriptor == other.Descriptor; - } - - bool operator!= (const TFieldsIterator& other) const { - return !(*this == other); - } - - private: - const NProtoBuf::Descriptor* Descriptor = nullptr; - int Position = 0; - }; -} - -// Namespaces required by `range-based for` ADL: -namespace google { - namespace protobuf { - NProtoBuf::TFieldsIterator begin(const NProtoBuf::Descriptor& descriptor) { - return NProtoBuf::TFieldsIterator(&descriptor); - } - - NProtoBuf::TFieldsIterator end(const NProtoBuf::Descriptor& descriptor) { - return NProtoBuf::TFieldsIterator(&descriptor, descriptor.field_count()); - } - } -} + +namespace NProtoBuf { + class TFieldsIterator { + public: + explicit TFieldsIterator(const NProtoBuf::Descriptor* descriptor, int position = 0) + : Descriptor(descriptor) + , Position(position) + { } + + TFieldsIterator& operator++() { + ++Position; + return *this; + } + + TFieldsIterator& operator++(int) { + auto& ret = *this; + ++*this; + return ret; + } + + const NProtoBuf::FieldDescriptor* operator*() const { + return Descriptor->field(Position); + } + + bool operator== (const TFieldsIterator& other) const { + return Position == other.Position && Descriptor == other.Descriptor; + } + + bool operator!= (const TFieldsIterator& other) const { + return !(*this == other); + } + + private: + const NProtoBuf::Descriptor* Descriptor = nullptr; + int Position = 0; + }; +} + +// Namespaces required by `range-based for` ADL: +namespace google { + namespace protobuf { + NProtoBuf::TFieldsIterator begin(const NProtoBuf::Descriptor& descriptor) { + return NProtoBuf::TFieldsIterator(&descriptor); + } + + NProtoBuf::TFieldsIterator end(const NProtoBuf::Descriptor& descriptor) { + return NProtoBuf::TFieldsIterator(&descriptor, descriptor.field_count()); + } + } +} diff --git a/library/cpp/protobuf/util/iterators_ut.cpp b/library/cpp/protobuf/util/iterators_ut.cpp index 9ebcff2963..0350fa425c 100644 --- a/library/cpp/protobuf/util/iterators_ut.cpp +++ b/library/cpp/protobuf/util/iterators_ut.cpp @@ -1,52 +1,52 @@ -#include "iterators.h" -#include "simple_reflection.h" +#include "iterators.h" +#include "simple_reflection.h" #include <library/cpp/protobuf/util/ut/common_ut.pb.h> - + #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/algorithm.h> - -using NProtoBuf::TFieldsIterator; -using NProtoBuf::TConstField; - + +#include <util/generic/algorithm.h> + +using NProtoBuf::TFieldsIterator; +using NProtoBuf::TConstField; + Y_UNIT_TEST_SUITE(Iterators) { Y_UNIT_TEST(Count) { - const NProtobufUtilUt::TWalkTest proto; - const NProtoBuf::Descriptor* d = proto.GetDescriptor(); - TFieldsIterator dbegin(d), dend(d, d->field_count()); - size_t steps = 0; - - UNIT_ASSERT_EQUAL(dbegin, begin(*d)); - UNIT_ASSERT_EQUAL(dend, end(*d)); - - for (; dbegin != dend; ++dbegin) - ++steps; - UNIT_ASSERT_VALUES_EQUAL(steps, d->field_count()); - } - - Y_UNIT_TEST(RangeFor) { - size_t steps = 0, values = 0; - NProtobufUtilUt::TWalkTest proto; - proto.SetOptStr("yandex"); - for (const auto& field : *proto.GetDescriptor()) { - values += TConstField(proto, field).HasValue(); - ++steps; - } - UNIT_ASSERT_VALUES_EQUAL(steps, proto.GetDescriptor()->field_count()); - UNIT_ASSERT_VALUES_EQUAL(values, 1); - } - + const NProtobufUtilUt::TWalkTest proto; + const NProtoBuf::Descriptor* d = proto.GetDescriptor(); + TFieldsIterator dbegin(d), dend(d, d->field_count()); + size_t steps = 0; + + UNIT_ASSERT_EQUAL(dbegin, begin(*d)); + UNIT_ASSERT_EQUAL(dend, end(*d)); + + for (; dbegin != dend; ++dbegin) + ++steps; + UNIT_ASSERT_VALUES_EQUAL(steps, d->field_count()); + } + + Y_UNIT_TEST(RangeFor) { + size_t steps = 0, values = 0; + NProtobufUtilUt::TWalkTest proto; + proto.SetOptStr("yandex"); + for (const auto& field : *proto.GetDescriptor()) { + values += TConstField(proto, field).HasValue(); + ++steps; + } + UNIT_ASSERT_VALUES_EQUAL(steps, proto.GetDescriptor()->field_count()); + UNIT_ASSERT_VALUES_EQUAL(values, 1); + } + Y_UNIT_TEST(AnyOf) { - NProtobufUtilUt::TWalkTest proto; - const NProtoBuf::Descriptor* d = proto.GetDescriptor(); - TFieldsIterator begin(d), end(d, d->field_count()); - UNIT_ASSERT(!AnyOf(begin, end, [&proto](const NProtoBuf::FieldDescriptor* f){ - return TConstField(proto, f).HasValue(); - })); - - proto.SetOptStr("yandex"); - UNIT_ASSERT(AnyOf(begin, end, [&proto](const NProtoBuf::FieldDescriptor* f){ - return TConstField(proto, f).HasValue(); - })); - } -} + NProtobufUtilUt::TWalkTest proto; + const NProtoBuf::Descriptor* d = proto.GetDescriptor(); + TFieldsIterator begin(d), end(d, d->field_count()); + UNIT_ASSERT(!AnyOf(begin, end, [&proto](const NProtoBuf::FieldDescriptor* f){ + return TConstField(proto, f).HasValue(); + })); + + proto.SetOptStr("yandex"); + UNIT_ASSERT(AnyOf(begin, end, [&proto](const NProtoBuf::FieldDescriptor* f){ + return TConstField(proto, f).HasValue(); + })); + } +} diff --git a/library/cpp/protobuf/util/ut/ya.make b/library/cpp/protobuf/util/ut/ya.make index 701ba9a8c8..bc1bacc52f 100644 --- a/library/cpp/protobuf/util/ut/ya.make +++ b/library/cpp/protobuf/util/ut/ya.make @@ -9,7 +9,7 @@ SRCS( common_ut.proto pb_io_ut.cpp is_equal_ut.cpp - iterators_ut.cpp + iterators_ut.cpp simple_reflection_ut.cpp repeated_field_utils_ut.cpp walk_ut.cpp diff --git a/library/cpp/protobuf/util/ya.make b/library/cpp/protobuf/util/ya.make index b62028af58..a5bf4383a7 100644 --- a/library/cpp/protobuf/util/ya.make +++ b/library/cpp/protobuf/util/ya.make @@ -11,7 +11,7 @@ PEERDIR( SRCS( is_equal.cpp - iterators.h + iterators.h merge.cpp path.cpp pb_io.cpp |