aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/scheme
diff options
context:
space:
mode:
authorvskipin <vskipin@yandex-team.ru>2022-02-10 16:46:00 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:00 +0300
commit4d8b546b89b5afc08cf3667e176271c7ba935f33 (patch)
tree1a2c5ffcf89eb53ecd79dbc9bc0a195c27404d0c /library/cpp/scheme
parent4e4b78bd7b67e2533da4dbb9696374a6d6068e32 (diff)
downloadydb-4d8b546b89b5afc08cf3667e176271c7ba935f33.tar.gz
Restoring authorship annotation for <vskipin@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/scheme')
-rw-r--r--library/cpp/scheme/scheme.h4
-rw-r--r--library/cpp/scheme/scimpl_protobuf.cpp126
-rw-r--r--library/cpp/scheme/tests/ut/scheme_proto_ut.cpp22
3 files changed, 76 insertions, 76 deletions
diff --git a/library/cpp/scheme/scheme.h b/library/cpp/scheme/scheme.h
index 857a7fb9e0..3d7c59f3c9 100644
--- a/library/cpp/scheme/scheme.h
+++ b/library/cpp/scheme/scheme.h
@@ -388,7 +388,7 @@ namespace NSc {
static TValue From(const ::google::protobuf::Message&, bool mapAsDict = false);
void To(::google::protobuf::Message&, const TProtoOpts& opts = {}) const;
-
+
public:
inline explicit TValue(TPoolPtr&);
@@ -420,7 +420,7 @@ namespace NSc {
static TValue FromField(const ::google::protobuf::Message&, const ::google::protobuf::FieldDescriptor*);
static TValue FromRepeatedField(const ::google::protobuf::Message&, const ::google::protobuf::FieldDescriptor*, int index);
-
+
void ValueToField(const TValue& value, ::google::protobuf::Message&, const ::google::protobuf::FieldDescriptor*, const TProtoOpts& opts) const;
void ToField(::google::protobuf::Message&, const ::google::protobuf::FieldDescriptor*, const TProtoOpts& opts) const;
void ToEnumField(::google::protobuf::Message&, const ::google::protobuf::FieldDescriptor*, const TProtoOpts& opts) const;
diff --git a/library/cpp/scheme/scimpl_protobuf.cpp b/library/cpp/scheme/scimpl_protobuf.cpp
index e24be0aad3..0c99122c69 100644
--- a/library/cpp/scheme/scimpl_protobuf.cpp
+++ b/library/cpp/scheme/scimpl_protobuf.cpp
@@ -130,41 +130,41 @@ namespace NSc {
}
void TValue::To(Message& msg, const TProtoOpts& opts) const {
- msg.Clear();
-
- if (IsNull()) {
- return;
- }
-
- if (!IsDict()) {
- ythrow TSchemeException() << "expected dictionary";
- }
-
- const Descriptor* descriptor = msg.GetDescriptor();
- for (int i = 0, count = descriptor->field_count(); i < count; ++i) {
- const FieldDescriptor* field = descriptor->field(i);
+ msg.Clear();
+
+ if (IsNull()) {
+ return;
+ }
+
+ if (!IsDict()) {
+ ythrow TSchemeException() << "expected dictionary";
+ }
+
+ const Descriptor* descriptor = msg.GetDescriptor();
+ for (int i = 0, count = descriptor->field_count(); i < count; ++i) {
+ const FieldDescriptor* field = descriptor->field(i);
if (field->is_map()) {
ToMapField(msg, field, opts);
} else if (field->is_repeated()) {
ToRepeatedField(msg, field, opts);
- } else {
+ } else {
ToField(msg, field, opts);
- }
- }
- }
-
+ }
+ }
+ }
+
void TValue::ValueToField(const TValue& value, Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const {
const TString& name = field->name();
- if (value.IsNull()) {
- if (field->is_required() && !field->has_default_value()) {
- ythrow TSchemeException() << "has no value for required field " << name;
- }
- return;
- }
-
- const Reflection* reflection = msg.GetReflection();
-
- switch (field->cpp_type()) {
+ if (value.IsNull()) {
+ if (field->is_required() && !field->has_default_value()) {
+ ythrow TSchemeException() << "has no value for required field " << name;
+ }
+ return;
+ }
+
+ const Reflection* reflection = msg.GetReflection();
+
+ switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
reflection->SetInt32(&msg, field, value.ForceIntNumber());
break;
@@ -199,9 +199,9 @@ namespace NSc {
ythrow TSchemeException()
<< "field " << field->full_name()
<< " unexpected type " << (int)field->cpp_type();
- }
- }
-
+ }
+ }
+
void TValue::ToField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const {
const TString& name = field->name();
const TValue& value = Get(name);
@@ -209,49 +209,49 @@ namespace NSc {
}
void TValue::ToEnumField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const {
- const EnumDescriptor* enumField = field->enum_type();
-
- const EnumValueDescriptor* enumFieldValue = IsString()
+ const EnumDescriptor* enumField = field->enum_type();
+
+ const EnumValueDescriptor* enumFieldValue = IsString()
? enumField->FindValueByName(ForceString())
: enumField->FindValueByNumber(ForceIntNumber());
-
- if (!enumFieldValue) {
+
+ if (!enumFieldValue) {
if (opts.UnknownEnumValueIsDefault) {
enumFieldValue = field->default_value_enum();
} else {
ythrow TSchemeException() << "invalid value of enum field " << field->name();
}
- }
-
- const Reflection* reflection = msg.GetReflection();
-
- if (field->is_repeated()) {
- reflection->AddEnum(&msg, field, enumFieldValue);
- } else {
- reflection->SetEnum(&msg, field, enumFieldValue);
- }
- }
-
+ }
+
+ const Reflection* reflection = msg.GetReflection();
+
+ if (field->is_repeated()) {
+ reflection->AddEnum(&msg, field, enumFieldValue);
+ } else {
+ reflection->SetEnum(&msg, field, enumFieldValue);
+ }
+ }
+
void TValue::ToRepeatedField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const {
const TString& name = field->name();
-
- const TValue& fieldValue = Get(name);
- if (fieldValue.IsNull()) {
- return;
- }
-
- if (!fieldValue.IsArray()) {
+
+ const TValue& fieldValue = Get(name);
+ if (fieldValue.IsNull()) {
+ return;
+ }
+
+ if (!fieldValue.IsArray()) {
if (opts.SkipTypeMismatch) {
return; // leave repeated field empty
} else {
ythrow TSchemeException() << "invalid type of repeated field " << name << ": not an array";
}
- }
-
- const Reflection* reflection = msg.GetReflection();
-
+ }
+
+ const Reflection* reflection = msg.GetReflection();
+
for (const TValue& value : fieldValue.GetArray()) {
- switch (field->cpp_type()) {
+ switch (field->cpp_type()) {
case FieldDescriptor::CPPTYPE_INT32:
reflection->AddInt32(&msg, field, value.ForceIntNumber());
break;
@@ -286,10 +286,10 @@ namespace NSc {
ythrow TSchemeException()
<< "field " << field->full_name()
<< " unexpected type " << (int)field->cpp_type();
- }
- }
- }
-
+ }
+ }
+ }
+
void TValue::ToMapField(Message& msg, const FieldDescriptor* field, const TProtoOpts& opts) const {
const TString& name = field->name();
diff --git a/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp b/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp
index 24c2addac9..e711a0d092 100644
--- a/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp
+++ b/library/cpp/scheme/tests/ut/scheme_proto_ut.cpp
@@ -8,12 +8,12 @@ Y_UNIT_TEST_SUITE(TSchemeProtoTest) {
Y_UNIT_TEST(TestFromProtobuf) {
DoTestProtobuf(true, false);
- }
-
+ }
+
Y_UNIT_TEST(TestToProtobuf) {
DoTestProtobuf(false, false);
- }
-
+ }
+
Y_UNIT_TEST(TestFromProtobufWithDict) {
DoTestProtobuf(true, true);
}
@@ -207,14 +207,14 @@ Y_UNIT_TEST_SUITE(TSchemeProtoTest) {
*(m.AddMessages()) = m2, v["Messages"][0] = v2;
*(m.AddMessages()) = m2, v["Messages"][1] = v2;
- if (fromProto) {
+ if (fromProto) {
UNIT_ASSERT(NSc::TValue::Equal(v, NSc::TValue::From(m, mapAsDict)));
- } else {
- NSc::TMessage proto;
- v.To(proto);
-
+ } else {
+ NSc::TMessage proto;
+ v.To(proto);
+
TString differentPath;
- UNIT_ASSERT_C(NProtoBuf::IsEqual(m, proto, &differentPath), differentPath);
- }
+ UNIT_ASSERT_C(NProtoBuf::IsEqual(m, proto, &differentPath), differentPath);
+ }
}
};