diff options
author | levanov <levanov@yandex-team.ru> | 2022-02-10 16:50:35 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:35 +0300 |
commit | e286bb0ae13ace8f8efe6aa628c5e1e67708e32e (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 | |
parent | 45c5374f026a836b0b16ea2d9246c8385d371ca7 (diff) | |
download | ydb-e286bb0ae13ace8f8efe6aa628c5e1e67708e32e.tar.gz |
Restoring authorship annotation for <levanov@yandex-team.ru>. Commit 2 of 2.
-rw-r--r-- | library/cpp/protobuf/json/json2proto.cpp | 14 | ||||
-rw-r--r-- | library/cpp/protobuf/json/json2proto.h | 34 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/json2proto_ut.cpp | 54 |
3 files changed, 51 insertions, 51 deletions
diff --git a/library/cpp/protobuf/json/json2proto.cpp b/library/cpp/protobuf/json/json2proto.cpp index 572b14bbf0..640c10f5a5 100644 --- a/library/cpp/protobuf/json/json2proto.cpp +++ b/library/cpp/protobuf/json/json2proto.cpp @@ -125,8 +125,8 @@ FindEnumValue(const NProtoBuf::EnumDescriptor* enumField, static void JsonEnum2Field(const NJson::TJsonValue& json, google::protobuf::Message& proto, - const google::protobuf::FieldDescriptor& field, - const NProtobufJson::TJson2ProtoConfig& config) { + const google::protobuf::FieldDescriptor& field, + const NProtobufJson::TJson2ProtoConfig& config) { using namespace google::protobuf; const Reflection* reflection = proto.GetReflection(); @@ -146,13 +146,13 @@ JsonEnum2Field(const NJson::TJsonValue& json, } } else if (json.IsString()) { const auto& value = json.GetString(); - if (config.EnumValueMode == NProtobufJson::TJson2ProtoConfig::EnumCaseInsensetive) { + if (config.EnumValueMode == NProtobufJson::TJson2ProtoConfig::EnumCaseInsensetive) { enumFieldValue = FindEnumValue(enumField, value, AsciiEqualsIgnoreCase); } else if (config.EnumValueMode == NProtobufJson::TJson2ProtoConfig::EnumSnakeCaseInsensitive) { enumFieldValue = FindEnumValue(enumField, value, NProtobufJson::EqualsIgnoringCaseAndUnderscores); - } else { + } else { enumFieldValue = enumField->FindValueByName(value); - } + } if (!enumFieldValue) { ythrow yexception() << "Invalid string value of JSON enum field: " << TStringBuf(value).Head(100) << "."; } @@ -208,7 +208,7 @@ Json2SingleField(const NJson::TJsonValue& json, } case FieldDescriptor::CPPTYPE_ENUM: { - JsonEnum2Field(fieldJson, proto, field, config); + JsonEnum2Field(fieldJson, proto, field, config); break; } @@ -283,7 +283,7 @@ Json2RepeatedFieldValue(const NJson::TJsonValue& jsonValue, } case FieldDescriptor::CPPTYPE_ENUM: { - JsonEnum2Field(jsonValue, proto, field, config); + JsonEnum2Field(jsonValue, proto, field, config); break; } diff --git a/library/cpp/protobuf/json/json2proto.h b/library/cpp/protobuf/json/json2proto.h index cd9aa70ea3..4c33498dfa 100644 --- a/library/cpp/protobuf/json/json2proto.h +++ b/library/cpp/protobuf/json/json2proto.h @@ -30,11 +30,11 @@ namespace NProtobufJson { FieldNameSnakeCaseDense // ABC -> abc, UserID -> user_id }; - enum EnumValueMode { - EnumCaseSensetive = 0, // default + enum EnumValueMode { + EnumCaseSensetive = 0, // default EnumCaseInsensetive, EnumSnakeCaseInsensitive - }; + }; TSelf& SetFieldNameMode(FldNameMode mode) { Y_ENSURE(mode == FieldNameOriginalCase || !UseJsonName, "FieldNameMode and UseJsonName are mutually exclusive"); @@ -68,11 +68,11 @@ namespace NProtobufJson { return *this; } - TSelf& SetMapAsObject(bool mapAsObject) { - MapAsObject = mapAsObject; - return *this; - } - + TSelf& SetMapAsObject(bool mapAsObject) { + MapAsObject = mapAsObject; + return *this; + } + TSelf& SetReplaceRepeatedFields(bool replaceRepeatedFields) { ReplaceRepeatedFields = replaceRepeatedFields; return *this; @@ -83,11 +83,11 @@ namespace NProtobufJson { return *this; } - TSelf& SetEnumValueMode(EnumValueMode enumValueMode) { - EnumValueMode = enumValueMode; - return *this; - } - + TSelf& SetEnumValueMode(EnumValueMode enumValueMode) { + EnumValueMode = enumValueMode; + return *this; + } + TSelf& SetVectorizeScalars(bool vectorizeScalars) { VectorizeScalars = vectorizeScalars; return *this; @@ -103,7 +103,7 @@ namespace NProtobufJson { return *this; } - FldNameMode FieldNameMode = FieldNameOriginalCase; + FldNameMode FieldNameMode = FieldNameOriginalCase; bool AllowUnknownFields = true; /// Use 'json_name' protobuf option for field name, mutually exclusive @@ -132,9 +132,9 @@ namespace NProtobufJson { /// Custom field names generator. TNameGenerator NameGenerator = {}; - - /// Enum value parsing mode. - EnumValueMode EnumValueMode = EnumCaseSensetive; + + /// Enum value parsing mode. + EnumValueMode EnumValueMode = EnumCaseSensetive; /// Append scalars to repeated fields bool VectorizeScalars = false; diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index 849c603a2e..0dfe57bc7a 100644 --- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp +++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp @@ -56,7 +56,7 @@ namespace { return buf.WriteJsonValue(&json).Str(); } - void TestComplexMapAsObject(std::function<void(TComplexMapType&)>&& init, const TString& json, const TJson2ProtoConfig& config = TJson2ProtoConfig().SetMapAsObject(true)) { + void TestComplexMapAsObject(std::function<void(TComplexMapType&)>&& init, const TString& json, const TJson2ProtoConfig& config = TJson2ProtoConfig().SetMapAsObject(true)) { TComplexMapType modelProto; init(modelProto); @@ -902,32 +902,32 @@ Y_UNIT_TEST(TestComplexMapAsObject_Enum) { R"_({"Enum":{"key1":1,"key2":2,"key3":3}})_"); } // TestComplexMapAsObject_Enum -Y_UNIT_TEST(TestComplexMapAsObject_EnumString) { - TestComplexMapAsObject( - [](TComplexMapType& proto) { - auto& items = *proto.MutableEnum(); - items["key1"] = EEnum::E_1; - items["key2"] = EEnum::E_2; - items["key3"] = EEnum::E_3; - }, - R"_({"Enum":{"key1":"E_1","key2":"E_2","key3":"E_3"}})_"); -} // TestComplexMapAsObject_EnumString - -Y_UNIT_TEST(TestComplexMapAsObject_EnumStringCaseInsensetive) { - TestComplexMapAsObject( - [](TComplexMapType& proto) { - auto& items = *proto.MutableEnum(); - items["key1"] = EEnum::E_1; - items["key2"] = EEnum::E_2; - items["key3"] = EEnum::E_3; - }, - R"_({"Enum":{"key1":"e_1","key2":"E_2","key3":"e_3"}})_", - TJson2ProtoConfig() - .SetMapAsObject(true) - .SetEnumValueMode(NProtobufJson::TJson2ProtoConfig::EnumCaseInsensetive) - ); -} // TestComplexMapAsObject_EnumStringCaseInsensetive - +Y_UNIT_TEST(TestComplexMapAsObject_EnumString) { + TestComplexMapAsObject( + [](TComplexMapType& proto) { + auto& items = *proto.MutableEnum(); + items["key1"] = EEnum::E_1; + items["key2"] = EEnum::E_2; + items["key3"] = EEnum::E_3; + }, + R"_({"Enum":{"key1":"E_1","key2":"E_2","key3":"E_3"}})_"); +} // TestComplexMapAsObject_EnumString + +Y_UNIT_TEST(TestComplexMapAsObject_EnumStringCaseInsensetive) { + TestComplexMapAsObject( + [](TComplexMapType& proto) { + auto& items = *proto.MutableEnum(); + items["key1"] = EEnum::E_1; + items["key2"] = EEnum::E_2; + items["key3"] = EEnum::E_3; + }, + R"_({"Enum":{"key1":"e_1","key2":"E_2","key3":"e_3"}})_", + TJson2ProtoConfig() + .SetMapAsObject(true) + .SetEnumValueMode(NProtobufJson::TJson2ProtoConfig::EnumCaseInsensetive) + ); +} // TestComplexMapAsObject_EnumStringCaseInsensetive + Y_UNIT_TEST(TestComplexMapAsObject_EnumStringSnakeCaseInsensitive) { TestComplexMapAsObject( [](TComplexMapType& proto) { |