aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf
diff options
context:
space:
mode:
authorbotay <botay@yandex-team.ru>2022-02-10 16:50:00 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:00 +0300
commitbdd495d3600d61815512f5dc4c1c02f65f047a16 (patch)
tree7c4a950805539954ff6ad9cfb914d9dbeb3f2cfb /library/cpp/protobuf
parent32ad1de867d9ab2dd9dc78caae239ab3a524110b (diff)
downloadydb-bdd495d3600d61815512f5dc4c1c02f65f047a16.tar.gz
Restoring authorship annotation for <botay@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/protobuf')
-rw-r--r--library/cpp/protobuf/util/pb_io.cpp4
-rw-r--r--library/cpp/protobuf/util/pb_io.h2
-rw-r--r--library/cpp/protobuf/util/simple_reflection.h18
-rw-r--r--library/cpp/protobuf/util/simple_reflection_ut.cpp162
-rw-r--r--library/cpp/protobuf/util/ut/sample_for_simple_reflection.proto14
-rw-r--r--library/cpp/protobuf/util/ut/ya.make2
6 files changed, 101 insertions, 101 deletions
diff --git a/library/cpp/protobuf/util/pb_io.cpp b/library/cpp/protobuf/util/pb_io.cpp
index 6270ee0624..564f3ce2b5 100644
--- a/library/cpp/protobuf/util/pb_io.cpp
+++ b/library/cpp/protobuf/util/pb_io.cpp
@@ -79,8 +79,8 @@ namespace NProtoBuf {
bool MergeFromString(NProtoBuf::Message& m, const TStringBuf serializedProtoMessage) {
return MergePartialFromString(m, serializedProtoMessage) && m.IsInitialized();
}
-}
-
+}
+
int operator&(NProtoBuf::Message& m, IBinSaver& f) {
TStringStream ss;
if (f.IsReading()) {
diff --git a/library/cpp/protobuf/util/pb_io.h b/library/cpp/protobuf/util/pb_io.h
index 493c84cb5f..eb9ca603e3 100644
--- a/library/cpp/protobuf/util/pb_io.h
+++ b/library/cpp/protobuf/util/pb_io.h
@@ -35,7 +35,7 @@ namespace NProtoBuf {
TString SerializeToBase64String(const Message& m);
void SerializeToBase64String(const Message& m, TString& dataBase64);
bool TrySerializeToBase64String(const Message& m, TString& dataBase64);
-
+
const TString ShortUtf8DebugString(const Message& message);
bool MergePartialFromString(NProtoBuf::Message& m, const TStringBuf serializedProtoMessage);
diff --git a/library/cpp/protobuf/util/simple_reflection.h b/library/cpp/protobuf/util/simple_reflection.h
index 61e877a787..fe470c53a8 100644
--- a/library/cpp/protobuf/util/simple_reflection.h
+++ b/library/cpp/protobuf/util/simple_reflection.h
@@ -103,7 +103,7 @@ namespace NProtoBuf {
const Reflection& Refl() const {
return *Msg.GetReflection();
}
-
+
[[noreturn]] void RaiseUnknown() const {
ythrow yexception() << "Unknown field cpp-type: " << (size_t)CppType();
}
@@ -127,7 +127,7 @@ namespace NProtoBuf {
static TMaybe<TMutableField> ByPath(Message& msg, const TStringBuf& path, bool createPath = false);
static TMaybe<TMutableField> ByPath(Message& msg, const TVector<const FieldDescriptor*>& fieldsPath, bool createPath = false);
static TMaybe<TMutableField> ByPath(Message& msg, const TFieldPath& fieldsPath, bool createPath = false);
-
+
Message* MutableParent() {
return Mut();
}
@@ -187,7 +187,7 @@ namespace NProtoBuf {
Y_ASSERT(index == 0);
return Refl().MutableMessage(Mut(), Fd);
}
- }
+ }
template <typename TMsg>
inline TMsg* AddMessage() {
@@ -203,7 +203,7 @@ namespace NProtoBuf {
Message* Mut() {
return const_cast<Message*>(&Msg);
}
-
+
template <typename T>
inline void MergeValue(T srcValue);
};
@@ -255,8 +255,8 @@ namespace NProtoBuf {
template <typename T>
inline void TMutableField::MergeValue(T srcValue) {
- Add(srcValue);
- }
+ Add(srcValue);
+ }
template <>
inline void TMutableField::MergeValue<const Message*>(const Message* srcValue) {
@@ -264,8 +264,8 @@ namespace NProtoBuf {
Add(srcValue);
} else {
MutableMessage()->MergeFrom(*srcValue);
- }
- }
+ }
+ }
inline void TMutableField::MergeFrom(const TConstField& src) {
Y_ASSERT(HasSameType(src));
@@ -286,4 +286,4 @@ namespace NProtoBuf {
#undef TMP_MACRO_FOR_CPPTYPE
}
-}
+}
diff --git a/library/cpp/protobuf/util/simple_reflection_ut.cpp b/library/cpp/protobuf/util/simple_reflection_ut.cpp
index 169d4703c9..7647e55db3 100644
--- a/library/cpp/protobuf/util/simple_reflection_ut.cpp
+++ b/library/cpp/protobuf/util/simple_reflection_ut.cpp
@@ -1,100 +1,100 @@
-#include "simple_reflection.h"
+#include "simple_reflection.h"
#include <library/cpp/protobuf/util/ut/sample_for_simple_reflection.pb.h>
#include <library/cpp/protobuf/util/ut/extensions.pb.h>
-
+
#include <library/cpp/testing/unittest/registar.h>
-
-using namespace NProtoBuf;
-
+
+using namespace NProtoBuf;
+
Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) {
static TSample GenSampleForMergeFrom() {
TSample smf;
- smf.SetOneStr("one str");
- smf.MutableOneMsg()->AddRepInt(1);
- smf.AddRepMsg()->AddRepInt(2);
- smf.AddRepMsg()->AddRepInt(3);
- smf.AddRepStr("one rep str");
- smf.AddRepStr("two rep str");
- smf.SetAnotherOneStr("another one str");
- return smf;
- }
-
+ smf.SetOneStr("one str");
+ smf.MutableOneMsg()->AddRepInt(1);
+ smf.AddRepMsg()->AddRepInt(2);
+ smf.AddRepMsg()->AddRepInt(3);
+ smf.AddRepStr("one rep str");
+ smf.AddRepStr("two rep str");
+ smf.SetAnotherOneStr("another one str");
+ return smf;
+ }
+
Y_UNIT_TEST(MergeFromGeneric) {
const TSample src(GenSampleForMergeFrom());
TSample dst;
- const Descriptor* descr = dst.GetDescriptor();
-
- {
- TMutableField dstOneStr(dst, descr->FindFieldByName("OneStr"));
- TConstField srcOneStr(src, descr->FindFieldByName("OneStr"));
- dstOneStr.MergeFrom(srcOneStr);
- UNIT_ASSERT_VALUES_EQUAL(dst.GetOneStr(), src.GetOneStr());
- }
-
- { // MergeFrom for single message fields acts like a Message::MergeFrom
- TMutableField dstOneMsg(dst, descr->FindFieldByName("OneMsg"));
- dstOneMsg.MergeFrom(TConstField(src, descr->FindFieldByName("OneMsg")));
- UNIT_ASSERT_VALUES_EQUAL(dst.GetOneMsg().RepIntSize(), src.GetOneMsg().RepIntSize());
- dstOneMsg.MergeFrom(TConstField(src, descr->FindFieldByName("OneMsg")));
+ const Descriptor* descr = dst.GetDescriptor();
+
+ {
+ TMutableField dstOneStr(dst, descr->FindFieldByName("OneStr"));
+ TConstField srcOneStr(src, descr->FindFieldByName("OneStr"));
+ dstOneStr.MergeFrom(srcOneStr);
+ UNIT_ASSERT_VALUES_EQUAL(dst.GetOneStr(), src.GetOneStr());
+ }
+
+ { // MergeFrom for single message fields acts like a Message::MergeFrom
+ TMutableField dstOneMsg(dst, descr->FindFieldByName("OneMsg"));
+ dstOneMsg.MergeFrom(TConstField(src, descr->FindFieldByName("OneMsg")));
+ UNIT_ASSERT_VALUES_EQUAL(dst.GetOneMsg().RepIntSize(), src.GetOneMsg().RepIntSize());
+ dstOneMsg.MergeFrom(TConstField(src, descr->FindFieldByName("OneMsg")));
UNIT_ASSERT_VALUES_EQUAL(dst.GetOneMsg().RepIntSize(), src.GetOneMsg().RepIntSize() * 2);
- }
-
- { // MergeFrom for repeated fields acts like append
- TMutableField dstRepMsg(dst, descr->FindFieldByName("RepMsg"));
- dstRepMsg.MergeFrom(TConstField(src, descr->FindFieldByName("RepMsg")));
- UNIT_ASSERT_VALUES_EQUAL(dst.RepMsgSize(), src.RepMsgSize());
- dstRepMsg.MergeFrom(TConstField(src, descr->FindFieldByName("RepMsg")));
+ }
+
+ { // MergeFrom for repeated fields acts like append
+ TMutableField dstRepMsg(dst, descr->FindFieldByName("RepMsg"));
+ dstRepMsg.MergeFrom(TConstField(src, descr->FindFieldByName("RepMsg")));
+ UNIT_ASSERT_VALUES_EQUAL(dst.RepMsgSize(), src.RepMsgSize());
+ dstRepMsg.MergeFrom(TConstField(src, descr->FindFieldByName("RepMsg")));
UNIT_ASSERT_VALUES_EQUAL(dst.RepMsgSize(), src.RepMsgSize() * 2);
- for (size_t repMsgIndex = 0; repMsgIndex < dst.RepMsgSize(); ++repMsgIndex) {
- UNIT_ASSERT_VALUES_EQUAL(dst.GetRepMsg(repMsgIndex).RepIntSize(), src.GetRepMsg(0).RepIntSize());
- }
- }
- }
-
+ for (size_t repMsgIndex = 0; repMsgIndex < dst.RepMsgSize(); ++repMsgIndex) {
+ UNIT_ASSERT_VALUES_EQUAL(dst.GetRepMsg(repMsgIndex).RepIntSize(), src.GetRepMsg(0).RepIntSize());
+ }
+ }
+ }
+
Y_UNIT_TEST(MergeFromSelf) {
const TSample sample(GenSampleForMergeFrom());
TSample msg(sample);
- const Descriptor* descr = msg.GetDescriptor();
-
- TMutableField oneStr(msg, descr->FindFieldByName("OneStr"));
- oneStr.MergeFrom(oneStr);
- UNIT_ASSERT_VALUES_EQUAL(msg.GetOneStr(), sample.GetOneStr());
-
- TMutableField oneMsg(msg, descr->FindFieldByName("OneMsg"));
- oneMsg.MergeFrom(oneMsg); // nothing should change
- UNIT_ASSERT_VALUES_EQUAL(msg.GetOneMsg().RepIntSize(), sample.GetOneMsg().RepIntSize());
- }
-
+ const Descriptor* descr = msg.GetDescriptor();
+
+ TMutableField oneStr(msg, descr->FindFieldByName("OneStr"));
+ oneStr.MergeFrom(oneStr);
+ UNIT_ASSERT_VALUES_EQUAL(msg.GetOneStr(), sample.GetOneStr());
+
+ TMutableField oneMsg(msg, descr->FindFieldByName("OneMsg"));
+ oneMsg.MergeFrom(oneMsg); // nothing should change
+ UNIT_ASSERT_VALUES_EQUAL(msg.GetOneMsg().RepIntSize(), sample.GetOneMsg().RepIntSize());
+ }
+
Y_UNIT_TEST(MergeFromAnotherFD) {
const TSample sample(GenSampleForMergeFrom());
TSample msg(GenSampleForMergeFrom());
- const Descriptor* descr = msg.GetDescriptor();
-
- { // string
- TMutableField oneStr(msg, descr->FindFieldByName("OneStr"));
- TMutableField repStr(msg, descr->FindFieldByName("RepStr"));
- TMutableField anotherOneStr(msg, descr->FindFieldByName("AnotherOneStr"));
- oneStr.MergeFrom(anotherOneStr);
- UNIT_ASSERT_VALUES_EQUAL(msg.GetOneStr(), sample.GetAnotherOneStr());
- oneStr.MergeFrom(repStr);
- const size_t sampleRepStrSize = sample.RepStrSize();
- UNIT_ASSERT_VALUES_EQUAL(msg.GetOneStr(), sample.GetRepStr(sampleRepStrSize - 1));
- repStr.MergeFrom(anotherOneStr);
- UNIT_ASSERT_VALUES_EQUAL(msg.RepStrSize(), sampleRepStrSize + 1);
- UNIT_ASSERT_VALUES_EQUAL(msg.GetRepStr(sampleRepStrSize), msg.GetAnotherOneStr());
- }
-
- { // Message
- TMutableField oneMsg(msg, descr->FindFieldByName("OneMsg"));
- TMutableField repMsg(msg, descr->FindFieldByName("RepMsg"));
- oneMsg.MergeFrom(repMsg);
- const size_t oneMsgRepIntSize = sample.GetOneMsg().RepIntSize();
- const size_t sizeOfAllRepIntsInRepMsg = sample.RepMsgSize();
- UNIT_ASSERT_VALUES_EQUAL(msg.GetOneMsg().RepIntSize(), oneMsgRepIntSize + sizeOfAllRepIntsInRepMsg);
- repMsg.MergeFrom(oneMsg);
- UNIT_ASSERT_VALUES_EQUAL(msg.RepMsgSize(), sample.RepMsgSize() + 1);
- }
- }
+ const Descriptor* descr = msg.GetDescriptor();
+
+ { // string
+ TMutableField oneStr(msg, descr->FindFieldByName("OneStr"));
+ TMutableField repStr(msg, descr->FindFieldByName("RepStr"));
+ TMutableField anotherOneStr(msg, descr->FindFieldByName("AnotherOneStr"));
+ oneStr.MergeFrom(anotherOneStr);
+ UNIT_ASSERT_VALUES_EQUAL(msg.GetOneStr(), sample.GetAnotherOneStr());
+ oneStr.MergeFrom(repStr);
+ const size_t sampleRepStrSize = sample.RepStrSize();
+ UNIT_ASSERT_VALUES_EQUAL(msg.GetOneStr(), sample.GetRepStr(sampleRepStrSize - 1));
+ repStr.MergeFrom(anotherOneStr);
+ UNIT_ASSERT_VALUES_EQUAL(msg.RepStrSize(), sampleRepStrSize + 1);
+ UNIT_ASSERT_VALUES_EQUAL(msg.GetRepStr(sampleRepStrSize), msg.GetAnotherOneStr());
+ }
+
+ { // Message
+ TMutableField oneMsg(msg, descr->FindFieldByName("OneMsg"));
+ TMutableField repMsg(msg, descr->FindFieldByName("RepMsg"));
+ oneMsg.MergeFrom(repMsg);
+ const size_t oneMsgRepIntSize = sample.GetOneMsg().RepIntSize();
+ const size_t sizeOfAllRepIntsInRepMsg = sample.RepMsgSize();
+ UNIT_ASSERT_VALUES_EQUAL(msg.GetOneMsg().RepIntSize(), oneMsgRepIntSize + sizeOfAllRepIntsInRepMsg);
+ repMsg.MergeFrom(oneMsg);
+ UNIT_ASSERT_VALUES_EQUAL(msg.RepMsgSize(), sample.RepMsgSize() + 1);
+ }
+ }
Y_UNIT_TEST(RemoveByIndex) {
TSample msg;
@@ -354,6 +354,6 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) {
UNIT_ASSERT(field->HasValue());
UNIT_ASSERT_VALUES_EQUAL(20, field->Get<int>());
}
-}
+}
}
}
diff --git a/library/cpp/protobuf/util/ut/sample_for_simple_reflection.proto b/library/cpp/protobuf/util/ut/sample_for_simple_reflection.proto
index cca1dd869a..ae714de227 100644
--- a/library/cpp/protobuf/util/ut/sample_for_simple_reflection.proto
+++ b/library/cpp/protobuf/util/ut/sample_for_simple_reflection.proto
@@ -1,15 +1,15 @@
message TInnerSample {
- repeated int32 RepInt = 1;
+ repeated int32 RepInt = 1;
extensions 100 to 199;
-}
-
+}
+
message TSample {
- optional string OneStr = 1;
+ optional string OneStr = 1;
optional TInnerSample OneMsg = 2;
repeated TInnerSample RepMsg = 3;
- repeated string RepStr = 4;
- optional string AnotherOneStr = 5;
+ repeated string RepStr = 4;
+ optional string AnotherOneStr = 5;
optional int32 OneInt = 6;
repeated int32 RepInt = 7;
@@ -22,4 +22,4 @@ message TSample {
repeated EEnum RepEnum = 9;
extensions 100 to 199;
-}
+}
diff --git a/library/cpp/protobuf/util/ut/ya.make b/library/cpp/protobuf/util/ut/ya.make
index 701ba9a8c8..32c19a87e0 100644
--- a/library/cpp/protobuf/util/ut/ya.make
+++ b/library/cpp/protobuf/util/ut/ya.make
@@ -5,7 +5,7 @@ UNITTEST_FOR(library/cpp/protobuf/util)
SRCS(
extensions.proto
sample_for_is_equal.proto
- sample_for_simple_reflection.proto
+ sample_for_simple_reflection.proto
common_ut.proto
pb_io_ut.cpp
is_equal_ut.cpp