aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/protobuf/util
diff options
context:
space:
mode:
authoryazevnul <yazevnul@yandex-team.ru>2022-02-10 16:46:46 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:46 +0300
commit8cbc307de0221f84c80c42dcbe07d40727537e2c (patch)
tree625d5a673015d1df891e051033e9fcde5c7be4e5 /library/cpp/protobuf/util
parent30d1ef3941e0dc835be7609de5ebee66958f215a (diff)
downloadydb-8cbc307de0221f84c80c42dcbe07d40727537e2c.tar.gz
Restoring authorship annotation for <yazevnul@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/protobuf/util')
-rw-r--r--library/cpp/protobuf/util/is_equal.h18
-rw-r--r--library/cpp/protobuf/util/is_equal_ut.cpp12
-rw-r--r--library/cpp/protobuf/util/iterators_ut.cpp6
-rw-r--r--library/cpp/protobuf/util/merge.cpp6
-rw-r--r--library/cpp/protobuf/util/merge.h16
-rw-r--r--library/cpp/protobuf/util/merge_ut.cpp4
-rw-r--r--library/cpp/protobuf/util/pb_io.cpp178
-rw-r--r--library/cpp/protobuf/util/pb_io.h208
-rw-r--r--library/cpp/protobuf/util/pb_io_ut.cpp534
-rw-r--r--library/cpp/protobuf/util/repeated_field_utils_ut.cpp4
-rw-r--r--library/cpp/protobuf/util/simple_reflection.h2
-rw-r--r--library/cpp/protobuf/util/simple_reflection_ut.cpp12
-rw-r--r--library/cpp/protobuf/util/ut/common_ut.proto8
-rw-r--r--library/cpp/protobuf/util/ut/ya.make2
-rw-r--r--library/cpp/protobuf/util/walk_ut.cpp2
15 files changed, 506 insertions, 506 deletions
diff --git a/library/cpp/protobuf/util/is_equal.h b/library/cpp/protobuf/util/is_equal.h
index 13c0aae63d..d47cb37cb7 100644
--- a/library/cpp/protobuf/util/is_equal.h
+++ b/library/cpp/protobuf/util/is_equal.h
@@ -1,22 +1,22 @@
#pragma once
-#include <util/generic/fwd.h>
+#include <util/generic/fwd.h>
-namespace google {
- namespace protobuf {
- class Message;
+namespace google {
+ namespace protobuf {
+ class Message;
class FieldDescriptor;
- }
-}
+ }
+}
namespace NProtoBuf {
using ::google::protobuf::FieldDescriptor;
using ::google::protobuf::Message;
-}
+}
-namespace NProtoBuf {
+namespace NProtoBuf {
// Reflection-based equality check for arbitrary protobuf messages
-
+
// Strict comparison: optional field without value is NOT equal to
// a field with explicitly set default value.
bool IsEqual(const Message& m1, const Message& m2);
diff --git a/library/cpp/protobuf/util/is_equal_ut.cpp b/library/cpp/protobuf/util/is_equal_ut.cpp
index 3ca4c90dd5..96e77c95c6 100644
--- a/library/cpp/protobuf/util/is_equal_ut.cpp
+++ b/library/cpp/protobuf/util/is_equal_ut.cpp
@@ -5,19 +5,19 @@
#include <google/protobuf/descriptor.h>
-Y_UNIT_TEST_SUITE(ProtobufIsEqual) {
+Y_UNIT_TEST_SUITE(ProtobufIsEqual) {
const ::google::protobuf::Descriptor* Descr = TSampleForIsEqual::descriptor();
const ::google::protobuf::FieldDescriptor* NameDescr = Descr->field(0);
const ::google::protobuf::FieldDescriptor* InnerDescr = Descr->field(1);
- Y_UNIT_TEST(CheckDescriptors) {
+ Y_UNIT_TEST(CheckDescriptors) {
UNIT_ASSERT(Descr);
UNIT_ASSERT(NameDescr);
UNIT_ASSERT_VALUES_EQUAL(NameDescr->name(), "Name");
UNIT_ASSERT_VALUES_EQUAL(InnerDescr->name(), "Inner");
}
- Y_UNIT_TEST(IsEqual1) {
+ Y_UNIT_TEST(IsEqual1) {
TSampleForIsEqual a;
TSampleForIsEqual b;
@@ -33,7 +33,7 @@ Y_UNIT_TEST_SUITE(ProtobufIsEqual) {
UNIT_ASSERT(!NProtoBuf::IsEqualField(a, b, *NameDescr));
}
- Y_UNIT_TEST(IsEqual2) {
+ Y_UNIT_TEST(IsEqual2) {
TSampleForIsEqual a;
TSampleForIsEqual b;
@@ -50,7 +50,7 @@ Y_UNIT_TEST_SUITE(ProtobufIsEqual) {
UNIT_ASSERT(!equalField);
}
- Y_UNIT_TEST(IsEqual3) {
+ Y_UNIT_TEST(IsEqual3) {
TSampleForIsEqual a;
TSampleForIsEqual b;
@@ -74,7 +74,7 @@ Y_UNIT_TEST_SUITE(ProtobufIsEqual) {
UNIT_ASSERT(!NProtoBuf::IsEqualField(a, b, *NameDescr));
}
- Y_UNIT_TEST(IsEqualDefault) {
+ Y_UNIT_TEST(IsEqualDefault) {
TSampleForIsEqual a;
TSampleForIsEqual b;
diff --git a/library/cpp/protobuf/util/iterators_ut.cpp b/library/cpp/protobuf/util/iterators_ut.cpp
index 9ebcff2963..7a255f0188 100644
--- a/library/cpp/protobuf/util/iterators_ut.cpp
+++ b/library/cpp/protobuf/util/iterators_ut.cpp
@@ -9,8 +9,8 @@
using NProtoBuf::TFieldsIterator;
using NProtoBuf::TConstField;
-Y_UNIT_TEST_SUITE(Iterators) {
- Y_UNIT_TEST(Count) {
+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());
@@ -36,7 +36,7 @@ Y_UNIT_TEST_SUITE(Iterators) {
UNIT_ASSERT_VALUES_EQUAL(values, 1);
}
- Y_UNIT_TEST(AnyOf) {
+ Y_UNIT_TEST(AnyOf) {
NProtobufUtilUt::TWalkTest proto;
const NProtoBuf::Descriptor* d = proto.GetDescriptor();
TFieldsIterator begin(d), end(d, d->field_count());
diff --git a/library/cpp/protobuf/util/merge.cpp b/library/cpp/protobuf/util/merge.cpp
index dc2b9cc806..19e1e6bafc 100644
--- a/library/cpp/protobuf/util/merge.cpp
+++ b/library/cpp/protobuf/util/merge.cpp
@@ -1,8 +1,8 @@
#include "merge.h"
-#include "simple_reflection.h"
-
+#include "simple_reflection.h"
+
#include <google/protobuf/message.h>
-
+
#include <library/cpp/protobuf/util/proto/merge.pb.h>
namespace NProtoBuf {
diff --git a/library/cpp/protobuf/util/merge.h b/library/cpp/protobuf/util/merge.h
index 924975f141..4acea08697 100644
--- a/library/cpp/protobuf/util/merge.h
+++ b/library/cpp/protobuf/util/merge.h
@@ -1,14 +1,14 @@
#pragma once
-namespace google {
- namespace protobuf {
- class Message;
- }
-}
+namespace google {
+ namespace protobuf {
+ class Message;
+ }
+}
-namespace NProtoBuf {
- using Message = ::google::protobuf::Message;
-}
+namespace NProtoBuf {
+ using Message = ::google::protobuf::Message;
+}
namespace NProtoBuf {
// Similiar to Message::MergeFrom, overwrites existing repeated fields
diff --git a/library/cpp/protobuf/util/merge_ut.cpp b/library/cpp/protobuf/util/merge_ut.cpp
index 22217db183..01bf3d1a48 100644
--- a/library/cpp/protobuf/util/merge_ut.cpp
+++ b/library/cpp/protobuf/util/merge_ut.cpp
@@ -5,7 +5,7 @@
using namespace NProtoBuf;
-Y_UNIT_TEST_SUITE(ProtobufMerge) {
+Y_UNIT_TEST_SUITE(ProtobufMerge) {
static void InitProto(NProtobufUtilUt::TMergeTest & p, bool isSrc) {
size_t start = isSrc ? 0 : 100;
@@ -35,7 +35,7 @@ Y_UNIT_TEST_SUITE(ProtobufMerge) {
mm3->AddB(start + 13);
}
- Y_UNIT_TEST(CustomMerge) {
+ Y_UNIT_TEST(CustomMerge) {
NProtobufUtilUt::TMergeTest src, dst;
InitProto(src, true);
InitProto(dst, false);
diff --git a/library/cpp/protobuf/util/pb_io.cpp b/library/cpp/protobuf/util/pb_io.cpp
index 6270ee0624..ab808fd6f4 100644
--- a/library/cpp/protobuf/util/pb_io.cpp
+++ b/library/cpp/protobuf/util/pb_io.cpp
@@ -8,11 +8,11 @@
#include <google/protobuf/text_format.h>
#include <util/generic/string.h>
-#include <util/stream/file.h>
-#include <util/stream/str.h>
+#include <util/stream/file.h>
+#include <util/stream/str.h>
#include <util/string/cast.h>
-namespace NProtoBuf {
+namespace NProtoBuf {
class TEnumIdValuePrinter : public google::protobuf::TextFormat::FastFieldValuePrinter {
public:
@@ -34,7 +34,7 @@ namespace NProtoBuf {
} catch (const std::exception&) {
return false;
}
- }
+ }
void SerializeToBase64String(const Message& m, TString& dataBase64) {
TString rawData;
@@ -58,8 +58,8 @@ namespace NProtoBuf {
} catch (const std::exception&) {
return false;
}
- }
-
+ }
+
const TString ShortUtf8DebugString(const Message& message) {
TextFormat::Printer printer;
printer.SetSingleLineMode(true);
@@ -93,21 +93,21 @@ int operator&(NProtoBuf::Message& m, IBinSaver& f) {
return 0;
}
-void SerializeToTextFormat(const NProtoBuf::Message& m, IOutputStream& out) {
- NProtoBuf::io::TCopyingOutputStreamAdaptor adaptor(&out);
+void SerializeToTextFormat(const NProtoBuf::Message& m, IOutputStream& out) {
+ NProtoBuf::io::TCopyingOutputStreamAdaptor adaptor(&out);
- if (!NProtoBuf::TextFormat::Print(m, &adaptor)) {
+ if (!NProtoBuf::TextFormat::Print(m, &adaptor)) {
ythrow yexception() << "SerializeToTextFormat failed on Print";
- }
+ }
}
void SerializeToTextFormat(const NProtoBuf::Message& m, const TString& fileName) {
/* TUnbufferedFileOutput is unbuffered, but TCopyingOutputStreamAdaptor adds
- * a buffer on top of it. */
+ * a buffer on top of it. */
TUnbufferedFileOutput stream(fileName);
- SerializeToTextFormat(m, stream);
-}
-
+ SerializeToTextFormat(m, stream);
+}
+
void SerializeToTextFormatWithEnumId(const NProtoBuf::Message& m, IOutputStream& out) {
google::protobuf::TextFormat::Printer printer;
printer.SetDefaultFieldValuePrinter(new NProtoBuf::TEnumIdValuePrinter());
@@ -130,20 +130,20 @@ void SerializeToTextFormatPretty(const NProtoBuf::Message& m, IOutputStream& out
}
}
-static void ConfigureParser(const EParseFromTextFormatOptions options,
- NProtoBuf::TextFormat::Parser& p) {
- if (options & EParseFromTextFormatOption::AllowUnknownField) {
- p.AllowUnknownField(true);
- }
-}
-
-void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options) {
- NProtoBuf::io::TCopyingInputStreamAdaptor adaptor(&in);
- NProtoBuf::TextFormat::Parser p;
- ConfigureParser(options, p);
-
- if (!p.Parse(&adaptor, &m)) {
+static void ConfigureParser(const EParseFromTextFormatOptions options,
+ NProtoBuf::TextFormat::Parser& p) {
+ if (options & EParseFromTextFormatOption::AllowUnknownField) {
+ p.AllowUnknownField(true);
+ }
+}
+
+void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options) {
+ NProtoBuf::io::TCopyingInputStreamAdaptor adaptor(&in);
+ NProtoBuf::TextFormat::Parser p;
+ ConfigureParser(options, p);
+
+ if (!p.Parse(&adaptor, &m)) {
// remove everything that may have been read
m.Clear();
ythrow yexception() << "ParseFromTextFormat failed on Parse for " << m.GetTypeName();
@@ -151,71 +151,71 @@ void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
}
void ParseFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options) {
+ const EParseFromTextFormatOptions options) {
/* TUnbufferedFileInput is unbuffered, but TCopyingInputStreamAdaptor adds
- * a buffer on top of it. */
+ * a buffer on top of it. */
TUnbufferedFileInput stream(fileName);
- ParseFromTextFormat(stream, m, options);
-}
-
+ ParseFromTextFormat(stream, m, options);
+}
+
bool TryParseFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options) {
- try {
- ParseFromTextFormat(fileName, m, options);
- } catch (std::exception&) {
- return false;
- }
-
- return true;
+ const EParseFromTextFormatOptions options) {
+ try {
+ ParseFromTextFormat(fileName, m, options);
+ } catch (std::exception&) {
+ return false;
+ }
+
+ return true;
}
-bool TryParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options) {
- try {
- ParseFromTextFormat(in, m, options);
- } catch (std::exception&) {
- return false;
- }
-
- return true;
-}
-
-void MergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options) {
- NProtoBuf::io::TCopyingInputStreamAdaptor adaptor(&in);
- NProtoBuf::TextFormat::Parser p;
- ConfigureParser(options, p);
- if (!p.Merge(&adaptor, &m)) {
- ythrow yexception() << "MergeFromTextFormat failed on Merge for " << m.GetTypeName();
- }
-}
-
-void MergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options) {
+bool TryParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options) {
+ try {
+ ParseFromTextFormat(in, m, options);
+ } catch (std::exception&) {
+ return false;
+ }
+
+ return true;
+}
+
+void MergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options) {
+ NProtoBuf::io::TCopyingInputStreamAdaptor adaptor(&in);
+ NProtoBuf::TextFormat::Parser p;
+ ConfigureParser(options, p);
+ if (!p.Merge(&adaptor, &m)) {
+ ythrow yexception() << "MergeFromTextFormat failed on Merge for " << m.GetTypeName();
+ }
+}
+
+void MergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options) {
/* TUnbufferedFileInput is unbuffered, but TCopyingInputStreamAdaptor adds
- * a buffer on top of it. */
+ * a buffer on top of it. */
TUnbufferedFileInput stream(fileName);
- MergeFromTextFormat(stream, m, options);
-}
-
-bool TryMergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options) {
- try {
- MergeFromTextFormat(fileName, m, options);
- } catch (std::exception&) {
- return false;
- }
-
- return true;
-}
-
-bool TryMergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options) {
- try {
- MergeFromTextFormat(in, m, options);
- } catch (std::exception&) {
- return false;
- }
-
- return true;
-}
+ MergeFromTextFormat(stream, m, options);
+}
+
+bool TryMergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options) {
+ try {
+ MergeFromTextFormat(fileName, m, options);
+ } catch (std::exception&) {
+ return false;
+ }
+
+ return true;
+}
+
+bool TryMergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options) {
+ try {
+ MergeFromTextFormat(in, m, options);
+ } catch (std::exception&) {
+ return false;
+ }
+
+ return true;
+}
diff --git a/library/cpp/protobuf/util/pb_io.h b/library/cpp/protobuf/util/pb_io.h
index 493c84cb5f..a431b4200b 100644
--- a/library/cpp/protobuf/util/pb_io.h
+++ b/library/cpp/protobuf/util/pb_io.h
@@ -1,37 +1,37 @@
#pragma once
-#include <util/generic/fwd.h>
-#include <util/generic/flags.h>
+#include <util/generic/fwd.h>
+#include <util/generic/flags.h>
-struct IBinSaver;
+struct IBinSaver;
-namespace google {
- namespace protobuf {
+namespace google {
+ namespace protobuf {
class Message;
- }
-}
-
-namespace NProtoBuf {
- using Message = ::google::protobuf::Message;
-}
-
-class IInputStream;
-class IOutputStream;
-
-namespace NProtoBuf {
- /* Parse base64 URL encoded serialized message from string.
- */
+ }
+}
+
+namespace NProtoBuf {
+ using Message = ::google::protobuf::Message;
+}
+
+class IInputStream;
+class IOutputStream;
+
+namespace NProtoBuf {
+ /* Parse base64 URL encoded serialized message from string.
+ */
void ParseFromBase64String(const TStringBuf dataBase64, Message& m, bool allowUneven = false);
bool TryParseFromBase64String(const TStringBuf dataBase64, Message& m, bool allowUneven = false);
- template <typename T>
+ template <typename T>
static T ParseFromBase64String(const TStringBuf& dataBase64, bool allowUneven = false) {
- T m;
+ T m;
ParseFromBase64String(dataBase64, m, allowUneven);
- return m;
- }
+ return m;
+ }
- /* Serialize message into string and apply base64 URL encoding.
- */
+ /* Serialize message into string and apply base64 URL encoding.
+ */
TString SerializeToBase64String(const Message& m);
void SerializeToBase64String(const Message& m, TString& dataBase64);
bool TrySerializeToBase64String(const Message& m, TString& dataBase64);
@@ -44,10 +44,10 @@ namespace NProtoBuf {
int operator&(NProtoBuf::Message& m, IBinSaver& f);
-// Write a textual representation of the given message to the given file.
+// Write a textual representation of the given message to the given file.
void SerializeToTextFormat(const NProtoBuf::Message& m, const TString& fileName);
-void SerializeToTextFormat(const NProtoBuf::Message& m, IOutputStream& out);
-
+void SerializeToTextFormat(const NProtoBuf::Message& m, IOutputStream& out);
+
// Write a textual representation of the given message to the given output stream
// with flags UseShortRepeatedPrimitives and UseUtf8StringEscaping set to true.
void SerializeToTextFormatPretty(const NProtoBuf::Message& m, IOutputStream& out);
@@ -56,83 +56,83 @@ void SerializeToTextFormatPretty(const NProtoBuf::Message& m, IOutputStream& out
// use enum id instead of enum name for all enum fields.
void SerializeToTextFormatWithEnumId(const NProtoBuf::Message& m, IOutputStream& out);
-enum class EParseFromTextFormatOption : ui64 {
- // Unknown fields will be ignored by the parser
- AllowUnknownField = 1
-};
-
-Y_DECLARE_FLAGS(EParseFromTextFormatOptions, EParseFromTextFormatOption);
-
-// Parse a text-format protocol message from the given file into message object.
+enum class EParseFromTextFormatOption : ui64 {
+ // Unknown fields will be ignored by the parser
+ AllowUnknownField = 1
+};
+
+Y_DECLARE_FLAGS(EParseFromTextFormatOptions, EParseFromTextFormatOption);
+
+// Parse a text-format protocol message from the given file into message object.
void ParseFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options = {});
-// NOTE: will read `in` till the end.
-void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options = {});
-
-/* @return `true` if parsing was successfull and `false` otherwise.
- *
- * @see `ParseFromTextFormat`
- */
+ const EParseFromTextFormatOptions options = {});
+// NOTE: will read `in` till the end.
+void ParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options = {});
+
+/* @return `true` if parsing was successfull and `false` otherwise.
+ *
+ * @see `ParseFromTextFormat`
+ */
bool TryParseFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options = {});
-// NOTE: will read `in` till the end.
-bool TryParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options = {});
-
-// @see `ParseFromTextFormat`
-template <typename T>
+ const EParseFromTextFormatOptions options = {});
+// NOTE: will read `in` till the end.
+bool TryParseFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options = {});
+
+// @see `ParseFromTextFormat`
+template <typename T>
static T ParseFromTextFormat(const TString& fileName,
- const EParseFromTextFormatOptions options = {}) {
- T message;
- ParseFromTextFormat(fileName, message, options);
- return message;
-}
-
-// @see `ParseFromTextFormat`
-// NOTE: will read `in` till the end.
-template <typename T>
-static T ParseFromTextFormat(IInputStream& in,
- const EParseFromTextFormatOptions options = {}) {
- T message;
- ParseFromTextFormat(in, message, options);
- return message;
-}
-
-// Merge a text-format protocol message from the given file into message object.
-//
-// NOTE: Even when parsing failed and exception was thrown `m` may be different from its original
-// value. User must implement transactional logic around `MergeFromTextFormat` by himself.
-void MergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options = {});
-// NOTE: will read `in` till the end.
-void MergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options = {});
-/* @return `true` if parsing was successfull and `false` otherwise.
- *
- * @see `MergeFromTextFormat`
- */
-bool TryMergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options = {});
-// NOTE: will read `in` till the end.
-bool TryMergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
- const EParseFromTextFormatOptions options = {});
-
-// @see `MergeFromTextFormat`
-template <typename T>
-static T MergeFromTextFormat(const TString& fileName,
- const EParseFromTextFormatOptions options = {}) {
- T message;
- MergeFromTextFormat(fileName, message, options);
- return message;
-}
-
-// @see `MergeFromTextFormat`
-// NOTE: will read `in` till the end.
-template <typename T>
-static T MergeFromTextFormat(IInputStream& in,
- const EParseFromTextFormatOptions options = {}) {
- T message;
- MergeFromTextFormat(in, message, options);
- return message;
-}
+ const EParseFromTextFormatOptions options = {}) {
+ T message;
+ ParseFromTextFormat(fileName, message, options);
+ return message;
+}
+
+// @see `ParseFromTextFormat`
+// NOTE: will read `in` till the end.
+template <typename T>
+static T ParseFromTextFormat(IInputStream& in,
+ const EParseFromTextFormatOptions options = {}) {
+ T message;
+ ParseFromTextFormat(in, message, options);
+ return message;
+}
+
+// Merge a text-format protocol message from the given file into message object.
+//
+// NOTE: Even when parsing failed and exception was thrown `m` may be different from its original
+// value. User must implement transactional logic around `MergeFromTextFormat` by himself.
+void MergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options = {});
+// NOTE: will read `in` till the end.
+void MergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options = {});
+/* @return `true` if parsing was successfull and `false` otherwise.
+ *
+ * @see `MergeFromTextFormat`
+ */
+bool TryMergeFromTextFormat(const TString& fileName, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options = {});
+// NOTE: will read `in` till the end.
+bool TryMergeFromTextFormat(IInputStream& in, NProtoBuf::Message& m,
+ const EParseFromTextFormatOptions options = {});
+
+// @see `MergeFromTextFormat`
+template <typename T>
+static T MergeFromTextFormat(const TString& fileName,
+ const EParseFromTextFormatOptions options = {}) {
+ T message;
+ MergeFromTextFormat(fileName, message, options);
+ return message;
+}
+
+// @see `MergeFromTextFormat`
+// NOTE: will read `in` till the end.
+template <typename T>
+static T MergeFromTextFormat(IInputStream& in,
+ const EParseFromTextFormatOptions options = {}) {
+ T message;
+ MergeFromTextFormat(in, message, options);
+ return message;
+}
diff --git a/library/cpp/protobuf/util/pb_io_ut.cpp b/library/cpp/protobuf/util/pb_io_ut.cpp
index 875d6dc602..32bba7bc40 100644
--- a/library/cpp/protobuf/util/pb_io_ut.cpp
+++ b/library/cpp/protobuf/util/pb_io_ut.cpp
@@ -1,22 +1,22 @@
-#include "pb_io.h"
-
-#include "is_equal.h"
-
+#include "pb_io.h"
+
+#include "is_equal.h"
+
#include <library/cpp/protobuf/util/ut/common_ut.pb.h>
-
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/folder/path.h>
-#include <util/folder/tempdir.h>
-#include <util/stream/file.h>
-#include <util/stream/str.h>
-
-static NProtobufUtilUt::TTextTest GetCorrectMessage() {
- NProtobufUtilUt::TTextTest m;
- m.SetFoo(42);
- return m;
-}
-
+
+#include <util/folder/path.h>
+#include <util/folder/tempdir.h>
+#include <util/stream/file.h>
+#include <util/stream/str.h>
+
+static NProtobufUtilUt::TTextTest GetCorrectMessage() {
+ NProtobufUtilUt::TTextTest m;
+ m.SetFoo(42);
+ return m;
+}
+
static NProtobufUtilUt::TTextEnumTest GetCorrectEnumMessage() {
NProtobufUtilUt::TTextEnumTest m;
m.SetSlot(NProtobufUtilUt::TTextEnumTest::EET_SLOT_1);
@@ -25,41 +25,41 @@ static NProtobufUtilUt::TTextEnumTest GetCorrectEnumMessage() {
static const TString CORRECT_MESSAGE =
R"(Foo: 42
-)";
+)";
static const TString CORRECT_ENUM_NAME_MESSAGE =
R"(Slot: EET_SLOT_1
)";
static const TString CORRECT_ENUM_ID_MESSAGE =
R"(Slot: 1
)";
-
+
static const TString INCORRECT_MESSAGE =
R"(Bar: 1
-)";
+)";
static const TString INCORRECT_ENUM_NAME_MESSAGE =
R"(Slot: EET_SLOT_3
)";
static const TString INCORRECT_ENUM_ID_MESSAGE =
R"(Slot: 3
)";
-
+
static const TString CORRECT_BASE64_MESSAGE = "CCo,";
static const TString CORRECT_UNEVEN_BASE64_MESSAGE = "CCo";
static const TString INCORRECT_BASE64_MESSAGE = "CC";
-Y_UNIT_TEST_SUITE(TTestProtoBufIO) {
- Y_UNIT_TEST(TestBase64) {
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT(NProtoBuf::TryParseFromBase64String(CORRECT_BASE64_MESSAGE, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT(!NProtoBuf::TryParseFromBase64String(INCORRECT_BASE64_MESSAGE, message));
- }
- {
+Y_UNIT_TEST_SUITE(TTestProtoBufIO) {
+ Y_UNIT_TEST(TestBase64) {
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT(NProtoBuf::TryParseFromBase64String(CORRECT_BASE64_MESSAGE, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT(!NProtoBuf::TryParseFromBase64String(INCORRECT_BASE64_MESSAGE, message));
+ }
+ {
NProtobufUtilUt::TTextTest message;
UNIT_ASSERT(NProtoBuf::TryParseFromBase64String(CORRECT_UNEVEN_BASE64_MESSAGE , message, true));
}
@@ -68,134 +68,134 @@ Y_UNIT_TEST_SUITE(TTestProtoBufIO) {
UNIT_ASSERT(!NProtoBuf::TryParseFromBase64String(CORRECT_UNEVEN_BASE64_MESSAGE , message, false));
}
{
- UNIT_ASSERT_VALUES_EQUAL(CORRECT_BASE64_MESSAGE, NProtoBuf::SerializeToBase64String(GetCorrectMessage()));
- }
- {
- const auto m = NProtoBuf::ParseFromBase64String<NProtobufUtilUt::TTextTest>(CORRECT_BASE64_MESSAGE);
- UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
- }
- }
-
- Y_UNIT_TEST(TestParseFromTextFormat) {
- TTempDir tempDir;
- const TFsPath correctFileName = TFsPath{tempDir()} / "correct.pb.txt";
- const TFsPath incorrectFileName = TFsPath{tempDir()} / "incorrect.pb.txt";
-
+ UNIT_ASSERT_VALUES_EQUAL(CORRECT_BASE64_MESSAGE, NProtoBuf::SerializeToBase64String(GetCorrectMessage()));
+ }
+ {
+ const auto m = NProtoBuf::ParseFromBase64String<NProtobufUtilUt::TTextTest>(CORRECT_BASE64_MESSAGE);
+ UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
+ }
+ }
+
+ Y_UNIT_TEST(TestParseFromTextFormat) {
+ TTempDir tempDir;
+ const TFsPath correctFileName = TFsPath{tempDir()} / "correct.pb.txt";
+ const TFsPath incorrectFileName = TFsPath{tempDir()} / "incorrect.pb.txt";
+
TFileOutput{correctFileName}.Write(CORRECT_MESSAGE);
TFileOutput{incorrectFileName}.Write(INCORRECT_MESSAGE);
-
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT(TryParseFromTextFormat(correctFileName, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT(!TryParseFromTextFormat(incorrectFileName, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- TStringInput in{CORRECT_MESSAGE};
- UNIT_ASSERT(TryParseFromTextFormat(in, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- TStringInput in{INCORRECT_MESSAGE};
- UNIT_ASSERT(!TryParseFromTextFormat(in, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT_NO_EXCEPTION(TryParseFromTextFormat(incorrectFileName, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT(!TryParseFromTextFormat("this_file_doesnt_exists", message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT_NO_EXCEPTION(TryParseFromTextFormat("this_file_doesnt_exists", message));
- }
- {
- NProtobufUtilUt::TTextTest message;
+
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT(TryParseFromTextFormat(correctFileName, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT(!TryParseFromTextFormat(incorrectFileName, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ TStringInput in{CORRECT_MESSAGE};
+ UNIT_ASSERT(TryParseFromTextFormat(in, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ TStringInput in{INCORRECT_MESSAGE};
+ UNIT_ASSERT(!TryParseFromTextFormat(in, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT_NO_EXCEPTION(TryParseFromTextFormat(incorrectFileName, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT(!TryParseFromTextFormat("this_file_doesnt_exists", message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT_NO_EXCEPTION(TryParseFromTextFormat("this_file_doesnt_exists", message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
UNIT_ASSERT_EXCEPTION(ParseFromTextFormat("this_file_doesnt_exists", message), TFileError);
}
{
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT_NO_EXCEPTION(ParseFromTextFormat(correctFileName, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT_EXCEPTION(ParseFromTextFormat(incorrectFileName, message), yexception);
- }
- {
- NProtobufUtilUt::TTextTest message;
- TStringInput in{CORRECT_MESSAGE};
- UNIT_ASSERT_NO_EXCEPTION(ParseFromTextFormat(in, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- TStringInput in{INCORRECT_MESSAGE};
- UNIT_ASSERT_EXCEPTION(ParseFromTextFormat(in, message), yexception);
- }
- {
- NProtobufUtilUt::TTextTest m;
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT_NO_EXCEPTION(ParseFromTextFormat(correctFileName, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT_EXCEPTION(ParseFromTextFormat(incorrectFileName, message), yexception);
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ TStringInput in{CORRECT_MESSAGE};
+ UNIT_ASSERT_NO_EXCEPTION(ParseFromTextFormat(in, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ TStringInput in{INCORRECT_MESSAGE};
+ UNIT_ASSERT_EXCEPTION(ParseFromTextFormat(in, message), yexception);
+ }
+ {
+ NProtobufUtilUt::TTextTest m;
const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) {
mm = ParseFromTextFormat<NProtobufUtilUt::TTextTest>(correctFileName);
- };
- UNIT_ASSERT_NO_EXCEPTION(f(m));
- UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
- }
- {
- UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextTest>(incorrectFileName), yexception);
- }
- {
- NProtobufUtilUt::TTextTest m;
- TStringInput in{CORRECT_MESSAGE};
+ };
+ UNIT_ASSERT_NO_EXCEPTION(f(m));
+ UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
+ }
+ {
+ UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextTest>(incorrectFileName), yexception);
+ }
+ {
+ NProtobufUtilUt::TTextTest m;
+ TStringInput in{CORRECT_MESSAGE};
const auto f = [&in](NProtobufUtilUt::TTextTest& mm) {
mm = ParseFromTextFormat<NProtobufUtilUt::TTextTest>(in);
- };
- UNIT_ASSERT_NO_EXCEPTION(f(m));
- UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
- }
- {
- TStringInput in{INCORRECT_MESSAGE};
- UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextTest>(in), yexception);
- }
- {
+ };
+ UNIT_ASSERT_NO_EXCEPTION(f(m));
+ UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
+ }
+ {
+ TStringInput in{INCORRECT_MESSAGE};
+ UNIT_ASSERT_EXCEPTION(ParseFromTextFormat<NProtobufUtilUt::TTextTest>(in), yexception);
+ }
+ {
const TFsPath correctFileName2 = TFsPath{tempDir()} / "serialized.pb.txt";
- const auto original = GetCorrectMessage();
+ const auto original = GetCorrectMessage();
UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, correctFileName2));
const auto serializedStr = TUnbufferedFileInput{correctFileName2}.ReadAll();
- UNIT_ASSERT_VALUES_EQUAL(serializedStr, CORRECT_MESSAGE);
- }
- {
- const auto original = GetCorrectMessage();
- TStringStream out;
- UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, out));
- UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_MESSAGE);
- }
- {
- NProtobufUtilUt::TTextTest m;
+ UNIT_ASSERT_VALUES_EQUAL(serializedStr, CORRECT_MESSAGE);
+ }
+ {
+ const auto original = GetCorrectMessage();
+ TStringStream out;
+ UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, out));
+ UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_MESSAGE);
+ }
+ {
+ NProtobufUtilUt::TTextTest m;
const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) {
mm = ParseFromTextFormat<NProtobufUtilUt::TTextTest>(
correctFileName,
EParseFromTextFormatOption::AllowUnknownField);
- };
- UNIT_ASSERT_NO_EXCEPTION(f(m));
- UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
- }
- {
- const NProtobufUtilUt::TTextTest empty;
- NProtobufUtilUt::TTextTest m;
+ };
+ UNIT_ASSERT_NO_EXCEPTION(f(m));
+ UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
+ }
+ {
+ const NProtobufUtilUt::TTextTest empty;
+ NProtobufUtilUt::TTextTest m;
const auto f = [&incorrectFileName](NProtobufUtilUt::TTextTest& mm) {
mm = ParseFromTextFormat<NProtobufUtilUt::TTextTest>(
incorrectFileName,
EParseFromTextFormatOption::AllowUnknownField);
- };
- UNIT_ASSERT_NO_EXCEPTION(f(m));
- UNIT_ASSERT(NProtoBuf::IsEqual(empty, m));
- }
- }
-
+ };
+ UNIT_ASSERT_NO_EXCEPTION(f(m));
+ UNIT_ASSERT(NProtoBuf::IsEqual(empty, m));
+ }
+ }
+
Y_UNIT_TEST(TestSerializeToTextFormatWithEnumId) {
TTempDir tempDir;
const TFsPath correctNameFileName = TFsPath{tempDir()} / "correct_name.pb.txt";
@@ -250,139 +250,139 @@ Y_UNIT_TEST_SUITE(TTestProtoBufIO) {
}
}
- Y_UNIT_TEST(TestMergeFromTextFormat) {
- //
- // Tests cases below are identical to `Parse` tests
- //
- TTempDir tempDir;
- const TFsPath correctFileName = TFsPath{tempDir()} / "correct.pb.txt";
- const TFsPath incorrectFileName = TFsPath{tempDir()} / "incorrect.pb.txt";
-
+ Y_UNIT_TEST(TestMergeFromTextFormat) {
+ //
+ // Tests cases below are identical to `Parse` tests
+ //
+ TTempDir tempDir;
+ const TFsPath correctFileName = TFsPath{tempDir()} / "correct.pb.txt";
+ const TFsPath incorrectFileName = TFsPath{tempDir()} / "incorrect.pb.txt";
+
TFileOutput{correctFileName}.Write(CORRECT_MESSAGE);
TFileOutput{incorrectFileName}.Write(INCORRECT_MESSAGE);
-
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT(TryMergeFromTextFormat(correctFileName, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT(!TryMergeFromTextFormat(incorrectFileName, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- TStringInput in{CORRECT_MESSAGE};
- UNIT_ASSERT(TryMergeFromTextFormat(in, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- TStringInput in{INCORRECT_MESSAGE};
- UNIT_ASSERT(!TryMergeFromTextFormat(in, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT_NO_EXCEPTION(TryMergeFromTextFormat(incorrectFileName, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT(!TryMergeFromTextFormat("this_file_doesnt_exists", message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT_NO_EXCEPTION(TryMergeFromTextFormat("this_file_doesnt_exists", message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT_EXCEPTION(MergeFromTextFormat("this_file_doesnt_exists", message), TFileError);
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT_NO_EXCEPTION(MergeFromTextFormat(correctFileName, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- UNIT_ASSERT_EXCEPTION(MergeFromTextFormat(incorrectFileName, message), yexception);
- }
- {
- NProtobufUtilUt::TTextTest message;
- TStringInput in{CORRECT_MESSAGE};
- UNIT_ASSERT_NO_EXCEPTION(MergeFromTextFormat(in, message));
- }
- {
- NProtobufUtilUt::TTextTest message;
- TStringInput in{INCORRECT_MESSAGE};
- UNIT_ASSERT_EXCEPTION(MergeFromTextFormat(in, message), yexception);
- }
- {
- NProtobufUtilUt::TTextTest m;
- const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) {
- mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(correctFileName);
- };
- UNIT_ASSERT_NO_EXCEPTION(f(m));
- UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
- }
- {
- UNIT_ASSERT_EXCEPTION(MergeFromTextFormat<NProtobufUtilUt::TTextTest>(incorrectFileName), yexception);
- }
- {
- NProtobufUtilUt::TTextTest m;
- TStringInput in{CORRECT_MESSAGE};
- const auto f = [&in](NProtobufUtilUt::TTextTest& mm) {
- mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(in);
- };
- UNIT_ASSERT_NO_EXCEPTION(f(m));
- UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
- }
- {
- TStringInput in{INCORRECT_MESSAGE};
- UNIT_ASSERT_EXCEPTION(MergeFromTextFormat<NProtobufUtilUt::TTextTest>(in), yexception);
- }
- {
- const TFsPath correctFileName2 = TFsPath{tempDir()} / "serialized.pb.txt";
- const auto original = GetCorrectMessage();
- UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, correctFileName2));
+
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT(TryMergeFromTextFormat(correctFileName, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT(!TryMergeFromTextFormat(incorrectFileName, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ TStringInput in{CORRECT_MESSAGE};
+ UNIT_ASSERT(TryMergeFromTextFormat(in, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ TStringInput in{INCORRECT_MESSAGE};
+ UNIT_ASSERT(!TryMergeFromTextFormat(in, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT_NO_EXCEPTION(TryMergeFromTextFormat(incorrectFileName, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT(!TryMergeFromTextFormat("this_file_doesnt_exists", message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT_NO_EXCEPTION(TryMergeFromTextFormat("this_file_doesnt_exists", message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT_EXCEPTION(MergeFromTextFormat("this_file_doesnt_exists", message), TFileError);
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT_NO_EXCEPTION(MergeFromTextFormat(correctFileName, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ UNIT_ASSERT_EXCEPTION(MergeFromTextFormat(incorrectFileName, message), yexception);
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ TStringInput in{CORRECT_MESSAGE};
+ UNIT_ASSERT_NO_EXCEPTION(MergeFromTextFormat(in, message));
+ }
+ {
+ NProtobufUtilUt::TTextTest message;
+ TStringInput in{INCORRECT_MESSAGE};
+ UNIT_ASSERT_EXCEPTION(MergeFromTextFormat(in, message), yexception);
+ }
+ {
+ NProtobufUtilUt::TTextTest m;
+ const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) {
+ mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(correctFileName);
+ };
+ UNIT_ASSERT_NO_EXCEPTION(f(m));
+ UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
+ }
+ {
+ UNIT_ASSERT_EXCEPTION(MergeFromTextFormat<NProtobufUtilUt::TTextTest>(incorrectFileName), yexception);
+ }
+ {
+ NProtobufUtilUt::TTextTest m;
+ TStringInput in{CORRECT_MESSAGE};
+ const auto f = [&in](NProtobufUtilUt::TTextTest& mm) {
+ mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(in);
+ };
+ UNIT_ASSERT_NO_EXCEPTION(f(m));
+ UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
+ }
+ {
+ TStringInput in{INCORRECT_MESSAGE};
+ UNIT_ASSERT_EXCEPTION(MergeFromTextFormat<NProtobufUtilUt::TTextTest>(in), yexception);
+ }
+ {
+ const TFsPath correctFileName2 = TFsPath{tempDir()} / "serialized.pb.txt";
+ const auto original = GetCorrectMessage();
+ UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, correctFileName2));
const auto serializedStr = TUnbufferedFileInput{correctFileName2}.ReadAll();
- UNIT_ASSERT_VALUES_EQUAL(serializedStr, CORRECT_MESSAGE);
- }
- {
- const auto original = GetCorrectMessage();
- TStringStream out;
- UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, out));
- UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_MESSAGE);
- }
- {
- NProtobufUtilUt::TTextTest m;
- const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) {
- mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(
+ UNIT_ASSERT_VALUES_EQUAL(serializedStr, CORRECT_MESSAGE);
+ }
+ {
+ const auto original = GetCorrectMessage();
+ TStringStream out;
+ UNIT_ASSERT_NO_EXCEPTION(SerializeToTextFormat(original, out));
+ UNIT_ASSERT_VALUES_EQUAL(out.Str(), CORRECT_MESSAGE);
+ }
+ {
+ NProtobufUtilUt::TTextTest m;
+ const auto f = [&correctFileName](NProtobufUtilUt::TTextTest& mm) {
+ mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(
correctFileName,
EParseFromTextFormatOption::AllowUnknownField);
- };
- UNIT_ASSERT_NO_EXCEPTION(f(m));
- UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
- }
- {
- const NProtobufUtilUt::TTextTest empty;
- NProtobufUtilUt::TTextTest m;
- const auto f = [&incorrectFileName](NProtobufUtilUt::TTextTest& mm) {
- mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(
+ };
+ UNIT_ASSERT_NO_EXCEPTION(f(m));
+ UNIT_ASSERT(NProtoBuf::IsEqual(GetCorrectMessage(), m));
+ }
+ {
+ const NProtobufUtilUt::TTextTest empty;
+ NProtobufUtilUt::TTextTest m;
+ const auto f = [&incorrectFileName](NProtobufUtilUt::TTextTest& mm) {
+ mm = MergeFromTextFormat<NProtobufUtilUt::TTextTest>(
incorrectFileName,
EParseFromTextFormatOption::AllowUnknownField);
- };
- UNIT_ASSERT_NO_EXCEPTION(f(m));
- UNIT_ASSERT(NProtoBuf::IsEqual(empty, m));
- }
-
- //
- // Test cases for `Merge`
- //
- {
- NProtobufUtilUt::TTextTest message;
- message.SetFoo(100500);
- TStringInput in{CORRECT_MESSAGE};
- UNIT_ASSERT(TryMergeFromTextFormat(in, message));
- UNIT_ASSERT(NProtoBuf::IsEqual(message, GetCorrectMessage()));
- }
- }
+ };
+ UNIT_ASSERT_NO_EXCEPTION(f(m));
+ UNIT_ASSERT(NProtoBuf::IsEqual(empty, m));
+ }
+
+ //
+ // Test cases for `Merge`
+ //
+ {
+ NProtobufUtilUt::TTextTest message;
+ message.SetFoo(100500);
+ TStringInput in{CORRECT_MESSAGE};
+ UNIT_ASSERT(TryMergeFromTextFormat(in, message));
+ UNIT_ASSERT(NProtoBuf::IsEqual(message, GetCorrectMessage()));
+ }
+ }
Y_UNIT_TEST(TestMergeFromString) {
NProtobufUtilUt::TMergeTest message;
@@ -415,4 +415,4 @@ Y_UNIT_TEST_SUITE(TTestProtoBufIO) {
UNIT_ASSERT(NProtoBuf::IsEqual(message, m3));
}
}
-}
+}
diff --git a/library/cpp/protobuf/util/repeated_field_utils_ut.cpp b/library/cpp/protobuf/util/repeated_field_utils_ut.cpp
index 58aaaa9e12..d8944cad04 100644
--- a/library/cpp/protobuf/util/repeated_field_utils_ut.cpp
+++ b/library/cpp/protobuf/util/repeated_field_utils_ut.cpp
@@ -5,8 +5,8 @@
using namespace NProtoBuf;
-Y_UNIT_TEST_SUITE(RepeatedFieldUtils) {
- Y_UNIT_TEST(RemoveIf) {
+Y_UNIT_TEST_SUITE(RepeatedFieldUtils) {
+ Y_UNIT_TEST(RemoveIf) {
{
NProtobufUtilUt::TWalkTest msg;
msg.AddRepInt(0);
diff --git a/library/cpp/protobuf/util/simple_reflection.h b/library/cpp/protobuf/util/simple_reflection.h
index 61e877a787..94723d8155 100644
--- a/library/cpp/protobuf/util/simple_reflection.h
+++ b/library/cpp/protobuf/util/simple_reflection.h
@@ -145,7 +145,7 @@ namespace NProtoBuf {
}
/*
void Swap(TMutableField& f) {
- Y_ASSERT(Field() == f.Field());
+ Y_ASSERT(Field() == f.Field());
// not implemented yet, TODO: implement when Reflection::Mutable(Ptr)RepeatedField
// is ported into arcadia protobuf library from up-stream.
diff --git a/library/cpp/protobuf/util/simple_reflection_ut.cpp b/library/cpp/protobuf/util/simple_reflection_ut.cpp
index 169d4703c9..bd5b32e463 100644
--- a/library/cpp/protobuf/util/simple_reflection_ut.cpp
+++ b/library/cpp/protobuf/util/simple_reflection_ut.cpp
@@ -6,7 +6,7 @@
using namespace NProtoBuf;
-Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) {
+Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) {
static TSample GenSampleForMergeFrom() {
TSample smf;
smf.SetOneStr("one str");
@@ -19,7 +19,7 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) {
return smf;
}
- Y_UNIT_TEST(MergeFromGeneric) {
+ Y_UNIT_TEST(MergeFromGeneric) {
const TSample src(GenSampleForMergeFrom());
TSample dst;
const Descriptor* descr = dst.GetDescriptor();
@@ -51,7 +51,7 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) {
}
}
- Y_UNIT_TEST(MergeFromSelf) {
+ Y_UNIT_TEST(MergeFromSelf) {
const TSample sample(GenSampleForMergeFrom());
TSample msg(sample);
const Descriptor* descr = msg.GetDescriptor();
@@ -65,7 +65,7 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) {
UNIT_ASSERT_VALUES_EQUAL(msg.GetOneMsg().RepIntSize(), sample.GetOneMsg().RepIntSize());
}
- Y_UNIT_TEST(MergeFromAnotherFD) {
+ Y_UNIT_TEST(MergeFromAnotherFD) {
const TSample sample(GenSampleForMergeFrom());
TSample msg(GenSampleForMergeFrom());
const Descriptor* descr = msg.GetDescriptor();
@@ -96,7 +96,7 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) {
}
}
- Y_UNIT_TEST(RemoveByIndex) {
+ Y_UNIT_TEST(RemoveByIndex) {
TSample msg;
const Descriptor* descr = msg.GetDescriptor();
@@ -142,7 +142,7 @@ Y_UNIT_TEST_SUITE(ProtobufSimpleReflection) {
}
}
- Y_UNIT_TEST(GetFieldByPath) {
+ Y_UNIT_TEST(GetFieldByPath) {
// Simple get by path
{
TSample msg;
diff --git a/library/cpp/protobuf/util/ut/common_ut.proto b/library/cpp/protobuf/util/ut/common_ut.proto
index 9cf803ffbf..638f13778c 100644
--- a/library/cpp/protobuf/util/ut/common_ut.proto
+++ b/library/cpp/protobuf/util/ut/common_ut.proto
@@ -58,10 +58,10 @@ message TMergeTest {
repeated TMergeTestMerge NoMergeRepSub = 4 [(DontMergeField)=true];
optional TMergeTestNoMerge NoMergeOptSub = 5;
}
-
-message TTextTest {
- optional uint32 Foo = 1;
-}
+
+message TTextTest {
+ optional uint32 Foo = 1;
+}
message TTextEnumTest {
enum EnumTest {
diff --git a/library/cpp/protobuf/util/ut/ya.make b/library/cpp/protobuf/util/ut/ya.make
index 701ba9a8c8..c358aac35c 100644
--- a/library/cpp/protobuf/util/ut/ya.make
+++ b/library/cpp/protobuf/util/ut/ya.make
@@ -7,7 +7,7 @@ SRCS(
sample_for_is_equal.proto
sample_for_simple_reflection.proto
common_ut.proto
- pb_io_ut.cpp
+ pb_io_ut.cpp
is_equal_ut.cpp
iterators_ut.cpp
simple_reflection_ut.cpp
diff --git a/library/cpp/protobuf/util/walk_ut.cpp b/library/cpp/protobuf/util/walk_ut.cpp
index 2ea6071b17..319e87983e 100644
--- a/library/cpp/protobuf/util/walk_ut.cpp
+++ b/library/cpp/protobuf/util/walk_ut.cpp
@@ -6,7 +6,7 @@
using namespace NProtoBuf;
-Y_UNIT_TEST_SUITE(ProtobufWalk) {
+Y_UNIT_TEST_SUITE(ProtobufWalk) {
static void InitProto(NProtobufUtilUt::TWalkTest & p, int level = 0) {
p.SetOptInt(1);
p.AddRepInt(2);