aboutsummaryrefslogtreecommitdiffstats
path: root/library
diff options
context:
space:
mode:
authorfamilom <familom@yandex-team.ru>2022-02-10 16:49:49 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:49:49 +0300
commitf281aaf77179d27d6208b873e95ae6cd45765a63 (patch)
treeb4229c6ece98c855bd9821ef0b656042c29a8953 /library
parent53d07fb9e28d179add32cd299c9341bf8a231a31 (diff)
downloadydb-f281aaf77179d27d6208b873e95ae6cd45765a63.tar.gz
Restoring authorship annotation for <familom@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library')
-rw-r--r--library/cpp/http/fetch/httpheader.cpp12
-rw-r--r--library/cpp/http/fetch/httpheader.h4
-rw-r--r--library/cpp/http/fetch/ya.make2
-rw-r--r--library/cpp/json/json_reader.cpp14
-rw-r--r--library/cpp/json/json_reader.h6
-rw-r--r--library/cpp/json/json_writer.cpp8
-rw-r--r--library/cpp/json/json_writer.h2
-rw-r--r--library/cpp/json/ut/json_reader_ut.cpp380
-rw-r--r--library/cpp/json/ut/json_writer_ut.cpp70
-rw-r--r--library/cpp/json/writer/json_value.cpp190
-rw-r--r--library/cpp/json/writer/json_value.h8
-rw-r--r--library/cpp/json/writer/json_value_ut.cpp350
-rw-r--r--library/cpp/messagebus/coreconn.cpp6
-rw-r--r--library/cpp/messagebus/coreconn.h2
-rw-r--r--library/cpp/messagebus/locator.cpp2
-rw-r--r--library/cpp/messagebus/rain_check/core/track_ut.cpp2
-rw-r--r--library/cpp/messagebus/rain_check/http/client.cpp50
-rw-r--r--library/cpp/messagebus/rain_check/http/client.h38
-rw-r--r--library/cpp/messagebus/rain_check/http/client_ut.cpp86
-rw-r--r--library/cpp/messagebus/rain_check/http/ya.make22
-rw-r--r--library/cpp/messagebus/rain_check/test/ut/ya.make2
-rw-r--r--library/cpp/protobuf/json/README2
-rw-r--r--library/cpp/protobuf/json/json2proto.cpp142
-rw-r--r--library/cpp/protobuf/json/json2proto.h12
-rw-r--r--library/cpp/protobuf/json/proto2json.cpp30
-rw-r--r--library/cpp/protobuf/json/proto2json.h34
-rw-r--r--library/cpp/protobuf/json/string_transform.cpp14
-rw-r--r--library/cpp/protobuf/json/string_transform.h36
-rw-r--r--library/cpp/protobuf/json/ut/fields.incl38
-rw-r--r--library/cpp/protobuf/json/ut/json.h50
-rw-r--r--library/cpp/protobuf/json/ut/json2proto_ut.cpp84
-rw-r--r--library/cpp/protobuf/json/ut/proto.h32
-rw-r--r--library/cpp/protobuf/json/ut/proto2json_ut.cpp204
-rw-r--r--library/cpp/protobuf/json/ut/repeated_fields.incl34
-rw-r--r--library/cpp/protobuf/json/ut/test.proto176
-rw-r--r--library/cpp/protobuf/json/ut/ya.make16
-rw-r--r--library/cpp/protobuf/json/ya.make26
-rw-r--r--library/cpp/testing/unittest/registar.h2
38 files changed, 1094 insertions, 1094 deletions
diff --git a/library/cpp/http/fetch/httpheader.cpp b/library/cpp/http/fetch/httpheader.cpp
index 7d2225b8b7..a01931d358 100644
--- a/library/cpp/http/fetch/httpheader.cpp
+++ b/library/cpp/http/fetch/httpheader.cpp
@@ -1,7 +1,7 @@
-#include "httpheader.h"
-
+#include "httpheader.h"
+
const i64 DEFAULT_RETRY_AFTER = -1;
-const i64 DEFAULT_IF_MODIFIED_SINCE = -1;
-const i32 DEFAULT_MAX_AGE = -1;
-const i8 DEFAULT_REQUEST_PRIORITY = -1;
-const i32 DEFAULT_RESPONSE_TIMEOUT = -1;
+const i64 DEFAULT_IF_MODIFIED_SINCE = -1;
+const i32 DEFAULT_MAX_AGE = -1;
+const i8 DEFAULT_REQUEST_PRIORITY = -1;
+const i32 DEFAULT_RESPONSE_TIMEOUT = -1;
diff --git a/library/cpp/http/fetch/httpheader.h b/library/cpp/http/fetch/httpheader.h
index b2810bbd41..9207ffc733 100644
--- a/library/cpp/http/fetch/httpheader.h
+++ b/library/cpp/http/fetch/httpheader.h
@@ -4,7 +4,7 @@
#include <library/cpp/mime/types/mime.h>
-#include <util/system/defaults.h>
+#include <util/system/defaults.h>
#include <util/system/compat.h>
#include <util/generic/string.h>
#include <util/generic/ylimits.h>
@@ -20,7 +20,7 @@
#define FETCHER_URL_MAX 8192
extern const i64 DEFAULT_RETRY_AFTER; /// == -1
-extern const i64 DEFAULT_IF_MODIFIED_SINCE; /// == -1
+extern const i64 DEFAULT_IF_MODIFIED_SINCE; /// == -1
extern const i32 DEFAULT_MAX_AGE; /// == -1
extern const i8 DEFAULT_REQUEST_PRIORITY; /// == -1
extern const i32 DEFAULT_RESPONSE_TIMEOUT; /// == -1
diff --git a/library/cpp/http/fetch/ya.make b/library/cpp/http/fetch/ya.make
index 7737127463..4d7a8206f3 100644
--- a/library/cpp/http/fetch/ya.make
+++ b/library/cpp/http/fetch/ya.make
@@ -17,7 +17,7 @@ PEERDIR(
SRCS(
http_digest.cpp
http_socket.cpp
- httpheader.cpp
+ httpheader.cpp
httpload.cpp
exthttpcodes.cpp
httpfsm.rl6
diff --git a/library/cpp/json/json_reader.cpp b/library/cpp/json/json_reader.cpp
index 072c8deafe..03233f90d0 100644
--- a/library/cpp/json/json_reader.cpp
+++ b/library/cpp/json/json_reader.cpp
@@ -1,5 +1,5 @@
-#include "json_reader.h"
-
+#include "json_reader.h"
+
#include "rapidjson_helpers.h"
#include <contrib/libs/rapidjson/include/rapidjson/error/en.h>
@@ -8,7 +8,7 @@
#include <util/generic/stack.h>
#include <util/string/cast.h>
-#include <util/system/yassert.h>
+#include <util/system/yassert.h>
#include <util/string/builder.h>
namespace NJson {
@@ -94,7 +94,7 @@ namespace NJson {
bool TParserCallbacks::OnString(const TStringBuf& val) {
return SetValue(val);
}
-
+
bool TParserCallbacks::OnDouble(double val) {
return SetValue(val);
}
@@ -148,7 +148,7 @@ namespace NJson {
void TJsonReaderConfig::SetBufferSize(size_t bufferSize) {
BufferSize = Max((size_t)1, Min(bufferSize, DEFAULT_BUFFER_LEN));
}
-
+
size_t TJsonReaderConfig::GetBufferSize() const {
return BufferSize;
}
@@ -437,7 +437,7 @@ namespace NJson {
: Impl(impl)
{
}
-
+
bool Null() {
return Impl.OnNull();
}
@@ -445,7 +445,7 @@ namespace NJson {
bool Bool(bool b) {
return Impl.OnBoolean(b);
}
-
+
template <class U>
bool ProcessUint(U u) {
if (Y_LIKELY(u <= ui64(Max<i64>()))) {
diff --git a/library/cpp/json/json_reader.h b/library/cpp/json/json_reader.h
index b673788330..54b9ea2c60 100644
--- a/library/cpp/json/json_reader.h
+++ b/library/cpp/json/json_reader.h
@@ -19,7 +19,7 @@ namespace NJson {
bool AllowComments = false;
bool DontValidateUtf8 = false;
bool AllowEscapedApostrophe = false;
-
+
void SetBufferSize(size_t bufferSize);
size_t GetBufferSize() const;
@@ -30,7 +30,7 @@ namespace NJson {
bool ReadJsonTree(TStringBuf in, TJsonValue* out, bool throwOnError = false);
bool ReadJsonTree(TStringBuf in, bool allowComments, TJsonValue* out, bool throwOnError = false);
bool ReadJsonTree(TStringBuf in, const TJsonReaderConfig* config, TJsonValue* out, bool throwOnError = false);
-
+
bool ReadJsonTree(IInputStream* in, TJsonValue* out, bool throwOnError = false);
bool ReadJsonTree(IInputStream* in, bool allowComments, TJsonValue* out, bool throwOnError = false);
bool ReadJsonTree(IInputStream* in, const TJsonReaderConfig* config, TJsonValue* out, bool throwOnError = false);
@@ -38,7 +38,7 @@ namespace NJson {
TJsonValue ReadJsonTree(IInputStream* in, bool throwOnError = false);
TJsonValue ReadJsonTree(IInputStream* in, bool allowComments, bool throwOnError);
TJsonValue ReadJsonTree(IInputStream* in, const TJsonReaderConfig* config, bool throwOnError = false);
-
+
bool ReadJson(IInputStream* in, TJsonCallbacks* callbacks);
bool ReadJson(IInputStream* in, bool allowComments, TJsonCallbacks* callbacks);
bool ReadJson(IInputStream* in, bool allowComments, bool allowEscapedApostrophe, TJsonCallbacks* callbacks);
diff --git a/library/cpp/json/json_writer.cpp b/library/cpp/json/json_writer.cpp
index 3d058bae36..925e97dbb7 100644
--- a/library/cpp/json/json_writer.cpp
+++ b/library/cpp/json/json_writer.cpp
@@ -45,7 +45,7 @@ namespace NJson {
}
}
}
-
+
void TJsonWriter::Flush() {
if (Out) {
Buf.FlushTo(Out);
@@ -101,7 +101,7 @@ namespace NJson {
void TJsonWriter::Write(unsigned long long value) {
Buf.WriteULongLong(value);
}
-
+
void TJsonWriter::Write(bool value) {
Buf.WriteBool(value);
}
@@ -145,5 +145,5 @@ namespace NJson {
w.Write(val);
w.Flush();
}
-
-}
+
+}
diff --git a/library/cpp/json/json_writer.h b/library/cpp/json/json_writer.h
index c7f5c9499a..9d4c2c2741 100644
--- a/library/cpp/json/json_writer.h
+++ b/library/cpp/json/json_writer.h
@@ -56,7 +56,7 @@ namespace NJson {
const bool ValidateUtf8;
const bool DontEscapeStrings;
const bool DontFlushInDestructor;
-
+
public:
TJsonWriter(IOutputStream* out, bool formatOutput, bool sortkeys = false, bool validateUtf8 = true);
TJsonWriter(IOutputStream* out, const TJsonWriterConfig& config, bool DontFlushInDestructor = false);
diff --git a/library/cpp/json/ut/json_reader_ut.cpp b/library/cpp/json/ut/json_reader_ut.cpp
index cd31afa0b8..c853ec3d56 100644
--- a/library/cpp/json/ut/json_reader_ut.cpp
+++ b/library/cpp/json/ut/json_reader_ut.cpp
@@ -26,10 +26,10 @@ public:
}
bool OnUInteger(unsigned long long val) override {
- Writer.Write(val);
- return true;
- }
-
+ Writer.Write(val);
+ return true;
+ }
+
bool OnString(const TStringBuf& val) override {
Writer.Write(val);
return true;
@@ -135,7 +135,7 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) {
UNIT_ASSERT_VALUES_EQUAL(value["array"][1].GetInteger(), 2);
UNIT_ASSERT_VALUES_EQUAL(value["array"][2].GetInteger(), 3);
UNIT_ASSERT_VALUES_EQUAL(value["array"][3].GetString(), TString("TString"));
- UNIT_ASSERT(value["null value"].IsNull());
+ UNIT_ASSERT(value["null value"].IsNull());
// AsString
UNIT_ASSERT_VALUES_EQUAL(value["intkey"].GetStringRobust(), "10");
@@ -146,12 +146,12 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) {
UNIT_ASSERT_VALUES_EQUAL(value["null value"].GetStringRobust(), "null");
const TJsonValue::TArray* array;
- UNIT_ASSERT(GetArrayPointer(value, "array", &array));
- UNIT_ASSERT_VALUES_EQUAL(value["array"].GetArray().size(), array->size());
- UNIT_ASSERT_VALUES_EQUAL(value["array"][0].GetInteger(), (*array)[0].GetInteger());
+ UNIT_ASSERT(GetArrayPointer(value, "array", &array));
+ UNIT_ASSERT_VALUES_EQUAL(value["array"].GetArray().size(), array->size());
+ UNIT_ASSERT_VALUES_EQUAL(value["array"][0].GetInteger(), (*array)[0].GetInteger());
UNIT_ASSERT_VALUES_EQUAL(value["array"][1].GetInteger(), (*array)[1].GetInteger());
UNIT_ASSERT_VALUES_EQUAL(value["array"][2].GetInteger(), (*array)[2].GetInteger());
- UNIT_ASSERT_VALUES_EQUAL(value["array"][3].GetString(), (*array)[3].GetString());
+ UNIT_ASSERT_VALUES_EQUAL(value["array"][3].GetString(), (*array)[3].GetString());
}
Y_UNIT_TEST(TJsonRomaTest) {
@@ -166,193 +166,193 @@ Y_UNIT_TEST_SUITE(TJsonReaderTest) {
}
Y_UNIT_TEST(TJsonReadTreeWithComments) {
- {
+ {
TString leadingCommentData = "{ // \"test\" : 1 \n}";
- {
- // No comments allowed
- TStringStream in;
- in << leadingCommentData;
- TJsonValue value;
- UNIT_ASSERT(!ReadJsonTree(&in, false, &value));
- }
-
- {
- // Comments allowed
- TStringStream in;
- in << leadingCommentData;
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, true, &value));
- UNIT_ASSERT(!value.Has("test"));
- }
- }
-
- {
+ {
+ // No comments allowed
+ TStringStream in;
+ in << leadingCommentData;
+ TJsonValue value;
+ UNIT_ASSERT(!ReadJsonTree(&in, false, &value));
+ }
+
+ {
+ // Comments allowed
+ TStringStream in;
+ in << leadingCommentData;
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, true, &value));
+ UNIT_ASSERT(!value.Has("test"));
+ }
+ }
+
+ {
TString trailingCommentData = "{ \"test1\" : 1 // \"test2\" : 2 \n }";
- {
- // No comments allowed
- TStringStream in;
- in << trailingCommentData;
- TJsonValue value;
- UNIT_ASSERT(!ReadJsonTree(&in, false, &value));
- }
-
- {
- // Comments allowed
- TStringStream in;
- in << trailingCommentData;
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, true, &value));
- UNIT_ASSERT(value.Has("test1"));
- UNIT_ASSERT_EQUAL(value["test1"].GetInteger(), 1);
- UNIT_ASSERT(!value.Has("test2"));
- }
- }
- }
-
+ {
+ // No comments allowed
+ TStringStream in;
+ in << trailingCommentData;
+ TJsonValue value;
+ UNIT_ASSERT(!ReadJsonTree(&in, false, &value));
+ }
+
+ {
+ // Comments allowed
+ TStringStream in;
+ in << trailingCommentData;
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, true, &value));
+ UNIT_ASSERT(value.Has("test1"));
+ UNIT_ASSERT_EQUAL(value["test1"].GetInteger(), 1);
+ UNIT_ASSERT(!value.Has("test2"));
+ }
+ }
+ }
+
Y_UNIT_TEST(TJsonSignedIntegerTest) {
- {
- TStringStream in;
- in << "{ \"test\" : " << Min<i64>() << " }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(value["test"].IsInteger());
- UNIT_ASSERT(!value["test"].IsUInteger());
- UNIT_ASSERT_EQUAL(value["test"].GetInteger(), Min<i64>());
- UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), Min<i64>());
- } // Min<i64>()
-
- {
- TStringStream in;
- in << "{ \"test\" : " << Max<i64>() + 1ull << " }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(!value["test"].IsInteger());
- UNIT_ASSERT(value["test"].IsUInteger());
+ {
+ TStringStream in;
+ in << "{ \"test\" : " << Min<i64>() << " }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(value["test"].IsInteger());
+ UNIT_ASSERT(!value["test"].IsUInteger());
+ UNIT_ASSERT_EQUAL(value["test"].GetInteger(), Min<i64>());
+ UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), Min<i64>());
+ } // Min<i64>()
+
+ {
+ TStringStream in;
+ in << "{ \"test\" : " << Max<i64>() + 1ull << " }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(!value["test"].IsInteger());
+ UNIT_ASSERT(value["test"].IsUInteger());
UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), (i64)(Max<i64>() + 1ull));
- } // Max<i64>() + 1
- }
-
+ } // Max<i64>() + 1
+ }
+
Y_UNIT_TEST(TJsonUnsignedIntegerTest) {
- {
- TStringStream in;
- in << "{ \"test\" : 1 }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(value["test"].IsInteger());
- UNIT_ASSERT(value["test"].IsUInteger());
- UNIT_ASSERT_EQUAL(value["test"].GetInteger(), 1);
- UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), 1);
- UNIT_ASSERT_EQUAL(value["test"].GetUInteger(), 1);
- UNIT_ASSERT_EQUAL(value["test"].GetUIntegerRobust(), 1);
- } // 1
-
- {
- TStringStream in;
- in << "{ \"test\" : -1 }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(value["test"].IsInteger());
- UNIT_ASSERT(!value["test"].IsUInteger());
- UNIT_ASSERT_EQUAL(value["test"].GetInteger(), -1);
- UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), -1);
- UNIT_ASSERT_EQUAL(value["test"].GetUInteger(), 0);
- UNIT_ASSERT_EQUAL(value["test"].GetUIntegerRobust(), static_cast<unsigned long long>(-1));
- } // -1
-
- {
- TStringStream in;
- in << "{ \"test\" : 18446744073709551615 }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(!value["test"].IsInteger());
- UNIT_ASSERT(value["test"].IsUInteger());
- UNIT_ASSERT_EQUAL(value["test"].GetInteger(), 0);
- UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), static_cast<long long>(18446744073709551615ull));
- UNIT_ASSERT_EQUAL(value["test"].GetUInteger(), 18446744073709551615ull);
- UNIT_ASSERT_EQUAL(value["test"].GetUIntegerRobust(), 18446744073709551615ull);
- } // 18446744073709551615
-
- {
- TStringStream in;
- in << "{ \"test\" : 1.1 }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(!value["test"].IsInteger());
- UNIT_ASSERT(!value["test"].IsUInteger());
- UNIT_ASSERT_EQUAL(value["test"].GetInteger(), 0);
- UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), static_cast<long long>(1.1));
- UNIT_ASSERT_EQUAL(value["test"].GetUInteger(), 0);
- UNIT_ASSERT_EQUAL(value["test"].GetUIntegerRobust(), static_cast<unsigned long long>(1.1));
- } // 1.1
-
- {
- TStringStream in;
- in << "{ \"test\" : [1, 18446744073709551615] }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(value["test"].IsArray());
- UNIT_ASSERT_EQUAL(value["test"].GetArray().size(), 2);
- UNIT_ASSERT(value["test"][0].IsInteger());
- UNIT_ASSERT(value["test"][0].IsUInteger());
- UNIT_ASSERT_EQUAL(value["test"][0].GetInteger(), 1);
- UNIT_ASSERT_EQUAL(value["test"][0].GetUInteger(), 1);
- UNIT_ASSERT(!value["test"][1].IsInteger());
- UNIT_ASSERT(value["test"][1].IsUInteger());
- UNIT_ASSERT_EQUAL(value["test"][1].GetUInteger(), 18446744073709551615ull);
- }
- } // TJsonUnsignedIntegerTest
-
+ {
+ TStringStream in;
+ in << "{ \"test\" : 1 }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(value["test"].IsInteger());
+ UNIT_ASSERT(value["test"].IsUInteger());
+ UNIT_ASSERT_EQUAL(value["test"].GetInteger(), 1);
+ UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), 1);
+ UNIT_ASSERT_EQUAL(value["test"].GetUInteger(), 1);
+ UNIT_ASSERT_EQUAL(value["test"].GetUIntegerRobust(), 1);
+ } // 1
+
+ {
+ TStringStream in;
+ in << "{ \"test\" : -1 }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(value["test"].IsInteger());
+ UNIT_ASSERT(!value["test"].IsUInteger());
+ UNIT_ASSERT_EQUAL(value["test"].GetInteger(), -1);
+ UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), -1);
+ UNIT_ASSERT_EQUAL(value["test"].GetUInteger(), 0);
+ UNIT_ASSERT_EQUAL(value["test"].GetUIntegerRobust(), static_cast<unsigned long long>(-1));
+ } // -1
+
+ {
+ TStringStream in;
+ in << "{ \"test\" : 18446744073709551615 }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(!value["test"].IsInteger());
+ UNIT_ASSERT(value["test"].IsUInteger());
+ UNIT_ASSERT_EQUAL(value["test"].GetInteger(), 0);
+ UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), static_cast<long long>(18446744073709551615ull));
+ UNIT_ASSERT_EQUAL(value["test"].GetUInteger(), 18446744073709551615ull);
+ UNIT_ASSERT_EQUAL(value["test"].GetUIntegerRobust(), 18446744073709551615ull);
+ } // 18446744073709551615
+
+ {
+ TStringStream in;
+ in << "{ \"test\" : 1.1 }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(!value["test"].IsInteger());
+ UNIT_ASSERT(!value["test"].IsUInteger());
+ UNIT_ASSERT_EQUAL(value["test"].GetInteger(), 0);
+ UNIT_ASSERT_EQUAL(value["test"].GetIntegerRobust(), static_cast<long long>(1.1));
+ UNIT_ASSERT_EQUAL(value["test"].GetUInteger(), 0);
+ UNIT_ASSERT_EQUAL(value["test"].GetUIntegerRobust(), static_cast<unsigned long long>(1.1));
+ } // 1.1
+
+ {
+ TStringStream in;
+ in << "{ \"test\" : [1, 18446744073709551615] }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(value["test"].IsArray());
+ UNIT_ASSERT_EQUAL(value["test"].GetArray().size(), 2);
+ UNIT_ASSERT(value["test"][0].IsInteger());
+ UNIT_ASSERT(value["test"][0].IsUInteger());
+ UNIT_ASSERT_EQUAL(value["test"][0].GetInteger(), 1);
+ UNIT_ASSERT_EQUAL(value["test"][0].GetUInteger(), 1);
+ UNIT_ASSERT(!value["test"][1].IsInteger());
+ UNIT_ASSERT(value["test"][1].IsUInteger());
+ UNIT_ASSERT_EQUAL(value["test"][1].GetUInteger(), 18446744073709551615ull);
+ }
+ } // TJsonUnsignedIntegerTest
+
Y_UNIT_TEST(TJsonDoubleTest) {
- {
- TStringStream in;
- in << "{ \"test\" : 1.0 }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(value["test"].IsDouble());
- UNIT_ASSERT_EQUAL(value["test"].GetDouble(), 1.0);
- UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), 1.0);
- } // 1.0
-
- {
- TStringStream in;
- in << "{ \"test\" : 1 }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(value["test"].IsDouble());
- UNIT_ASSERT_EQUAL(value["test"].GetDouble(), 1.0);
- UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), 1.0);
- } // 1
-
- {
- TStringStream in;
- in << "{ \"test\" : -1 }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(value["test"].IsDouble());
- UNIT_ASSERT_EQUAL(value["test"].GetDouble(), -1.0);
- UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), -1.0);
- } // -1
-
- {
- TStringStream in;
- in << "{ \"test\" : " << Max<ui64>() << " }";
- TJsonValue value;
- UNIT_ASSERT(ReadJsonTree(&in, &value));
- UNIT_ASSERT(value.Has("test"));
- UNIT_ASSERT(!value["test"].IsDouble());
- UNIT_ASSERT_EQUAL(value["test"].GetDouble(), 0.0);
- UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), static_cast<double>(Max<ui64>()));
- } // Max<ui64>()
+ {
+ TStringStream in;
+ in << "{ \"test\" : 1.0 }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(value["test"].IsDouble());
+ UNIT_ASSERT_EQUAL(value["test"].GetDouble(), 1.0);
+ UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), 1.0);
+ } // 1.0
+
+ {
+ TStringStream in;
+ in << "{ \"test\" : 1 }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(value["test"].IsDouble());
+ UNIT_ASSERT_EQUAL(value["test"].GetDouble(), 1.0);
+ UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), 1.0);
+ } // 1
+
+ {
+ TStringStream in;
+ in << "{ \"test\" : -1 }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(value["test"].IsDouble());
+ UNIT_ASSERT_EQUAL(value["test"].GetDouble(), -1.0);
+ UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), -1.0);
+ } // -1
+
+ {
+ TStringStream in;
+ in << "{ \"test\" : " << Max<ui64>() << " }";
+ TJsonValue value;
+ UNIT_ASSERT(ReadJsonTree(&in, &value));
+ UNIT_ASSERT(value.Has("test"));
+ UNIT_ASSERT(!value["test"].IsDouble());
+ UNIT_ASSERT_EQUAL(value["test"].GetDouble(), 0.0);
+ UNIT_ASSERT_EQUAL(value["test"].GetDoubleRobust(), static_cast<double>(Max<ui64>()));
+ } // Max<ui64>()
} // TJsonDoubleTest
Y_UNIT_TEST(TJsonInvalidTest) {
diff --git a/library/cpp/json/ut/json_writer_ut.cpp b/library/cpp/json/ut/json_writer_ut.cpp
index ca11d34dad..f9f44ed34e 100644
--- a/library/cpp/json/ut/json_writer_ut.cpp
+++ b/library/cpp/json/ut/json_writer_ut.cpp
@@ -54,7 +54,7 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) {
WriteJson(&out, &v);
UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
}
-
+
Y_UNIT_TEST(FormatOutput) {
TString expected = "{\n \"key1\":null,\n \"key2\":\n {\n \"subkey1\":\n [\n 1,\n {\n \"subsubkey\":\"test2\"\n },\n null,\n true\n ],\n \"subkey2\":\"test\"\n }\n}";
TJsonValue v;
@@ -83,45 +83,45 @@ Y_UNIT_TEST_SUITE(TJsonWriterTest) {
}
Y_UNIT_TEST(SimpleUnsignedIntegerWriteTest) {
- {
+ {
TString expected = "{\"test\":1}";
- TJsonValue v;
- v.InsertValue("test", 1ull);
- TStringStream out;
- WriteJson(&out, &v);
- UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
- } // 1
-
- {
+ TJsonValue v;
+ v.InsertValue("test", 1ull);
+ TStringStream out;
+ WriteJson(&out, &v);
+ UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
+ } // 1
+
+ {
TString expected = "{\"test\":-1}";
- TJsonValue v;
- v.InsertValue("test", -1);
- TStringStream out;
- WriteJson(&out, &v);
- UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
- } // -1
-
- {
+ TJsonValue v;
+ v.InsertValue("test", -1);
+ TStringStream out;
+ WriteJson(&out, &v);
+ UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
+ } // -1
+
+ {
TString expected = "{\"test\":18446744073709551615}";
- TJsonValue v;
- v.InsertValue("test", 18446744073709551615ull);
- TStringStream out;
- WriteJson(&out, &v);
- UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
- } // 18446744073709551615
-
- {
+ TJsonValue v;
+ v.InsertValue("test", 18446744073709551615ull);
+ TStringStream out;
+ WriteJson(&out, &v);
+ UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
+ } // 18446744073709551615
+
+ {
TString expected = "{\"test\":[1,18446744073709551615]}";
- TJsonValue v;
- v.InsertValue("test", TJsonValue());
- v["test"].AppendValue(1);
- v["test"].AppendValue(18446744073709551615ull);
- TStringStream out;
- WriteJson(&out, &v);
- UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
- } // 18446744073709551615
+ TJsonValue v;
+ v.InsertValue("test", TJsonValue());
+ v["test"].AppendValue(1);
+ v["test"].AppendValue(18446744073709551615ull);
+ TStringStream out;
+ WriteJson(&out, &v);
+ UNIT_ASSERT_VALUES_EQUAL(out.Str(), expected);
+ } // 18446744073709551615
} // SimpleUnsignedIntegerWriteTest
-
+
Y_UNIT_TEST(WriteOptionalTest) {
{
TString expected = "{\"test\":1}";
diff --git a/library/cpp/json/writer/json_value.cpp b/library/cpp/json/writer/json_value.cpp
index c61e8d1dc4..3e7ab2915e 100644
--- a/library/cpp/json/writer/json_value.cpp
+++ b/library/cpp/json/writer/json_value.cpp
@@ -2,7 +2,7 @@
#include "json.h"
#include <util/generic/ymath.h>
-#include <util/generic/ylimits.h>
+#include <util/generic/ylimits.h>
#include <util/generic/utility.h>
#include <util/generic/singleton.h>
#include <util/stream/str.h>
@@ -10,63 +10,63 @@
#include <util/string/cast.h>
#include <util/string/type.h>
#include <util/string/vector.h>
-#include <util/system/yassert.h>
+#include <util/system/yassert.h>
#include <util/ysaveload.h>
#include <util/generic/bt_exception.h>
-static bool
-AreJsonMapsEqual(const NJson::TJsonValue& lhs, const NJson::TJsonValue& rhs) {
- using namespace NJson;
-
+static bool
+AreJsonMapsEqual(const NJson::TJsonValue& lhs, const NJson::TJsonValue& rhs) {
+ using namespace NJson;
+
Y_VERIFY(lhs.GetType() == JSON_MAP, "lhs has not a JSON_MAP type.");
-
- if (rhs.GetType() != JSON_MAP)
- return false;
-
+
+ if (rhs.GetType() != JSON_MAP)
+ return false;
+
typedef TJsonValue::TMapType TMapType;
const TMapType& lhsMap = lhs.GetMap();
const TMapType& rhsMap = rhs.GetMap();
-
- if (lhsMap.size() != rhsMap.size())
- return false;
-
+
+ if (lhsMap.size() != rhsMap.size())
+ return false;
+
for (const auto& lhsIt : lhsMap) {
TMapType::const_iterator rhsIt = rhsMap.find(lhsIt.first);
- if (rhsIt == rhsMap.end())
- return false;
-
+ if (rhsIt == rhsMap.end())
+ return false;
+
if (lhsIt.second != rhsIt->second)
- return false;
- }
-
- return true;
-}
-
-static bool
-AreJsonArraysEqual(const NJson::TJsonValue& lhs, const NJson::TJsonValue& rhs) {
- using namespace NJson;
-
+ return false;
+ }
+
+ return true;
+}
+
+static bool
+AreJsonArraysEqual(const NJson::TJsonValue& lhs, const NJson::TJsonValue& rhs) {
+ using namespace NJson;
+
Y_VERIFY(lhs.GetType() == JSON_ARRAY, "lhs has not a JSON_ARRAY type.");
-
- if (rhs.GetType() != JSON_ARRAY)
- return false;
-
- typedef TJsonValue::TArray TArray;
- const TArray& lhsArray = lhs.GetArray();
- const TArray& rhsArray = rhs.GetArray();
-
- if (lhsArray.size() != rhsArray.size())
- return false;
-
- for (TArray::const_iterator lhsIt = lhsArray.begin(), rhsIt = rhsArray.begin();
+
+ if (rhs.GetType() != JSON_ARRAY)
+ return false;
+
+ typedef TJsonValue::TArray TArray;
+ const TArray& lhsArray = lhs.GetArray();
+ const TArray& rhsArray = rhs.GetArray();
+
+ if (lhsArray.size() != rhsArray.size())
+ return false;
+
+ for (TArray::const_iterator lhsIt = lhsArray.begin(), rhsIt = rhsArray.begin();
lhsIt != lhsArray.end(); ++lhsIt, ++rhsIt) {
- if (*lhsIt != *rhsIt)
- return false;
- }
-
- return true;
-}
-
+ if (*lhsIt != *rhsIt)
+ return false;
+ }
+
+ return true;
+}
+
namespace NJson {
const TJsonValue TJsonValue::UNDEFINED{};
@@ -135,7 +135,7 @@ namespace NJson {
SetType(JSON_UINTEGER);
Value.UInteger = value;
}
-
+
TJsonValue::TJsonValue(const int value) noexcept {
SetType(JSON_INTEGER);
Value.Integer = value;
@@ -145,7 +145,7 @@ namespace NJson {
SetType(JSON_UINTEGER);
Value.UInteger = value;
}
-
+
TJsonValue::TJsonValue(const long value) noexcept {
SetType(JSON_INTEGER);
Value.Integer = value;
@@ -155,7 +155,7 @@ namespace NJson {
SetType(JSON_UINTEGER);
Value.UInteger = value;
}
-
+
TJsonValue::TJsonValue(const double value) noexcept {
SetType(JSON_DOUBLE);
Value.Double = value;
@@ -362,55 +362,55 @@ namespace NJson {
case JSON_UINTEGER:
return Value.UInteger;
-
+
case JSON_DOUBLE:
return Value.Double;
-
+
default:
Y_ASSERT(false && "Unexpected type.");
return 0;
}
- }
+ }
unsigned long long TJsonValue::GetUInteger() const {
if (!IsUInteger())
return 0;
-
+
switch (Type) {
case JSON_UINTEGER:
return Value.UInteger;
-
+
case JSON_INTEGER:
return Value.Integer;
-
+
case JSON_DOUBLE:
return Value.Double;
-
+
default:
Y_ASSERT(false && "Unexpected type.");
return 0;
}
- }
-
+ }
+
double TJsonValue::GetDouble() const {
if (!IsDouble())
return 0.0;
-
+
switch (Type) {
case JSON_DOUBLE:
return Value.Double;
-
+
case JSON_INTEGER:
return Value.Integer;
-
+
case JSON_UINTEGER:
return Value.UInteger;
-
+
default:
Y_ASSERT(false && "Unexpected type.");
return 0.0;
}
- }
+ }
const TString& TJsonValue::GetString() const {
return Type != JSON_STRING ? Singleton<TDefaultsHolder>()->String : Value.String;
@@ -593,8 +593,8 @@ namespace NJson {
case JSON_UINTEGER:
return Value.UInteger;
}
- }
-
+ }
+
double TJsonValue::GetDoubleRobust() const noexcept {
switch (Type) {
case JSON_ARRAY:
@@ -664,11 +664,11 @@ namespace NJson {
bool TJsonValue::GetUInteger(unsigned long long* value) const noexcept {
if (!IsUInteger())
return false;
-
+
*value = GetUInteger();
return true;
}
-
+
bool TJsonValue::GetDouble(double* value) const noexcept {
if (!IsDouble())
return false;
@@ -765,56 +765,56 @@ namespace NJson {
bool TJsonValue::IsBoolean() const noexcept {
return Type == JSON_BOOLEAN;
}
-
+
bool TJsonValue::IsInteger() const noexcept {
switch (Type) {
case JSON_INTEGER:
return true;
-
+
case JSON_UINTEGER:
return (Value.UInteger <= static_cast<unsigned long long>(Max<long long>()));
-
+
case JSON_DOUBLE:
return ((long long)Value.Double == Value.Double);
default:
return false;
}
- }
+ }
bool TJsonValue::IsUInteger() const noexcept {
switch (Type) {
case JSON_UINTEGER:
return true;
-
+
case JSON_INTEGER:
return (Value.Integer >= 0);
-
+
case JSON_DOUBLE:
return ((unsigned long long)Value.Double == Value.Double);
-
+
default:
return false;
}
- }
-
+ }
+
bool TJsonValue::IsDouble() const noexcept {
// Check whether we can convert integer to floating-point
// without precision loss.
switch (Type) {
case JSON_DOUBLE:
return true;
-
+
case JSON_INTEGER:
return (1ll << std::numeric_limits<double>::digits) >= Abs(Value.Integer);
-
+
case JSON_UINTEGER:
return (1ull << std::numeric_limits<double>::digits) >= Value.UInteger;
-
+
default:
return false;
}
- }
+ }
namespace {
template <class TPtr, class T>
@@ -906,42 +906,42 @@ namespace NJson {
void TJsonValue::Scan(IScanCallback& callback) {
DoScan("", nullptr, callback);
- }
-
+ }
+
bool TJsonValue::IsString() const noexcept {
return Type == JSON_STRING;
- }
-
+ }
+
bool TJsonValue::IsMap() const noexcept {
return Type == JSON_MAP;
- }
-
+ }
+
bool TJsonValue::IsArray() const noexcept {
return Type == JSON_ARRAY;
- }
-
+ }
+
bool TJsonValue::Has(const TStringBuf& key) const noexcept {
return Type == JSON_MAP && Value.Map->contains(key);
- }
-
+ }
+
bool TJsonValue::Has(size_t key) const noexcept {
return Type == JSON_ARRAY && Value.Array->size() > key;
- }
-
+ }
+
bool TJsonValue::operator==(const TJsonValue& rhs) const {
switch (Type) {
case JSON_UNDEFINED: {
return (rhs.GetType() == JSON_UNDEFINED);
}
-
+
case JSON_NULL: {
return rhs.IsNull();
}
-
+
case JSON_BOOLEAN: {
return (rhs.IsBoolean() && Value.Boolean == rhs.Value.Boolean);
}
-
+
case JSON_INTEGER: {
return (rhs.IsInteger() && GetInteger() == rhs.GetInteger());
}
diff --git a/library/cpp/json/writer/json_value.h b/library/cpp/json/writer/json_value.h
index 3f0f50bc4c..d777d07062 100644
--- a/library/cpp/json/writer/json_value.h
+++ b/library/cpp/json/writer/json_value.h
@@ -170,10 +170,10 @@ namespace NJson {
/// @return true if JSON_UINTEGER or (JSON_INTEGER and Value >= 0)
bool IsUInteger() const noexcept;
-
+
bool Has(const TStringBuf& key) const noexcept;
bool Has(size_t key) const noexcept;
-
+
void Scan(IScanCallback& callback);
/// Non-robust comparison.
@@ -182,9 +182,9 @@ namespace NJson {
bool operator!=(const TJsonValue& rhs) const {
return !(*this == rhs);
}
-
+
void Swap(TJsonValue& rhs) noexcept;
-
+
// save using util/ysaveload.h serialization (not to JSON stream)
void Save(IOutputStream* s) const;
diff --git a/library/cpp/json/writer/json_value_ut.cpp b/library/cpp/json/writer/json_value_ut.cpp
index dc7f6affdf..7cb1003a75 100644
--- a/library/cpp/json/writer/json_value_ut.cpp
+++ b/library/cpp/json/writer/json_value_ut.cpp
@@ -1,11 +1,11 @@
-#include "json_value.h"
-
+#include "json_value.h"
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/stream/input.h>
-
-using namespace NJson;
-
+
+#include <util/stream/input.h>
+
+using namespace NJson;
+
Y_UNIT_TEST_SUITE(TJsonValueTest) {
Y_UNIT_TEST(UndefTest) {
TJsonValue undef;
@@ -37,177 +37,177 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
}
Y_UNIT_TEST(DefaultCompareTest) {
- {
- TJsonValue lhs;
- TJsonValue rhs;
- UNIT_ASSERT(lhs == rhs);
- UNIT_ASSERT(rhs == lhs);
- }
-
- {
- TJsonValue lhs;
- TJsonValue rhs(JSON_NULL);
- UNIT_ASSERT(lhs != rhs);
- UNIT_ASSERT(rhs != lhs);
- }
- }
-
+ {
+ TJsonValue lhs;
+ TJsonValue rhs;
+ UNIT_ASSERT(lhs == rhs);
+ UNIT_ASSERT(rhs == lhs);
+ }
+
+ {
+ TJsonValue lhs;
+ TJsonValue rhs(JSON_NULL);
+ UNIT_ASSERT(lhs != rhs);
+ UNIT_ASSERT(rhs != lhs);
+ }
+ }
+
Y_UNIT_TEST(NullCompareTest) {
- TJsonValue lhs(JSON_NULL);
- TJsonValue rhs(JSON_NULL);
- UNIT_ASSERT(lhs == rhs);
- UNIT_ASSERT(rhs == lhs);
- }
-
+ TJsonValue lhs(JSON_NULL);
+ TJsonValue rhs(JSON_NULL);
+ UNIT_ASSERT(lhs == rhs);
+ UNIT_ASSERT(rhs == lhs);
+ }
+
Y_UNIT_TEST(StringCompareTest) {
- {
- TJsonValue lhs(JSON_STRING);
- TJsonValue rhs(JSON_STRING);
- UNIT_ASSERT(lhs == rhs);
- UNIT_ASSERT(rhs == lhs);
- }
-
- {
- TJsonValue lhs("");
- TJsonValue rhs("");
- UNIT_ASSERT(lhs == rhs);
- UNIT_ASSERT(rhs == lhs);
- }
-
- {
- TJsonValue lhs("abc");
- TJsonValue rhs("abc");
- UNIT_ASSERT(lhs == rhs);
- UNIT_ASSERT(rhs == lhs);
- }
-
- {
- TJsonValue lhs("1");
- TJsonValue rhs(1);
- UNIT_ASSERT(lhs != rhs);
- UNIT_ASSERT(rhs != lhs);
- }
- }
-
+ {
+ TJsonValue lhs(JSON_STRING);
+ TJsonValue rhs(JSON_STRING);
+ UNIT_ASSERT(lhs == rhs);
+ UNIT_ASSERT(rhs == lhs);
+ }
+
+ {
+ TJsonValue lhs("");
+ TJsonValue rhs("");
+ UNIT_ASSERT(lhs == rhs);
+ UNIT_ASSERT(rhs == lhs);
+ }
+
+ {
+ TJsonValue lhs("abc");
+ TJsonValue rhs("abc");
+ UNIT_ASSERT(lhs == rhs);
+ UNIT_ASSERT(rhs == lhs);
+ }
+
+ {
+ TJsonValue lhs("1");
+ TJsonValue rhs(1);
+ UNIT_ASSERT(lhs != rhs);
+ UNIT_ASSERT(rhs != lhs);
+ }
+ }
+
Y_UNIT_TEST(ArrayCompareTest) {
- {
- TJsonValue lhs(JSON_ARRAY);
- TJsonValue rhs(JSON_ARRAY);
- UNIT_ASSERT(lhs == rhs);
- UNIT_ASSERT(rhs == lhs);
- }
-
- {
- TJsonValue lhs;
- TJsonValue rhs;
-
- lhs.AppendValue(TJsonValue());
-
- UNIT_ASSERT(lhs != rhs);
- UNIT_ASSERT(rhs != lhs);
- }
-
- {
- TJsonValue lhs;
- TJsonValue rhs;
-
- lhs.AppendValue(1);
- lhs.AppendValue("2");
- lhs.AppendValue(3.0);
- lhs.AppendValue(TJsonValue());
- lhs.AppendValue(TJsonValue(JSON_NULL));
-
- rhs.AppendValue(1);
- rhs.AppendValue("2");
- rhs.AppendValue(3.0);
- rhs.AppendValue(TJsonValue());
- rhs.AppendValue(TJsonValue(JSON_NULL));
-
- UNIT_ASSERT(lhs == rhs);
- UNIT_ASSERT(rhs == lhs);
- }
-
- {
- TJsonValue lhs;
- TJsonValue rhs;
-
- lhs.AppendValue(1);
- rhs.AppendValue("1");
-
- UNIT_ASSERT(lhs != rhs);
- UNIT_ASSERT(rhs != lhs);
- }
- }
-
+ {
+ TJsonValue lhs(JSON_ARRAY);
+ TJsonValue rhs(JSON_ARRAY);
+ UNIT_ASSERT(lhs == rhs);
+ UNIT_ASSERT(rhs == lhs);
+ }
+
+ {
+ TJsonValue lhs;
+ TJsonValue rhs;
+
+ lhs.AppendValue(TJsonValue());
+
+ UNIT_ASSERT(lhs != rhs);
+ UNIT_ASSERT(rhs != lhs);
+ }
+
+ {
+ TJsonValue lhs;
+ TJsonValue rhs;
+
+ lhs.AppendValue(1);
+ lhs.AppendValue("2");
+ lhs.AppendValue(3.0);
+ lhs.AppendValue(TJsonValue());
+ lhs.AppendValue(TJsonValue(JSON_NULL));
+
+ rhs.AppendValue(1);
+ rhs.AppendValue("2");
+ rhs.AppendValue(3.0);
+ rhs.AppendValue(TJsonValue());
+ rhs.AppendValue(TJsonValue(JSON_NULL));
+
+ UNIT_ASSERT(lhs == rhs);
+ UNIT_ASSERT(rhs == lhs);
+ }
+
+ {
+ TJsonValue lhs;
+ TJsonValue rhs;
+
+ lhs.AppendValue(1);
+ rhs.AppendValue("1");
+
+ UNIT_ASSERT(lhs != rhs);
+ UNIT_ASSERT(rhs != lhs);
+ }
+ }
+
Y_UNIT_TEST(CompareTest) {
- {
- TJsonValue lhs;
- lhs.InsertValue("null value", TJsonValue(JSON_NULL));
- lhs.InsertValue("int key", TJsonValue(10));
- lhs.InsertValue("double key", TJsonValue(11.11));
- lhs.InsertValue("string key", TJsonValue("string"));
-
- TJsonValue array;
- array.AppendValue(1);
- array.AppendValue(2);
- array.AppendValue(3);
- array.AppendValue("string");
- lhs.InsertValue("array", array);
-
- lhs.InsertValue("bool key", TJsonValue(true));
-
- TJsonValue rhs;
- rhs = lhs;
-
- UNIT_ASSERT(lhs == rhs);
- UNIT_ASSERT(rhs == lhs);
- }
-
- {
- // Insert keys in different orders
- const int NUM_KEYS = 1000;
-
- TJsonValue lhs;
- for (int i = 0; i < NUM_KEYS; ++i)
- lhs.InsertValue(ToString(i), i);
-
- TJsonValue rhs;
- for (int i = 0; i < NUM_KEYS; i += 2)
- rhs.InsertValue(ToString(i), i);
- for (int i = 1; i < NUM_KEYS; i += 2)
- rhs.InsertValue(ToString(i), i);
-
- UNIT_ASSERT(lhs == rhs);
- UNIT_ASSERT(rhs == lhs);
- }
-
- {
- TJsonValue lhs;
- lhs.InsertValue("null value", TJsonValue(JSON_NULL));
- lhs.InsertValue("int key", TJsonValue(10));
- lhs.InsertValue("double key", TJsonValue(11.11));
- lhs.InsertValue("string key", TJsonValue("string"));
-
- TJsonValue array;
- array.AppendValue(1);
- array.AppendValue(2);
- array.AppendValue(3);
- array.AppendValue("string");
- lhs.InsertValue("array", array);
-
- lhs.InsertValue("bool key", TJsonValue(true));
-
- TJsonValue rhs;
- rhs.InsertValue("null value", TJsonValue(JSON_NULL));
- rhs.InsertValue("int key", TJsonValue(10));
- rhs.InsertValue("double key", TJsonValue(11.11));
- rhs.InsertValue("string key", TJsonValue("string"));
- rhs.InsertValue("bool key", TJsonValue(true));
-
- UNIT_ASSERT(lhs != rhs);
- UNIT_ASSERT(rhs != lhs);
- }
- }
+ {
+ TJsonValue lhs;
+ lhs.InsertValue("null value", TJsonValue(JSON_NULL));
+ lhs.InsertValue("int key", TJsonValue(10));
+ lhs.InsertValue("double key", TJsonValue(11.11));
+ lhs.InsertValue("string key", TJsonValue("string"));
+
+ TJsonValue array;
+ array.AppendValue(1);
+ array.AppendValue(2);
+ array.AppendValue(3);
+ array.AppendValue("string");
+ lhs.InsertValue("array", array);
+
+ lhs.InsertValue("bool key", TJsonValue(true));
+
+ TJsonValue rhs;
+ rhs = lhs;
+
+ UNIT_ASSERT(lhs == rhs);
+ UNIT_ASSERT(rhs == lhs);
+ }
+
+ {
+ // Insert keys in different orders
+ const int NUM_KEYS = 1000;
+
+ TJsonValue lhs;
+ for (int i = 0; i < NUM_KEYS; ++i)
+ lhs.InsertValue(ToString(i), i);
+
+ TJsonValue rhs;
+ for (int i = 0; i < NUM_KEYS; i += 2)
+ rhs.InsertValue(ToString(i), i);
+ for (int i = 1; i < NUM_KEYS; i += 2)
+ rhs.InsertValue(ToString(i), i);
+
+ UNIT_ASSERT(lhs == rhs);
+ UNIT_ASSERT(rhs == lhs);
+ }
+
+ {
+ TJsonValue lhs;
+ lhs.InsertValue("null value", TJsonValue(JSON_NULL));
+ lhs.InsertValue("int key", TJsonValue(10));
+ lhs.InsertValue("double key", TJsonValue(11.11));
+ lhs.InsertValue("string key", TJsonValue("string"));
+
+ TJsonValue array;
+ array.AppendValue(1);
+ array.AppendValue(2);
+ array.AppendValue(3);
+ array.AppendValue("string");
+ lhs.InsertValue("array", array);
+
+ lhs.InsertValue("bool key", TJsonValue(true));
+
+ TJsonValue rhs;
+ rhs.InsertValue("null value", TJsonValue(JSON_NULL));
+ rhs.InsertValue("int key", TJsonValue(10));
+ rhs.InsertValue("double key", TJsonValue(11.11));
+ rhs.InsertValue("string key", TJsonValue("string"));
+ rhs.InsertValue("bool key", TJsonValue(true));
+
+ UNIT_ASSERT(lhs != rhs);
+ UNIT_ASSERT(rhs != lhs);
+ }
+ }
Y_UNIT_TEST(SwapTest) {
{
@@ -647,4 +647,4 @@ Y_UNIT_TEST_SUITE(TJsonValueTest) {
UNIT_ASSERT_VALUES_EQUAL(filled["4"].GetMapSafe().size(), 1);
UNIT_ASSERT_VALUES_EQUAL(filled["4"]["5"], TJsonValue{5});
}
-} // TJsonValueTest
+} // TJsonValueTest
diff --git a/library/cpp/messagebus/coreconn.cpp b/library/cpp/messagebus/coreconn.cpp
index d9411bb5db..3ffc2a77e9 100644
--- a/library/cpp/messagebus/coreconn.cpp
+++ b/library/cpp/messagebus/coreconn.cpp
@@ -3,7 +3,7 @@
#include "remote_connection.h"
#include <util/datetime/base.h>
-#include <util/generic/yexception.h>
+#include <util/generic/yexception.h>
#include <util/network/socket.h>
#include <util/string/util.h>
#include <util/system/thread.h>
@@ -25,6 +25,6 @@ namespace NBus {
}
ythrow yexception() << "Neither of IPv4/IPv6 is allowed.";
- }
-
+ }
+
}
diff --git a/library/cpp/messagebus/coreconn.h b/library/cpp/messagebus/coreconn.h
index fca228d82e..724639f68c 100644
--- a/library/cpp/messagebus/coreconn.h
+++ b/library/cpp/messagebus/coreconn.h
@@ -48,7 +48,7 @@ namespace NBus {
int syserr = LastSystemError();
return syserr == EAGAIN || syserr == EINPROGRESS || syserr == EWOULDBLOCK || syserr == EINTR;
}
-
+
class TBusSession;
struct TMaxConnectedException: public yexception {
diff --git a/library/cpp/messagebus/locator.cpp b/library/cpp/messagebus/locator.cpp
index e38a35c426..55eaf050a4 100644
--- a/library/cpp/messagebus/locator.cpp
+++ b/library/cpp/messagebus/locator.cpp
@@ -6,7 +6,7 @@
#include "ybus.h"
-#include <util/generic/hash_set.h>
+#include <util/generic/hash_set.h>
#include <util/system/hostname.h>
namespace NBus {
diff --git a/library/cpp/messagebus/rain_check/core/track_ut.cpp b/library/cpp/messagebus/rain_check/core/track_ut.cpp
index 05f7de1319..38730cf24f 100644
--- a/library/cpp/messagebus/rain_check/core/track_ut.cpp
+++ b/library/cpp/messagebus/rain_check/core/track_ut.cpp
@@ -34,7 +34,7 @@ Y_UNIT_TEST_SUITE(TaskTracker) {
testSync.WaitFor(1);
- UNIT_ASSERT_VALUES_EQUAL(1u, tracker->Size());
+ UNIT_ASSERT_VALUES_EQUAL(1u, tracker->Size());
testSync.CheckAndIncrement(1);
diff --git a/library/cpp/messagebus/rain_check/http/client.cpp b/library/cpp/messagebus/rain_check/http/client.cpp
index 5ef5ceeece..c72fbd33e0 100644
--- a/library/cpp/messagebus/rain_check/http/client.cpp
+++ b/library/cpp/messagebus/rain_check/http/client.cpp
@@ -1,5 +1,5 @@
-#include "client.h"
-
+#include "client.h"
+
#include "http_code_extractor.h"
#include <library/cpp/http/io/stream.h>
@@ -7,13 +7,13 @@
#include <library/cpp/neh/http_common.h>
#include <library/cpp/neh/location.h>
#include <library/cpp/neh/neh.h>
-
+
#include <util/generic/ptr.h>
#include <util/generic/strbuf.h>
#include <util/network/socket.h>
#include <util/stream/str.h>
-
-namespace NRainCheck {
+
+namespace NRainCheck {
class THttpCallback: public NNeh::IOnRecv {
public:
THttpCallback(NRainCheck::THttpFuture* future)
@@ -21,7 +21,7 @@ namespace NRainCheck {
{
Y_VERIFY(!!future, "future is NULL");
}
-
+
void OnRecv(NNeh::THandle& handle) override {
THolder<THttpCallback> self(this);
NNeh::TResponseRef response = handle.Get();
@@ -35,24 +35,24 @@ namespace NRainCheck {
THttpFuture::THttpFuture()
: Task(nullptr)
, ErrorCode(THttpFuture::NoError)
- {
- }
-
+ {
+ }
+
THttpFuture::~THttpFuture() {
- }
-
+ }
+
bool THttpFuture::HasError() const {
return (ErrorCode != THttpFuture::NoError);
}
-
+
THttpFuture::EError THttpFuture::GetErrorCode() const {
return ErrorCode;
}
-
+
TString THttpFuture::GetErrorDescription() const {
return ErrorDescription;
}
-
+
THttpClientService::THttpClientService()
: GetProtocol(NNeh::ProtocolFactory()->Protocol("http"))
, FullProtocol(NNeh::ProtocolFactory()->Protocol("full"))
@@ -60,10 +60,10 @@ namespace NRainCheck {
Y_VERIFY(!!GetProtocol, "GET protocol is NULL.");
Y_VERIFY(!!FullProtocol, "POST protocol is NULL.");
}
-
+
THttpClientService::~THttpClientService() {
}
-
+
void THttpClientService::SendPost(TString addr, const TString& data, const THttpHeaders& headers, THttpFuture* future) {
Y_VERIFY(!!future, "future is NULL.");
@@ -86,10 +86,10 @@ namespace NRainCheck {
future->SetFail(THttpFuture::OtherError, err.AsStrBuf());
}
}
-
+
void THttpClientService::Send(const TString& request, THttpFuture* future) {
Y_VERIFY(!!future, "future is NULL.");
-
+
TTaskRunnerBase* current = TTaskRunnerBase::CurrentTask();
future->SetRunning(current);
future->Task = current;
@@ -115,18 +115,18 @@ namespace NRainCheck {
bool THttpFuture::HasResponseBody() const {
return !!Response;
}
-
+
ui32 THttpFuture::GetHttpCode() const {
Y_ASSERT(IsDone());
Y_ASSERT(HasHttpCode());
-
+
return static_cast<ui32>(*HttpCode);
}
-
+
TString THttpFuture::GetResponseBody() const {
Y_ASSERT(IsDone());
Y_ASSERT(HasResponseBody());
-
+
return Response->Data;
}
@@ -137,18 +137,18 @@ namespace NRainCheck {
} else {
ErrorCode = THttpFuture::BadHttpCodeError;
ErrorDescription = response->GetErrorText();
-
+
HttpCode = TryGetHttpCodeFromErrorDescription(ErrorDescription);
}
Response.Reset(response);
SetDone();
}
-
+
void THttpFuture::SetFail(THttpFuture::EError errorCode, const TStringBuf& errorDescription) {
ErrorCode = errorCode;
ErrorDescription = errorDescription;
Response.Destroy();
SetDone();
}
-
+
}
diff --git a/library/cpp/messagebus/rain_check/http/client.h b/library/cpp/messagebus/rain_check/http/client.h
index d4199c4c98..d44567625e 100644
--- a/library/cpp/messagebus/rain_check/http/client.h
+++ b/library/cpp/messagebus/rain_check/http/client.h
@@ -1,31 +1,31 @@
-#pragma once
-
+#pragma once
+
#include <library/cpp/messagebus/rain_check/core/task.h>
-
+
#include <library/cpp/http/misc/httpcodes.h>
#include <util/generic/maybe.h>
-#include <util/generic/ptr.h>
+#include <util/generic/ptr.h>
#include <util/generic/string.h>
-#include <util/system/defaults.h>
-#include <util/system/yassert.h>
-
+#include <util/system/defaults.h>
+#include <util/system/yassert.h>
+
class THttpHeaders;
-namespace NNeh {
+namespace NNeh {
class IProtocol;
struct TResponse;
}
-
-namespace NRainCheck {
+
+namespace NRainCheck {
class THttpCallback;
class THttpClientService;
-
+
class THttpFuture: public TSubtaskCompletion {
public:
enum EError {
NoError = 0,
-
+
CantResolveNameError = 1,
BadHttpCodeError = 2,
@@ -39,17 +39,17 @@ namespace NRainCheck {
public:
THttpFuture();
~THttpFuture() override;
-
+
bool HasHttpCode() const;
bool HasResponseBody() const;
-
+
ui32 GetHttpCode() const;
TString GetResponseBody() const;
bool HasError() const;
EError GetErrorCode() const;
TString GetErrorDescription() const;
-
+
private:
void SetDoneAndSchedule(TAutoPtr<NNeh::TResponse> response);
void SetFail(EError errorCode, const TStringBuf& errorDescription);
@@ -61,18 +61,18 @@ namespace NRainCheck {
EError ErrorCode;
TString ErrorDescription;
};
-
+
class THttpClientService {
public:
THttpClientService();
virtual ~THttpClientService();
-
+
void Send(const TString& request, THttpFuture* future);
void SendPost(TString addr, const TString& data, const THttpHeaders& headers, THttpFuture* future);
-
+
private:
NNeh::IProtocol* const GetProtocol;
NNeh::IProtocol* const FullProtocol;
};
-
+
}
diff --git a/library/cpp/messagebus/rain_check/http/client_ut.cpp b/library/cpp/messagebus/rain_check/http/client_ut.cpp
index 1628114391..a455727081 100644
--- a/library/cpp/messagebus/rain_check/http/client_ut.cpp
+++ b/library/cpp/messagebus/rain_check/http/client_ut.cpp
@@ -1,45 +1,45 @@
#include <library/cpp/testing/unittest/registar.h>
-#include "client.h"
+#include "client.h"
#include "http_code_extractor.h"
#include <library/cpp/messagebus/rain_check/test/ut/test.h>
#include <library/cpp/messagebus/test/helper/fixed_port.h>
-
+
#include <library/cpp/http/io/stream.h>
#include <library/cpp/neh/rpc.h>
-
-#include <util/generic/cast.h>
-#include <util/generic/ptr.h>
-#include <util/generic/strbuf.h>
+
+#include <util/generic/cast.h>
+#include <util/generic/ptr.h>
+#include <util/generic/strbuf.h>
#include <util/generic/string.h>
-#include <util/generic/vector.h>
-#include <util/network/ip.h>
+#include <util/generic/vector.h>
+#include <util/network/ip.h>
#include <util/stream/str.h>
#include <util/string/printf.h>
-#include <util/system/defaults.h>
-#include <util/system/yassert.h>
-
-#include <cstdlib>
+#include <util/system/defaults.h>
+#include <util/system/yassert.h>
+
+#include <cstdlib>
#include <utility>
-
-using namespace NRainCheck;
+
+using namespace NRainCheck;
using namespace NBus::NTest;
-
-namespace {
+
+namespace {
class THttpClientEnv: public TTestEnvTemplate<THttpClientEnv> {
public:
THttpClientService HttpClientService;
};
-
+
const TString TEST_SERVICE = "test-service";
const TString TEST_GET_PARAMS = "p=GET";
const TString TEST_POST_PARAMS = "p=POST";
const TString TEST_POST_HEADERS = "Content-Type: application/json\r\n";
const TString TEST_GET_RECV = "GET was ok.";
const TString TEST_POST_RECV = "POST was ok.";
-
+
TString BuildServiceLocation(ui32 port) {
return Sprintf("http://*:%" PRIu32 "/%s", port, TEST_SERVICE.data());
}
@@ -47,11 +47,11 @@ namespace {
TString BuildPostServiceLocation(ui32 port) {
return Sprintf("post://*:%" PRIu32 "/%s", port + 1, TEST_SERVICE.data());
}
-
+
TString BuildGetTestRequest(ui32 port) {
return BuildServiceLocation(port) + "?" + TEST_GET_PARAMS;
}
-
+
class TSimpleServer {
public:
inline void ServeRequest(const NNeh::IRequestRef& req) {
@@ -76,16 +76,16 @@ namespace {
} catch (...) {
Y_FAIL("Can't run server: %s", CurrentExceptionMessage().data());
}
-
+
return runner;
- }
+ }
enum ERequestType {
RT_HTTP_GET = 0,
RT_HTTP_POST = 1
};
-
+
using TTaskParam = std::pair<TIpPort, ERequestType>;
-
+
class THttpClientTask: public ISimpleTask {
public:
THttpClientTask(THttpClientEnv* env, TTaskParam param)
@@ -118,46 +118,46 @@ namespace {
}
return &THttpClientTask::GotReplies;
- }
-
+ }
+
TContinueFunc GotReplies() {
const TString& TEST_OK_RECV = (ReqType == RT_HTTP_GET) ? TEST_GET_RECV : TEST_POST_RECV;
for (size_t i = 0; i < Requests.size(); ++i) {
UNIT_ASSERT_EQUAL(Requests[i]->GetHttpCode(), 200);
UNIT_ASSERT_EQUAL(Requests[i]->GetResponseBody(), TEST_OK_RECV);
}
-
+
Env->TestSync.CheckAndIncrement(0);
return nullptr;
- }
-
+ }
+
THttpClientEnv* const Env;
const TIpPort ServerPort;
const ERequestType ReqType;
-
+
TVector<TSimpleSharedPtr<THttpFuture>> Requests;
};
-
-} // anonymous namespace
-
+
+} // anonymous namespace
+
Y_UNIT_TEST_SUITE(RainCheckHttpClient) {
- static const TIpPort SERVER_PORT = 4000;
-
+ static const TIpPort SERVER_PORT = 4000;
+
Y_UNIT_TEST(Simple) {
// TODO: randomize port
if (!IsFixedPortTestAllowed()) {
return;
}
- TSimpleServer server;
- NNeh::IServicesRef runner = RunServer(SERVER_PORT, server);
-
- THttpClientEnv env;
+ TSimpleServer server;
+ NNeh::IServicesRef runner = RunServer(SERVER_PORT, server);
+
+ THttpClientEnv env;
TIntrusivePtr<TSimpleTaskRunner> task = env.SpawnTask<THttpClientTask>(TTaskParam(SERVER_PORT, RT_HTTP_GET));
-
- env.TestSync.WaitForAndIncrement(1);
- }
+
+ env.TestSync.WaitForAndIncrement(1);
+ }
Y_UNIT_TEST(SimplePost) {
// TODO: randomize port
@@ -202,4 +202,4 @@ Y_UNIT_TEST_SUITE(RainCheckHttpClient) {
CHECK_INVALID_LINE(TStringBuf("request failed(HTTP/1.1 3334 Some random message"));
#undef CHECK_INVALID_LINE
}
-}
+}
diff --git a/library/cpp/messagebus/rain_check/http/ya.make b/library/cpp/messagebus/rain_check/http/ya.make
index ef13329df3..579a0935d1 100644
--- a/library/cpp/messagebus/rain_check/http/ya.make
+++ b/library/cpp/messagebus/rain_check/http/ya.make
@@ -1,17 +1,17 @@
-LIBRARY()
-
+LIBRARY()
+
OWNER(g:messagebus)
-
-SRCS(
- client.cpp
+
+SRCS(
+ client.cpp
http_code_extractor.cpp
-)
-
-PEERDIR(
+)
+
+PEERDIR(
library/cpp/messagebus/rain_check/core
library/cpp/neh
library/cpp/http/misc
library/cpp/http/io
-)
-
-END()
+)
+
+END()
diff --git a/library/cpp/messagebus/rain_check/test/ut/ya.make b/library/cpp/messagebus/rain_check/test/ut/ya.make
index 9f7a93417a..ba5a7849ea 100644
--- a/library/cpp/messagebus/rain_check/test/ut/ya.make
+++ b/library/cpp/messagebus/rain_check/test/ut/ya.make
@@ -16,7 +16,7 @@ SRCS(
../../core/sleep_ut.cpp
../../core/spawn_ut.cpp
../../core/track_ut.cpp
- ../../http/client_ut.cpp
+ ../../http/client_ut.cpp
../../messagebus/messagebus_client_ut.cpp
../../messagebus/messagebus_server_ut.cpp
)
diff --git a/library/cpp/protobuf/json/README b/library/cpp/protobuf/json/README
index a0d1092ee2..b3a79ad7e6 100644
--- a/library/cpp/protobuf/json/README
+++ b/library/cpp/protobuf/json/README
@@ -1 +1 @@
-Protobuf to/from JSON converter.
+Protobuf to/from JSON converter.
diff --git a/library/cpp/protobuf/json/json2proto.cpp b/library/cpp/protobuf/json/json2proto.cpp
index 640c10f5a5..f2bb8d61ee 100644
--- a/library/cpp/protobuf/json/json2proto.cpp
+++ b/library/cpp/protobuf/json/json2proto.cpp
@@ -1,16 +1,16 @@
-#include "json2proto.h"
+#include "json2proto.h"
#include "util.h"
-
+
#include <library/cpp/json/json_value.h>
-
+
#include <google/protobuf/message.h>
#include <google/protobuf/descriptor.h>
-
+
#include <util/generic/hash.h>
#include <util/generic/maybe.h>
#include <util/string/ascii.h>
-#include <util/string/cast.h>
-
+#include <util/string/cast.h>
+
#define JSON_TO_FIELD(EProtoCppType, name, json, JsonCheckType, ProtoSet, JsonGet) \
case FieldDescriptor::EProtoCppType: { \
if (config.CastRobust) { \
@@ -32,8 +32,8 @@
} \
reflection->ProtoSet(&proto, &field, json.JsonGet()); \
break; \
- }
-
+ }
+
static TString GetFieldName(const google::protobuf::FieldDescriptor& field,
const NProtobufJson::TJson2ProtoConfig& config) {
if (config.NameGenerator) {
@@ -71,13 +71,13 @@ static TString GetFieldName(const google::protobuf::FieldDescriptor& field,
case NProtobufJson::TJson2ProtoConfig::FieldNameSnakeCaseDense:
NProtobufJson::ToSnakeCaseDense(&name);
break;
- default:
+ default:
Y_VERIFY_DEBUG(false, "Unknown FieldNameMode.");
}
return name;
}
-static void
+static void
JsonString2Field(const NJson::TJsonValue& json,
google::protobuf::Message& proto,
const google::protobuf::FieldDescriptor& field,
@@ -123,28 +123,28 @@ FindEnumValue(const NProtoBuf::EnumDescriptor* enumField,
}
static void
-JsonEnum2Field(const NJson::TJsonValue& json,
- google::protobuf::Message& proto,
+JsonEnum2Field(const NJson::TJsonValue& json,
+ google::protobuf::Message& proto,
const google::protobuf::FieldDescriptor& field,
const NProtobufJson::TJson2ProtoConfig& config) {
- using namespace google::protobuf;
-
- const Reflection* reflection = proto.GetReflection();
+ using namespace google::protobuf;
+
+ const Reflection* reflection = proto.GetReflection();
Y_ASSERT(!!reflection);
-
- const EnumDescriptor* enumField = field.enum_type();
+
+ const EnumDescriptor* enumField = field.enum_type();
Y_ASSERT(!!enumField);
-
- /// @todo configure name/numerical value
+
+ /// @todo configure name/numerical value
const EnumValueDescriptor* enumFieldValue = nullptr;
-
- if (json.IsInteger()) {
+
+ if (json.IsInteger()) {
const auto value = json.GetInteger();
enumFieldValue = enumField->FindValueByNumber(value);
if (!enumFieldValue) {
ythrow yexception() << "Invalid integer value of JSON enum field: " << value << ".";
}
- } else if (json.IsString()) {
+ } else if (json.IsString()) {
const auto& value = json.GetString();
if (config.EnumValueMode == NProtobufJson::TJson2ProtoConfig::EnumCaseInsensetive) {
enumFieldValue = FindEnumValue(enumField, value, AsciiEqualsIgnoreCase);
@@ -156,25 +156,25 @@ JsonEnum2Field(const NJson::TJsonValue& json,
if (!enumFieldValue) {
ythrow yexception() << "Invalid string value of JSON enum field: " << TStringBuf(value).Head(100) << ".";
}
- } else {
- ythrow yexception() << "Invalid type of JSON enum field: not an integer/string.";
- }
-
+ } else {
+ ythrow yexception() << "Invalid type of JSON enum field: not an integer/string.";
+ }
+
if (field.is_repeated()) {
reflection->AddEnum(&proto, &field, enumFieldValue);
- } else {
+ } else {
reflection->SetEnum(&proto, &field, enumFieldValue);
- }
-}
-
-static void
-Json2SingleField(const NJson::TJsonValue& json,
- google::protobuf::Message& proto,
+ }
+}
+
+static void
+Json2SingleField(const NJson::TJsonValue& json,
+ google::protobuf::Message& proto,
const google::protobuf::FieldDescriptor& field,
const NProtobufJson::TJson2ProtoConfig& config,
bool isMapValue = false) {
- using namespace google::protobuf;
-
+ using namespace google::protobuf;
+
const Reflection* reflection = proto.GetReflection();
Y_ASSERT(!!reflection);
@@ -188,12 +188,12 @@ Json2SingleField(const NJson::TJsonValue& json,
}
return;
- }
- }
-
+ }
+ }
+
const NJson::TJsonValue& fieldJson = name ? json[name] : json;
-
- switch (field.cpp_type()) {
+
+ switch (field.cpp_type()) {
JSON_TO_FIELD(CPPTYPE_INT32, field.name(), fieldJson, IsInteger, SetInt32, GetInteger);
JSON_TO_FIELD(CPPTYPE_INT64, field.name(), fieldJson, IsInteger, SetInt64, GetInteger);
JSON_TO_FIELD(CPPTYPE_UINT32, field.name(), fieldJson, IsInteger, SetUInt32, GetInteger);
@@ -201,7 +201,7 @@ Json2SingleField(const NJson::TJsonValue& json,
JSON_TO_FIELD(CPPTYPE_DOUBLE, field.name(), fieldJson, IsDouble, SetDouble, GetDouble);
JSON_TO_FIELD(CPPTYPE_FLOAT, field.name(), fieldJson, IsDouble, SetFloat, GetDouble);
JSON_TO_FIELD(CPPTYPE_BOOL, field.name(), fieldJson, IsBoolean, SetBool, GetBoolean);
-
+
case FieldDescriptor::CPPTYPE_STRING: {
JsonString2Field(fieldJson, proto, field, config);
break;
@@ -211,22 +211,22 @@ Json2SingleField(const NJson::TJsonValue& json,
JsonEnum2Field(fieldJson, proto, field, config);
break;
}
-
+
case FieldDescriptor::CPPTYPE_MESSAGE: {
Message* innerProto = reflection->MutableMessage(&proto, &field);
Y_ASSERT(!!innerProto);
NProtobufJson::MergeJson2Proto(fieldJson, *innerProto, config);
-
+
break;
}
-
+
default:
ythrow yexception() << "Unknown protobuf field type: "
<< static_cast<int>(field.cpp_type()) << ".";
- }
-}
-
-static void
+ }
+}
+
+static void
SetKey(NProtoBuf::Message& proto,
const NProtoBuf::FieldDescriptor& field,
const TString& key) {
@@ -312,20 +312,20 @@ Json2RepeatedFieldValue(const NJson::TJsonValue& jsonValue,
}
static void
-Json2RepeatedField(const NJson::TJsonValue& json,
- google::protobuf::Message& proto,
+Json2RepeatedField(const NJson::TJsonValue& json,
+ google::protobuf::Message& proto,
const google::protobuf::FieldDescriptor& field,
const NProtobufJson::TJson2ProtoConfig& config) {
- using namespace google::protobuf;
-
+ using namespace google::protobuf;
+
TString name = GetFieldName(field, config);
if (!json.Has(name))
- return;
-
+ return;
+
const NJson::TJsonValue& fieldJson = json[name];
if (fieldJson.GetType() == NJson::JSON_UNDEFINED || fieldJson.GetType() == NJson::JSON_NULL)
- return;
-
+ return;
+
bool isMap = fieldJson.GetType() == NJson::JSON_MAP;
if (isMap) {
if (!config.MapAsObject) {
@@ -336,15 +336,15 @@ Json2RepeatedField(const NJson::TJsonValue& json,
}
if (fieldJson.GetType() != NJson::JSON_ARRAY && !config.MapAsObject && !config.VectorizeScalars && !config.ValueVectorizer) {
- ythrow yexception() << "JSON field doesn't represent an array for "
+ ythrow yexception() << "JSON field doesn't represent an array for "
<< name
- << "(actual type is "
- << static_cast<int>(fieldJson.GetType()) << ").";
- }
-
- const Reflection* reflection = proto.GetReflection();
+ << "(actual type is "
+ << static_cast<int>(fieldJson.GetType()) << ").";
+ }
+
+ const Reflection* reflection = proto.GetReflection();
Y_ASSERT(!!reflection);
-
+
if (isMap) {
const THashMap<TString, NJson::TJsonValue> jsonMap = fieldJson.GetMap();
for (const auto& x : jsonMap) {
@@ -367,16 +367,16 @@ Json2RepeatedField(const NJson::TJsonValue& json,
}
} else if (config.VectorizeScalars) {
Json2RepeatedFieldValue(fieldJson, proto, field, config, reflection);
- }
- }
-}
-
-namespace NProtobufJson {
+ }
+ }
+}
+
+namespace NProtobufJson {
void MergeJson2Proto(const NJson::TJsonValue& json, google::protobuf::Message& proto, const TJson2ProtoConfig& config) {
if (json.IsNull()) {
return;
}
-
+
Y_ENSURE(json.IsMap(), "expected json map");
const google::protobuf::Descriptor* descriptor = proto.GetDescriptor();
@@ -385,7 +385,7 @@ namespace NProtobufJson {
for (int f = 0, endF = descriptor->field_count(); f < endF; ++f) {
const google::protobuf::FieldDescriptor* field = descriptor->field(f);
Y_ASSERT(!!field);
-
+
if (field->is_repeated()) {
Json2RepeatedField(json, proto, *field, config);
} else {
@@ -404,7 +404,7 @@ namespace NProtobufJson {
}
}
}
-
+
void MergeJson2Proto(const TStringBuf& json, google::protobuf::Message& proto, const TJson2ProtoConfig& config) {
NJson::TJsonReaderConfig jsonCfg;
jsonCfg.DontValidateUtf8 = true;
diff --git a/library/cpp/protobuf/json/json2proto.h b/library/cpp/protobuf/json/json2proto.h
index 4c33498dfa..343502aab2 100644
--- a/library/cpp/protobuf/json/json2proto.h
+++ b/library/cpp/protobuf/json/json2proto.h
@@ -1,5 +1,5 @@
-#pragma once
-
+#pragma once
+
#include "string_transform.h"
#include "name_generator.h"
@@ -9,18 +9,18 @@
#include <util/stream/input.h>
#include <util/stream/str.h>
#include <util/stream/mem.h>
-
+
namespace google {
namespace protobuf {
class Message;
}
}
-namespace NProtobufJson {
+namespace NProtobufJson {
struct TJson2ProtoConfig {
using TSelf = TJson2ProtoConfig;
using TValueVectorizer = std::function<NJson::TJsonValue::TArray(const NJson::TJsonValue& jsonValue)>;
-
+
enum FldNameMode {
FieldNameOriginalCase = 0, // default
FieldNameLowerCase,
@@ -167,7 +167,7 @@ namespace NProtobufJson {
/// @throw yexception
void Json2Proto(const TStringBuf& json, google::protobuf::Message& proto,
const TJson2ProtoConfig& config = TJson2ProtoConfig());
-
+
/// @throw yexception
inline void Json2Proto(const TString& json, google::protobuf::Message& proto,
const TJson2ProtoConfig& config = TJson2ProtoConfig()) {
diff --git a/library/cpp/protobuf/json/proto2json.cpp b/library/cpp/protobuf/json/proto2json.cpp
index 3d76a91686..662172caaa 100644
--- a/library/cpp/protobuf/json/proto2json.cpp
+++ b/library/cpp/protobuf/json/proto2json.cpp
@@ -1,25 +1,25 @@
-#include "proto2json.h"
-
+#include "proto2json.h"
+
#include "json_output_create.h"
#include "proto2json_printer.h"
#include <library/cpp/json/json_reader.h>
#include <library/cpp/json/json_value.h>
#include <library/cpp/json/json_writer.h>
-
-#include <util/generic/ptr.h>
-#include <util/generic/strbuf.h>
-#include <util/stream/output.h>
-#include <util/stream/str.h>
-#include <util/system/yassert.h>
-
+
+#include <util/generic/ptr.h>
+#include <util/generic/strbuf.h>
+#include <util/stream/output.h>
+#include <util/stream/str.h>
+#include <util/system/yassert.h>
+
namespace NProtobufJson {
void Proto2Json(const NProtoBuf::Message& proto, IJsonOutput& jsonOutput,
const TProto2JsonConfig& config, bool closeMap) {
TProto2JsonPrinter printer(config);
printer.Print(proto, jsonOutput, closeMap);
}
-
+
void Proto2Json(const NProtoBuf::Message& proto, NJson::TJsonValue& json,
const TProto2JsonConfig& config) {
Proto2Json(proto, *CreateJsonMapOutput(json), config);
@@ -30,27 +30,27 @@ namespace NProtobufJson {
Proto2Json(proto, *CreateJsonMapOutput(writer), config);
writer.Flush();
}
-
+
void Proto2Json(const NProtoBuf::Message& proto, IOutputStream& out,
const TProto2JsonConfig& config) {
Proto2Json(proto, *CreateJsonMapOutput(out, config), config);
}
-
+
void Proto2Json(const NProtoBuf::Message& proto, TStringStream& out,
const TProto2JsonConfig& config) {
Proto2Json(proto, *CreateJsonMapOutput(out, config), config);
}
-
+
void Proto2Json(const NProtoBuf::Message& proto, TString& str,
const TProto2JsonConfig& config) {
Proto2Json(proto, *CreateJsonMapOutput(str, config), config);
}
-
+
TString Proto2Json(const ::NProtoBuf::Message& proto,
const TProto2JsonConfig& config) {
TString res;
Proto2Json(proto, res, config);
return res;
}
-
+
}
diff --git a/library/cpp/protobuf/json/proto2json.h b/library/cpp/protobuf/json/proto2json.h
index 89a1781a40..7381297b56 100644
--- a/library/cpp/protobuf/json/proto2json.h
+++ b/library/cpp/protobuf/json/proto2json.h
@@ -1,38 +1,38 @@
-#pragma once
-
+#pragma once
+
#include "config.h"
#include "json_output.h"
-
+
#include <google/protobuf/descriptor.h>
#include <google/protobuf/descriptor.pb.h>
#include <google/protobuf/message.h>
#include <util/generic/fwd.h>
-#include <util/generic/vector.h>
+#include <util/generic/vector.h>
#include <util/generic/yexception.h>
#include <util/stream/str.h>
-
+
#include <functional>
-
-namespace NJson {
+
+namespace NJson {
class TJsonValue;
class TJsonWriter;
}
-
+
class IOutputStream;
-class TStringStream;
-
-namespace NProtobufJson {
+class TStringStream;
+
+namespace NProtobufJson {
void Proto2Json(const NProtoBuf::Message& proto, IJsonOutput& jsonOutput,
const TProto2JsonConfig& config = TProto2JsonConfig(), bool closeMap = true);
-
+
void Proto2Json(const NProtoBuf::Message& proto, NJson::TJsonWriter& writer,
const TProto2JsonConfig& config = TProto2JsonConfig());
-
+
/// @throw yexception
void Proto2Json(const NProtoBuf::Message& proto, NJson::TJsonValue& json,
const TProto2JsonConfig& config = TProto2JsonConfig());
-
+
/// @throw yexception
void Proto2Json(const NProtoBuf::Message& proto, IOutputStream& out,
const TProto2JsonConfig& config);
@@ -41,7 +41,7 @@ namespace NProtobufJson {
inline void Proto2Json(const T& proto, IOutputStream& out) {
out << proto.AsJSON();
}
-
+
// TStringStream deserves a special overload as its operator TString() would cause ambiguity
/// @throw yexception
void Proto2Json(const NProtoBuf::Message& proto, TStringStream& out,
@@ -62,7 +62,7 @@ namespace NProtobufJson {
TStringOutput out(str);
out << proto.AsJSON();
}
-
+
/// @throw yexception
TString Proto2Json(const NProtoBuf::Message& proto,
const TProto2JsonConfig& config);
@@ -74,5 +74,5 @@ namespace NProtobufJson {
Proto2Json(proto, result);
return result;
}
-
+
}
diff --git a/library/cpp/protobuf/json/string_transform.cpp b/library/cpp/protobuf/json/string_transform.cpp
index 7c42daa677..0931f47f53 100644
--- a/library/cpp/protobuf/json/string_transform.cpp
+++ b/library/cpp/protobuf/json/string_transform.cpp
@@ -1,18 +1,18 @@
-#include "string_transform.h"
-
+#include "string_transform.h"
+
#include <google/protobuf/stubs/strutil.h>
-
+
#include <library/cpp/string_utils/base64/base64.h>
-namespace NProtobufJson {
+namespace NProtobufJson {
void TCEscapeTransform::Transform(TString& str) const {
str = google::protobuf::CEscape(str);
}
-
+
void TSafeUtf8CEscapeTransform::Transform(TString& str) const {
str = google::protobuf::strings::Utf8SafeCEscape(str);
}
-
+
void TDoubleEscapeTransform::Transform(TString& str) const {
TString escaped = google::protobuf::CEscape(str);
str = "";
@@ -22,7 +22,7 @@ namespace NProtobufJson {
str += *it;
}
}
-
+
void TDoubleUnescapeTransform::Transform(TString& str) const {
str = google::protobuf::UnescapeCEscapeString(Unescape(str));
}
diff --git a/library/cpp/protobuf/json/string_transform.h b/library/cpp/protobuf/json/string_transform.h
index e4b296bc01..3676c0eae5 100644
--- a/library/cpp/protobuf/json/string_transform.h
+++ b/library/cpp/protobuf/json/string_transform.h
@@ -1,26 +1,26 @@
-#pragma once
-
+#pragma once
+
#include <library/cpp/string_utils/relaxed_escaper/relaxed_escaper.h>
-#include <util/generic/ptr.h>
-#include <util/generic/refcount.h>
-
-namespace NProtobufJson {
+#include <util/generic/ptr.h>
+#include <util/generic/refcount.h>
+
+namespace NProtobufJson {
class IStringTransform: public TSimpleRefCount<IStringTransform> {
public:
virtual ~IStringTransform() {
}
-
+
/// Some transforms have special meaning.
/// For example, escape transforms cause generic JSON escaping to be turned off.
enum Type {
EscapeTransform = 0x1,
};
-
+
virtual int GetType() const = 0;
-
+
/// This method is called for each string field in proto
virtual void Transform(TString& str) const = 0;
-
+
/// This method is called for each bytes field in proto
virtual void TransformBytes(TString& str) const {
// Default behaviour is to apply string transform
@@ -29,45 +29,45 @@ namespace NProtobufJson {
};
using TStringTransformPtr = TIntrusivePtr<IStringTransform>;
-
+
template <bool quote, bool tounicode>
class TEscapeJTransform: public IStringTransform {
public:
int GetType() const override {
return EscapeTransform;
}
-
+
void Transform(TString& str) const override {
TString newStr;
NEscJ::EscapeJ<quote, tounicode>(str, newStr);
str = newStr;
}
};
-
+
class TCEscapeTransform: public IStringTransform {
public:
int GetType() const override {
return EscapeTransform;
}
-
+
void Transform(TString& str) const override;
};
-
+
class TSafeUtf8CEscapeTransform: public IStringTransform {
public:
int GetType() const override {
return EscapeTransform;
}
-
+
void Transform(TString& str) const override;
};
-
+
class TDoubleEscapeTransform: public IStringTransform {
public:
int GetType() const override {
return EscapeTransform;
}
-
+
void Transform(TString& str) const override;
};
diff --git a/library/cpp/protobuf/json/ut/fields.incl b/library/cpp/protobuf/json/ut/fields.incl
index 4b22985836..de255a08da 100644
--- a/library/cpp/protobuf/json/ut/fields.incl
+++ b/library/cpp/protobuf/json/ut/fields.incl
@@ -1,22 +1,22 @@
-// Intentionally no #pragma once
-
-// (Field name == JSON key, Value)
-DEFINE_FIELD(I32, Min<i32>())
-DEFINE_FIELD(I64, Min<i64>())
-DEFINE_FIELD(UI32, Max<ui32>())
-DEFINE_FIELD(UI64, Max<ui64>())
-DEFINE_FIELD(SI32, Min<i32>())
-DEFINE_FIELD(SI64, Min<i64>())
-DEFINE_FIELD(FI32, Max<ui32>())
-DEFINE_FIELD(FI64, Max<ui64>())
-DEFINE_FIELD(SFI32, Min<i32>())
-DEFINE_FIELD(SFI64, Min<i64>())
-DEFINE_FIELD(Bool, true)
-DEFINE_FIELD(String, "Lorem ipsum")
-DEFINE_FIELD(Bytes, "מחשב")
-DEFINE_FIELD(Enum, E_1)
-DEFINE_FIELD(Float, 1.123f)
-DEFINE_FIELD(Double, 1.123456789012)
+// Intentionally no #pragma once
+
+// (Field name == JSON key, Value)
+DEFINE_FIELD(I32, Min<i32>())
+DEFINE_FIELD(I64, Min<i64>())
+DEFINE_FIELD(UI32, Max<ui32>())
+DEFINE_FIELD(UI64, Max<ui64>())
+DEFINE_FIELD(SI32, Min<i32>())
+DEFINE_FIELD(SI64, Min<i64>())
+DEFINE_FIELD(FI32, Max<ui32>())
+DEFINE_FIELD(FI64, Max<ui64>())
+DEFINE_FIELD(SFI32, Min<i32>())
+DEFINE_FIELD(SFI64, Min<i64>())
+DEFINE_FIELD(Bool, true)
+DEFINE_FIELD(String, "Lorem ipsum")
+DEFINE_FIELD(Bytes, "מחשב")
+DEFINE_FIELD(Enum, E_1)
+DEFINE_FIELD(Float, 1.123f)
+DEFINE_FIELD(Double, 1.123456789012)
DEFINE_FIELD(OneString, "Lorem ipsum dolor")
DEFINE_FIELD(OneTwoString, "Lorem ipsum dolor sit")
DEFINE_FIELD(ABC, "abc")
diff --git a/library/cpp/protobuf/json/ut/json.h b/library/cpp/protobuf/json/ut/json.h
index c1f108e6e4..4f942f347b 100644
--- a/library/cpp/protobuf/json/ut/json.h
+++ b/library/cpp/protobuf/json/ut/json.h
@@ -1,34 +1,34 @@
-#pragma once
-
+#pragma once
+
#include <library/cpp/protobuf/json/ut/test.pb.h>
-
+
#include <library/cpp/json/json_value.h>
-
-#include <cstdarg>
-
-#include <util/generic/hash_set.h>
+
+#include <cstdarg>
+
+#include <util/generic/hash_set.h>
#include <util/generic/string.h>
-
-#include <util/system/defaults.h>
-
-namespace NProtobufJsonTest {
+
+#include <util/system/defaults.h>
+
+namespace NProtobufJsonTest {
inline NJson::TJsonValue
CreateFlatJson(const THashSet<TString>& skippedKeys = THashSet<TString>()) {
NJson::TJsonValue json;
-
+
#define DEFINE_FIELD(name, value) \
if (skippedKeys.find(#name) == skippedKeys.end()) \
- json.InsertValue(#name, value);
-#include "fields.incl"
-#undef DEFINE_FIELD
-
+ json.InsertValue(#name, value);
+#include "fields.incl"
+#undef DEFINE_FIELD
+
return json;
}
-
+
inline NJson::TJsonValue
CreateRepeatedFlatJson(const THashSet<TString>& skippedKeys = THashSet<TString>()) {
NJson::TJsonValue json;
-
+
#define DEFINE_REPEATED_FIELD(name, type, ...) \
if (skippedKeys.find(#name) == skippedKeys.end()) { \
type values[] = {__VA_ARGS__}; \
@@ -37,22 +37,22 @@ namespace NProtobufJsonTest {
array.AppendValue(values[i]); \
} \
json.InsertValue(#name, array); \
- }
-#include "repeated_fields.incl"
-#undef DEFINE_REPEATED_FIELD
-
+ }
+#include "repeated_fields.incl"
+#undef DEFINE_REPEATED_FIELD
+
return json;
}
-
+
inline NJson::TJsonValue
CreateCompositeJson(const THashSet<TString>& skippedKeys = THashSet<TString>()) {
const NJson::TJsonValue& part = CreateFlatJson(skippedKeys);
NJson::TJsonValue json;
json.InsertValue("Part", part);
-
+
return json;
}
-
+
#define UNIT_ASSERT_JSONS_EQUAL(lhs, rhs) \
if (lhs != rhs) { \
UNIT_ASSERT_STRINGS_EQUAL(lhs.GetStringRobust(), rhs.GetStringRobust()); \
diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp
index 0dfe57bc7a..4752d2dfa6 100644
--- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp
+++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp
@@ -1,28 +1,28 @@
-#include "json.h"
-#include "proto.h"
+#include "json.h"
+#include "proto.h"
#include "proto2json.h"
-
+
#include <library/cpp/protobuf/json/ut/test.pb.h>
#include <library/cpp/json/json_value.h>
#include <library/cpp/json/json_reader.h>
#include <library/cpp/json/json_writer.h>
-
+
#include <library/cpp/protobuf/json/json2proto.h>
-
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/generic/hash_set.h>
+
+#include <util/generic/hash_set.h>
#include <util/generic/string.h>
-#include <util/generic/ylimits.h>
-#include <util/stream/str.h>
+#include <util/generic/ylimits.h>
+#include <util/stream/str.h>
#include <util/string/cast.h>
-#include <util/system/defaults.h>
-#include <util/system/yassert.h>
-
-using namespace NProtobufJson;
-using namespace NProtobufJsonTest;
-
+#include <util/system/defaults.h>
+#include <util/system/yassert.h>
+
+using namespace NProtobufJson;
+using namespace NProtobufJsonTest;
+
namespace google {
namespace protobuf {
namespace internal {
@@ -79,7 +79,7 @@ Y_UNIT_TEST_SUITE(TJson2ProtoTest) {
FillFlatProto(&modelProto);
UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto);
}
-
+
// Try to skip each field
#define DEFINE_FIELD(name, value) \
{ \
@@ -93,9 +93,9 @@ Y_UNIT_TEST_SUITE(TJson2ProtoTest) {
UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); \
}
#include <library/cpp/protobuf/json/ut/fields.incl>
-#undef DEFINE_FIELD
+#undef DEFINE_FIELD
} // TestFlatOptional
-
+
Y_UNIT_TEST(TestFlatRequired){
{const NJson::TJsonValue& json = CreateFlatJson();
TFlatRequired proto;
@@ -104,7 +104,7 @@ TFlatRequired modelProto;
FillFlatProto(&modelProto);
UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto);
}
-
+
// Try to skip each field
#define DEFINE_FIELD(name, value) \
{ \
@@ -115,9 +115,9 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto);
UNIT_ASSERT_EXCEPTION(Json2Proto(json, proto), yexception); \
}
#include <library/cpp/protobuf/json/ut/fields.incl>
-#undef DEFINE_FIELD
+#undef DEFINE_FIELD
} // TestFlatRequired
-
+
Y_UNIT_TEST(TestNameGenerator) {
TJson2ProtoConfig cfg;
cfg.SetNameGenerator([](const NProtoBuf::FieldDescriptor&) { return "42"; });
@@ -165,7 +165,7 @@ TFlatRepeated modelProto;
FillRepeatedProto(&modelProto);
UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto);
}
-
+
// Try to skip each field
#define DEFINE_REPEATED_FIELD(name, ...) \
{ \
@@ -179,9 +179,9 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto);
UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); \
}
#include <library/cpp/protobuf/json/ut/repeated_fields.incl>
-#undef DEFINE_REPEATED_FIELD
+#undef DEFINE_REPEATED_FIELD
} // TestFlatRepeated
-
+
Y_UNIT_TEST(TestCompositeOptional){
{const NJson::TJsonValue& json = CreateCompositeJson();
TCompositeOptional proto;
@@ -190,7 +190,7 @@ TCompositeOptional modelProto;
FillCompositeProto(&modelProto);
UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto);
}
-
+
// Try to skip each field
#define DEFINE_FIELD(name, value) \
{ \
@@ -204,9 +204,9 @@ UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto);
UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto); \
}
#include <library/cpp/protobuf/json/ut/fields.incl>
-#undef DEFINE_FIELD
+#undef DEFINE_FIELD
} // TestCompositeOptional
-
+
Y_UNIT_TEST(TestCompositeOptionalStringBuf){
{NJson::TJsonValue json = CreateCompositeJson();
json["Part"]["Double"] = 42.5;
@@ -249,37 +249,37 @@ Y_UNIT_TEST(TestCompositeRequired) {
FillCompositeProto(&modelProto);
UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto);
}
-
+
{
NJson::TJsonValue json;
TCompositeRequired proto;
UNIT_ASSERT_EXCEPTION(Json2Proto(json, proto), yexception);
}
} // TestCompositeRequired
-
+
Y_UNIT_TEST(TestCompositeRepeated) {
{
NJson::TJsonValue json;
NJson::TJsonValue array;
array.AppendValue(CreateFlatJson());
json.InsertValue("Part", array);
-
+
TCompositeRepeated proto;
Json2Proto(json, proto);
-
+
TFlatOptional partModelProto;
FillFlatProto(&partModelProto);
TCompositeRepeated modelProto;
modelProto.AddPart()->CopyFrom(partModelProto);
-
+
UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto);
}
-
+
{
// Array of messages with each field skipped
TCompositeRepeated modelProto;
NJson::TJsonValue array;
-
+
#define DEFINE_REPEATED_FIELD(name, ...) \
{ \
THashSet<TString> skippedField; \
@@ -290,18 +290,18 @@ Y_UNIT_TEST(TestCompositeRepeated) {
array.AppendValue(CreateFlatJson(skippedField)); \
}
#include <library/cpp/protobuf/json/ut/repeated_fields.incl>
-#undef DEFINE_REPEATED_FIELD
-
+#undef DEFINE_REPEATED_FIELD
+
NJson::TJsonValue json;
json.InsertValue("Part", array);
-
+
TCompositeRepeated proto;
Json2Proto(json, proto);
-
+
UNIT_ASSERT_PROTOS_EQUAL(proto, modelProto);
}
} // TestCompositeRepeated
-
+
Y_UNIT_TEST(TestInvalidEnum) {
{
NJson::TJsonValue json;
@@ -309,13 +309,13 @@ Y_UNIT_TEST(TestInvalidEnum) {
TFlatOptional proto;
UNIT_ASSERT_EXCEPTION(Json2Proto(json, proto), yexception);
}
-
+
{
NJson::TJsonValue json;
json.InsertValue("Enum", 100);
TFlatOptional proto;
UNIT_ASSERT_EXCEPTION(Json2Proto(json, proto), yexception);
- }
+ }
}
Y_UNIT_TEST(TestFieldNameMode) {
@@ -1144,4 +1144,4 @@ Y_UNIT_TEST(TestAllowComments) {
UNIT_ASSERT_VALUES_EQUAL(proto.GetI64(), 3423);
} // TestAllowComments
-} // TJson2ProtoTest
+} // TJson2ProtoTest
diff --git a/library/cpp/protobuf/json/ut/proto.h b/library/cpp/protobuf/json/ut/proto.h
index 8183bfc8e1..db27ed52c7 100644
--- a/library/cpp/protobuf/json/ut/proto.h
+++ b/library/cpp/protobuf/json/ut/proto.h
@@ -1,11 +1,11 @@
-#pragma once
-
-#include <util/generic/hash_set.h>
+#pragma once
+
+#include <util/generic/hash_set.h>
#include <util/generic/string.h>
-
-#include <util/system/defaults.h>
-
-namespace NProtobufJsonTest {
+
+#include <util/system/defaults.h>
+
+namespace NProtobufJsonTest {
template <typename TProto>
inline void
FillFlatProto(TProto* proto,
@@ -14,20 +14,20 @@ namespace NProtobufJsonTest {
if (skippedFields.find(#name) == skippedFields.end()) \
proto->Set##name(value);
#include <library/cpp/protobuf/json/ut/fields.incl>
-#undef DEFINE_FIELD
+#undef DEFINE_FIELD
}
-
+
template <typename TRepeatedField, typename TValue>
inline void
AddValue(TRepeatedField* field, TValue value) {
field->Add(value);
}
-
+
inline void
AddValue(google::protobuf::RepeatedPtrField<TString>* field, const TString& value) {
*(field->Add()) = value;
}
-
+
inline void
FillRepeatedProto(TFlatRepeated* proto,
const THashSet<TString>& skippedFields = THashSet<TString>()) {
@@ -37,17 +37,17 @@ namespace NProtobufJsonTest {
for (size_t i = 0, end = Y_ARRAY_SIZE(values); i < end; ++i) { \
AddValue(proto->Mutable##name(), values[i]); \
} \
- }
+ }
#include <library/cpp/protobuf/json/ut/repeated_fields.incl>
-#undef DEFINE_REPEATED_FIELD
+#undef DEFINE_REPEATED_FIELD
}
-
+
template <typename TProto>
inline void
FillCompositeProto(TProto* proto, const THashSet<TString>& skippedFields = THashSet<TString>()) {
FillFlatProto(proto->MutablePart(), skippedFields);
}
-
+
#define UNIT_ASSERT_PROTOS_EQUAL(lhs, rhs) \
do { \
if (lhs.SerializeAsString() != rhs.SerializeAsString()) { \
@@ -58,5 +58,5 @@ namespace NProtobufJsonTest {
UNIT_ASSERT_STRINGS_EQUAL(lhs.SerializeAsString(), rhs.SerializeAsString()); \
} \
} while (false);
-
+
}
diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp
index 07e52d7f2f..0de60cbe8c 100644
--- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp
+++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp
@@ -1,30 +1,30 @@
-#include "json.h"
-#include "proto.h"
-
+#include "json.h"
+#include "proto.h"
+
#include <library/cpp/protobuf/json/ut/test.pb.h>
#include <library/cpp/json/json_value.h>
#include <library/cpp/json/json_reader.h>
#include <library/cpp/json/json_writer.h>
-
+
#include <library/cpp/protobuf/json/proto2json.h>
-
+
#include <library/cpp/testing/unittest/registar.h>
-
-#include <util/generic/hash_set.h>
+
+#include <util/generic/hash_set.h>
#include <util/generic/string.h>
-#include <util/generic/ylimits.h>
-
-#include <util/stream/str.h>
-
-#include <util/system/defaults.h>
-#include <util/system/yassert.h>
-
+#include <util/generic/ylimits.h>
+
+#include <util/stream/str.h>
+
+#include <util/system/defaults.h>
+#include <util/system/yassert.h>
+
#include <limits>
-using namespace NProtobufJson;
-using namespace NProtobufJsonTest;
-
+using namespace NProtobufJson;
+using namespace NProtobufJsonTest;
+
Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) {
Y_UNIT_TEST(TestFlatDefault) {
using namespace ::google::protobuf;
@@ -109,7 +109,7 @@ Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) {
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
-
+
{
TStringStream jsonStream;
NJson::TJsonValue json;
@@ -118,7 +118,7 @@ Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) {
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
} // streamed
}
-
+
// Try to skip each field
#define DEFINE_FIELD(name, value) \
{ \
@@ -138,9 +138,9 @@ Y_UNIT_TEST_SUITE(TProto2JsonFlatTest) {
} \
}
#include <library/cpp/protobuf/json/ut/fields.incl>
-#undef DEFINE_FIELD
+#undef DEFINE_FIELD
} // TestFlatOptional
-
+
Y_UNIT_TEST(TestFlatRequired){
{TFlatRequired proto;
FillFlatProto(&proto);
@@ -150,7 +150,7 @@ const NJson::TJsonValue& modelJson = CreateFlatJson();
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
-
+
{
TStringStream jsonStream;
NJson::TJsonValue json;
@@ -159,7 +159,7 @@ const NJson::TJsonValue& modelJson = CreateFlatJson();
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
} // streamed
}
-
+
// Try to skip each field
#define DEFINE_FIELD(name, value) \
{ \
@@ -179,20 +179,20 @@ const NJson::TJsonValue& modelJson = CreateFlatJson();
} \
}
#include <library/cpp/protobuf/json/ut/fields.incl>
-#undef DEFINE_FIELD
+#undef DEFINE_FIELD
} // TestFlatRequired
-
+
Y_UNIT_TEST(TestFlatRepeated) {
{
TFlatRepeated proto;
FillRepeatedProto(&proto);
const NJson::TJsonValue& modelJson = CreateRepeatedFlatJson();
- {
+ {
NJson::TJsonValue json;
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
- }
-
+ }
+
{
TStringStream jsonStream;
NJson::TJsonValue json;
@@ -224,9 +224,9 @@ Y_UNIT_TEST(TestFlatRepeated) {
} \
}
#include <library/cpp/protobuf/json/ut/repeated_fields.incl>
-#undef DEFINE_REPEATED_FIELD
+#undef DEFINE_REPEATED_FIELD
} // TestFlatRepeated
-
+
Y_UNIT_TEST(TestCompositeOptional){
{TCompositeOptional proto;
FillCompositeProto(&proto);
@@ -236,7 +236,7 @@ const NJson::TJsonValue& modelJson = CreateCompositeJson();
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
-
+
{
TStringStream jsonStream;
NJson::TJsonValue json;
@@ -245,7 +245,7 @@ const NJson::TJsonValue& modelJson = CreateCompositeJson();
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
} // streamed
}
-
+
// Try to skip each field
#define DEFINE_FIELD(name, value) \
{ \
@@ -265,9 +265,9 @@ const NJson::TJsonValue& modelJson = CreateCompositeJson();
} \
}
#include <library/cpp/protobuf/json/ut/fields.incl>
-#undef DEFINE_FIELD
+#undef DEFINE_FIELD
} // TestCompositeOptional
-
+
Y_UNIT_TEST(TestCompositeRequired){
{TCompositeRequired proto;
FillCompositeProto(&proto);
@@ -277,7 +277,7 @@ const NJson::TJsonValue& modelJson = CreateCompositeJson();
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
-
+
{
TStringStream jsonStream;
NJson::TJsonValue json;
@@ -286,7 +286,7 @@ const NJson::TJsonValue& modelJson = CreateCompositeJson();
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
} // streamed
}
-
+
// Try to skip each field
#define DEFINE_FIELD(name, value) \
{ \
@@ -306,9 +306,9 @@ const NJson::TJsonValue& modelJson = CreateCompositeJson();
} \
}
#include <library/cpp/protobuf/json/ut/fields.incl>
-#undef DEFINE_FIELD
+#undef DEFINE_FIELD
} // TestCompositeRequired
-
+
Y_UNIT_TEST(TestCompositeRepeated) {
{
TFlatOptional partProto;
@@ -320,13 +320,13 @@ Y_UNIT_TEST(TestCompositeRepeated) {
NJson::TJsonValue modelArray;
modelArray.AppendValue(CreateFlatJson());
modelJson.InsertValue("Part", modelArray);
- {
+ {
NJson::TJsonValue json;
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
- }
-
- {
+ }
+
+ {
TStringStream jsonStream;
NJson::TJsonValue json;
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStream));
@@ -334,7 +334,7 @@ Y_UNIT_TEST(TestCompositeRepeated) {
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
} // streamed
}
-
+
{
// Array of messages with each field skipped
TCompositeRepeated proto;
@@ -350,27 +350,27 @@ Y_UNIT_TEST(TestCompositeRepeated) {
modelArray.AppendValue(CreateFlatJson(skippedField)); \
}
#include <library/cpp/protobuf/json/ut/repeated_fields.incl>
-#undef DEFINE_REPEATED_FIELD
-
+#undef DEFINE_REPEATED_FIELD
+
NJson::TJsonValue modelJson;
modelJson.InsertValue("Part", modelArray);
-
- {
- NJson::TJsonValue json;
+
+ {
+ NJson::TJsonValue json;
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
- }
-
- {
+ }
+
+ {
TStringStream jsonStream;
- NJson::TJsonValue json;
+ NJson::TJsonValue json;
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStream));
UNIT_ASSERT(ReadJsonTree(&jsonStream, &json));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
} // streamed
}
} // TestCompositeRepeated
-
+
Y_UNIT_TEST(TestEnumConfig) {
{
TFlatOptional proto;
@@ -380,11 +380,11 @@ Y_UNIT_TEST(TestEnumConfig) {
NJson::TJsonValue json;
TProto2JsonConfig config;
config.EnumMode = TProto2JsonConfig::EnumNumber;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
-
+
{
TFlatOptional proto;
proto.SetEnum(E_1);
@@ -393,11 +393,11 @@ Y_UNIT_TEST(TestEnumConfig) {
NJson::TJsonValue json;
TProto2JsonConfig config;
config.EnumMode = TProto2JsonConfig::EnumName;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
-
+
{
TFlatOptional proto;
proto.SetEnum(E_1);
@@ -406,11 +406,11 @@ Y_UNIT_TEST(TestEnumConfig) {
NJson::TJsonValue json;
TProto2JsonConfig config;
config.EnumMode = TProto2JsonConfig::EnumFullName;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
-
+
{
TFlatOptional proto;
proto.SetEnum(E_1);
@@ -419,11 +419,11 @@ Y_UNIT_TEST(TestEnumConfig) {
NJson::TJsonValue json;
TProto2JsonConfig config;
config.EnumMode = TProto2JsonConfig::EnumNameLowerCase;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
-
+
{
TFlatOptional proto;
proto.SetEnum(E_1);
@@ -455,13 +455,13 @@ Y_UNIT_TEST(TestMissingSingleKeyConfig) {
#define DEFINE_FIELD(name, value) \
modelJson.InsertValue(#name, NJson::TJsonValue(NJson::JSON_NULL));
#include <library/cpp/protobuf/json/ut/fields.incl>
-#undef DEFINE_FIELD
-
+#undef DEFINE_FIELD
+
TFlatOptional proto;
NJson::TJsonValue json;
TProto2JsonConfig config;
config.MissingSingleKeyMode = TProto2JsonConfig::MissingKeyNull;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
@@ -512,7 +512,7 @@ Y_UNIT_TEST(TestMissingSingleKeyConfig) {
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
} // TestMissingSingleKeyConfig
-
+
Y_UNIT_TEST(TestMissingRepeatedKeyNoConfig) {
{
TFlatRepeated proto;
@@ -531,23 +531,23 @@ Y_UNIT_TEST(TestMissingRepeatedKeyConfig) {
NJson::TJsonValue json;
TProto2JsonConfig config;
config.MissingRepeatedKeyMode = TProto2JsonConfig::MissingKeySkip;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
-
+
{
NJson::TJsonValue modelJson;
#define DEFINE_FIELD(name, value) \
modelJson.InsertValue(#name, NJson::TJsonValue(NJson::JSON_NULL));
#include <library/cpp/protobuf/json/ut/fields.incl>
-#undef DEFINE_FIELD
-
+#undef DEFINE_FIELD
+
TFlatRepeated proto;
NJson::TJsonValue json;
TProto2JsonConfig config;
config.MissingRepeatedKeyMode = TProto2JsonConfig::MissingKeyNull;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, json, config));
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
@@ -563,63 +563,63 @@ Y_UNIT_TEST(TestMissingRepeatedKeyConfig) {
UNIT_ASSERT_JSONS_EQUAL(json, modelJson);
}
} // TestMissingRepeatedKeyConfig
-
+
Y_UNIT_TEST(TestEscaping) {
// No escape
{
TString modelStr(R"_({"String":"value\""})_");
-
+
TFlatOptional proto;
proto.SetString(R"_(value")_");
TStringStream jsonStr;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr));
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
}
-
+
// TEscapeJTransform
{
TString modelStr(R"_({"String":"value\""})_");
-
+
TFlatOptional proto;
proto.SetString(R"_(value")_");
TProto2JsonConfig config;
config.StringTransforms.push_back(new TEscapeJTransform<false, true>());
TStringStream jsonStr;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
UNIT_ASSERT_JSON_STRINGS_EQUAL(modelStr, jsonStr.Str());
}
-
+
// TCEscapeTransform
{
TString modelStr(R"_({"String":"value\""})_");
-
+
TFlatOptional proto;
proto.SetString(R"_(value")_");
TProto2JsonConfig config;
config.StringTransforms.push_back(new TCEscapeTransform());
TStringStream jsonStr;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
}
-
+
// TSafeUtf8CEscapeTransform
{
TString modelStr(R"_({"String":"value\""})_");
-
+
TFlatOptional proto;
proto.SetString(R"_(value")_");
TProto2JsonConfig config;
config.StringTransforms.push_back(new TSafeUtf8CEscapeTransform());
TStringStream jsonStr;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
}
} // TestEscaping
-
+
class TBytesTransform: public IStringTransform {
public:
int GetType() const override {
@@ -666,58 +666,58 @@ Y_UNIT_TEST(TestFieldNameMode) {
// Original case 1
{
TString modelStr(R"_({"String":"value"})_");
-
+
TFlatOptional proto;
proto.SetString("value");
TStringStream jsonStr;
TProto2JsonConfig config;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
}
-
+
// Original case 2
{
TString modelStr(R"_({"String":"value"})_");
-
+
TFlatOptional proto;
proto.SetString("value");
TStringStream jsonStr;
TProto2JsonConfig config;
config.FieldNameMode = TProto2JsonConfig::FieldNameOriginalCase;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
}
-
+
// Lowercase
{
TString modelStr(R"_({"string":"value"})_");
-
+
TFlatOptional proto;
proto.SetString("value");
TStringStream jsonStr;
TProto2JsonConfig config;
config.FieldNameMode = TProto2JsonConfig::FieldNameLowerCase;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
}
-
+
// Uppercase
{
TString modelStr(R"_({"STRING":"value"})_");
-
+
TFlatOptional proto;
proto.SetString("value");
TStringStream jsonStr;
TProto2JsonConfig config;
config.FieldNameMode = TProto2JsonConfig::FieldNameUpperCase;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
}
-
+
// Camelcase
{
TString modelStr(R"_({"string":"value"})_");
@@ -825,33 +825,33 @@ Y_UNIT_TEST(TestFieldNameMode) {
// Original case, repeated
{
TString modelStr(R"_({"I32":[1,2]})_");
-
+
TFlatRepeated proto;
proto.AddI32(1);
proto.AddI32(2);
TStringStream jsonStr;
TProto2JsonConfig config;
config.FieldNameMode = TProto2JsonConfig::FieldNameOriginalCase;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
}
-
+
// Lower case, repeated
{
TString modelStr(R"_({"i32":[1,2]})_");
-
+
TFlatRepeated proto;
proto.AddI32(1);
proto.AddI32(2);
TStringStream jsonStr;
TProto2JsonConfig config;
config.FieldNameMode = TProto2JsonConfig::FieldNameLowerCase;
-
+
UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config));
UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr);
}
-
+
// UseJsonName
{
// FIXME(CONTRIB-139): see the comment about UseJsonName in json2proto_ut.cpp:
@@ -1019,4 +1019,4 @@ Y_UNIT_TEST(TestExtension) {
UNIT_ASSERT_EQUAL(Proto2Json(proto, cfg), "{\"bar\":1}");
} // TestExtension
-} // TProto2JsonTest
+} // TProto2JsonTest
diff --git a/library/cpp/protobuf/json/ut/repeated_fields.incl b/library/cpp/protobuf/json/ut/repeated_fields.incl
index e9548917d8..53c1dc94a7 100644
--- a/library/cpp/protobuf/json/ut/repeated_fields.incl
+++ b/library/cpp/protobuf/json/ut/repeated_fields.incl
@@ -1,21 +1,21 @@
-// Intentionally no #pragma once
-
-// (Field name == JSON key, Type, Values...)
-DEFINE_REPEATED_FIELD(I32, i32, Min<i32>(), -1, 0, 1, Max<i32>())
-DEFINE_REPEATED_FIELD(I64, i64, Min<i64>(), -1ll, 0ll, 1ll, Max<i64>())
-DEFINE_REPEATED_FIELD(UI32, ui32, 0ul, 1ul, Max<ui32>())
-DEFINE_REPEATED_FIELD(UI64, ui64, 0ull, 1ull, Max<ui64>())
-DEFINE_REPEATED_FIELD(SI32, i32, Min<i32>(), -1, 0, 1, Max<i32>())
-DEFINE_REPEATED_FIELD(SI64, i64, Min<i64>(), -1ll, 0ll, 1ll, Max<i64>())
-DEFINE_REPEATED_FIELD(FI32, ui32, 0, 1, Max<ui32>())
-DEFINE_REPEATED_FIELD(FI64, ui64, 0ull, 1ull, Max<ui64>())
-DEFINE_REPEATED_FIELD(SFI32, i32, Min<i32>(), -1, 0, 1, Max<i32>())
-DEFINE_REPEATED_FIELD(SFI64, i64, Min<i64>(), -1ll, 0ll, 1ll, Max<i64>())
-DEFINE_REPEATED_FIELD(Bool, bool, false, true)
+// Intentionally no #pragma once
+
+// (Field name == JSON key, Type, Values...)
+DEFINE_REPEATED_FIELD(I32, i32, Min<i32>(), -1, 0, 1, Max<i32>())
+DEFINE_REPEATED_FIELD(I64, i64, Min<i64>(), -1ll, 0ll, 1ll, Max<i64>())
+DEFINE_REPEATED_FIELD(UI32, ui32, 0ul, 1ul, Max<ui32>())
+DEFINE_REPEATED_FIELD(UI64, ui64, 0ull, 1ull, Max<ui64>())
+DEFINE_REPEATED_FIELD(SI32, i32, Min<i32>(), -1, 0, 1, Max<i32>())
+DEFINE_REPEATED_FIELD(SI64, i64, Min<i64>(), -1ll, 0ll, 1ll, Max<i64>())
+DEFINE_REPEATED_FIELD(FI32, ui32, 0, 1, Max<ui32>())
+DEFINE_REPEATED_FIELD(FI64, ui64, 0ull, 1ull, Max<ui64>())
+DEFINE_REPEATED_FIELD(SFI32, i32, Min<i32>(), -1, 0, 1, Max<i32>())
+DEFINE_REPEATED_FIELD(SFI64, i64, Min<i64>(), -1ll, 0ll, 1ll, Max<i64>())
+DEFINE_REPEATED_FIELD(Bool, bool, false, true)
DEFINE_REPEATED_FIELD(String, TString, "", "Lorem ipsum", "123123")
DEFINE_REPEATED_FIELD(Bytes, TString, "", "מחשב", "\x1")
-DEFINE_REPEATED_FIELD(Enum, EEnum, E_1, E_2, E_3)
-DEFINE_REPEATED_FIELD(Float, float, 0.0f, 1.0f, 1.123f)
-DEFINE_REPEATED_FIELD(Double, double, 0.0, 1.0, 1.123456789012)
+DEFINE_REPEATED_FIELD(Enum, EEnum, E_1, E_2, E_3)
+DEFINE_REPEATED_FIELD(Float, float, 0.0f, 1.0f, 1.123f)
+DEFINE_REPEATED_FIELD(Double, double, 0.0, 1.0, 1.123456789012)
DEFINE_REPEATED_FIELD(OneString, TString, "", "Lorem ipsum dolor", "1231231")
DEFINE_REPEATED_FIELD(OneTwoString, TString, "", "Lorem ipsum dolor sit", "12312312")
diff --git a/library/cpp/protobuf/json/ut/test.proto b/library/cpp/protobuf/json/ut/test.proto
index 0fa996fd41..fab7b6a5f2 100644
--- a/library/cpp/protobuf/json/ut/test.proto
+++ b/library/cpp/protobuf/json/ut/test.proto
@@ -1,96 +1,96 @@
-package NProtobufJsonTest;
-
-enum EEnum {
+package NProtobufJsonTest;
+
+enum EEnum {
E_0 = 0;
- E_1 = 1;
- E_2 = 2;
- E_3 = 3;
-};
-
-message TFlatOptional {
- optional int32 I32 = 1;
- optional int64 I64 = 2;
- optional uint32 UI32 = 3;
- optional uint64 UI64 = 4;
- optional sint32 SI32 = 5;
- optional sint64 SI64 = 6;
- optional fixed32 FI32 = 7;
- optional fixed64 FI64 = 8;
- optional sfixed32 SFI32 = 9;
- optional sfixed64 SFI64 = 10;
-
- optional bool Bool = 11;
-
- optional string String = 12;
- optional bytes Bytes = 13;
-
- optional EEnum Enum = 14;
-
- optional float Float = 15;
- optional double Double = 16;
+ E_1 = 1;
+ E_2 = 2;
+ E_3 = 3;
+};
+
+message TFlatOptional {
+ optional int32 I32 = 1;
+ optional int64 I64 = 2;
+ optional uint32 UI32 = 3;
+ optional uint64 UI64 = 4;
+ optional sint32 SI32 = 5;
+ optional sint64 SI64 = 6;
+ optional fixed32 FI32 = 7;
+ optional fixed64 FI64 = 8;
+ optional sfixed32 SFI32 = 9;
+ optional sfixed64 SFI64 = 10;
+
+ optional bool Bool = 11;
+
+ optional string String = 12;
+ optional bytes Bytes = 13;
+
+ optional EEnum Enum = 14;
+
+ optional float Float = 15;
+ optional double Double = 16;
optional string OneString = 17;
optional string OneTwoString = 18;
optional string ABC = 19;
optional string UserID = 20;
-};
-
-message TFlatRequired {
- required int32 I32 = 1;
- required int64 I64 = 2;
- required uint32 UI32 = 3;
- required uint64 UI64 = 4;
- required sint32 SI32 = 5;
- required sint64 SI64 = 6;
- required fixed32 FI32 = 7;
- required fixed64 FI64 = 8;
- required sfixed32 SFI32 = 9;
- required sfixed64 SFI64 = 10;
-
- required bool Bool = 11;
-
- required string String = 12;
- required bytes Bytes = 13;
-
- required EEnum Enum = 14;
-
- required float Float = 15;
- required double Double = 16;
+};
+
+message TFlatRequired {
+ required int32 I32 = 1;
+ required int64 I64 = 2;
+ required uint32 UI32 = 3;
+ required uint64 UI64 = 4;
+ required sint32 SI32 = 5;
+ required sint64 SI64 = 6;
+ required fixed32 FI32 = 7;
+ required fixed64 FI64 = 8;
+ required sfixed32 SFI32 = 9;
+ required sfixed64 SFI64 = 10;
+
+ required bool Bool = 11;
+
+ required string String = 12;
+ required bytes Bytes = 13;
+
+ required EEnum Enum = 14;
+
+ required float Float = 15;
+ required double Double = 16;
required string OneString = 17;
required string OneTwoString = 18;
required string ABC = 19;
required string UserID = 20;
-};
-
-message TFlatRepeated {
- repeated int32 I32 = 1;
- repeated int64 I64 = 2;
- repeated uint32 UI32 = 3;
- repeated uint64 UI64 = 4;
- repeated sint32 SI32 = 5;
- repeated sint64 SI64 = 6;
- repeated fixed32 FI32 = 7;
- repeated fixed64 FI64 = 8;
- repeated sfixed32 SFI32 = 9;
- repeated sfixed64 SFI64 = 10;
-
- repeated bool Bool = 11;
-
- repeated string String = 12;
- repeated bytes Bytes = 13;
-
- repeated EEnum Enum = 14;
-
- repeated float Float = 15;
- repeated double Double = 16;
+};
+
+message TFlatRepeated {
+ repeated int32 I32 = 1;
+ repeated int64 I64 = 2;
+ repeated uint32 UI32 = 3;
+ repeated uint64 UI64 = 4;
+ repeated sint32 SI32 = 5;
+ repeated sint64 SI64 = 6;
+ repeated fixed32 FI32 = 7;
+ repeated fixed64 FI64 = 8;
+ repeated sfixed32 SFI32 = 9;
+ repeated sfixed64 SFI64 = 10;
+
+ repeated bool Bool = 11;
+
+ repeated string String = 12;
+ repeated bytes Bytes = 13;
+
+ repeated EEnum Enum = 14;
+
+ repeated float Float = 15;
+ repeated double Double = 16;
repeated string OneString = 17;
repeated string OneTwoString = 18;
repeated string ABC = 19;
repeated string UserID = 20;
-};
-
+};
+
message TFlatDefault {
optional int32 I32 = 1 [default = 132];
optional int64 I64 = 2 [default = 164];
@@ -119,17 +119,17 @@ message TFlatDefault {
optional string UserID = 20 [default = "some_id"];
};
-message TCompositeOptional {
- optional TFlatOptional Part = 1;
-};
-
-message TCompositeRequired {
- required TFlatRequired Part = 1;
-};
-
-message TCompositeRepeated {
- repeated TFlatOptional Part = 1;
-};
+message TCompositeOptional {
+ optional TFlatOptional Part = 1;
+};
+
+message TCompositeRequired {
+ required TFlatRequired Part = 1;
+};
+
+message TCompositeRepeated {
+ repeated TFlatOptional Part = 1;
+};
message TMapType {
map<string, string> Items = 1;
diff --git a/library/cpp/protobuf/json/ut/ya.make b/library/cpp/protobuf/json/ut/ya.make
index b60a6d3c17..8f224e22fa 100644
--- a/library/cpp/protobuf/json/ut/ya.make
+++ b/library/cpp/protobuf/json/ut/ya.make
@@ -1,23 +1,23 @@
UNITTEST_FOR(library/cpp/protobuf/json)
-
+
OWNER(avitella)
-SRCS(
+SRCS(
filter_ut.cpp
- json2proto_ut.cpp
- proto2json_ut.cpp
+ json2proto_ut.cpp
+ proto2json_ut.cpp
inline_ut.proto
inline_ut.cpp
string_transform_ut.cpp
filter_ut.proto
test.proto
util_ut.cpp
-)
-
+)
+
GENERATE_ENUM_SERIALIZATION(test.pb.h)
PEERDIR(
library/cpp/protobuf/json
)
-
-END()
+
+END()
diff --git a/library/cpp/protobuf/json/ya.make b/library/cpp/protobuf/json/ya.make
index 2f2c75cfdb..49e073c89b 100644
--- a/library/cpp/protobuf/json/ya.make
+++ b/library/cpp/protobuf/json/ya.make
@@ -1,25 +1,25 @@
-LIBRARY()
-
+LIBRARY()
+
OWNER(avitella)
-
-SRCS(
- json2proto.cpp
+
+SRCS(
+ json2proto.cpp
json_output_create.cpp
json_value_output.cpp
json_writer_output.cpp
name_generator.cpp
proto2json.cpp
proto2json_printer.cpp
- string_transform.cpp
+ string_transform.cpp
util.h
util.cpp
-)
-
-PEERDIR(
- contrib/libs/protobuf
+)
+
+PEERDIR(
+ contrib/libs/protobuf
library/cpp/json
library/cpp/protobuf/util
library/cpp/string_utils/relaxed_escaper
-)
-
-END()
+)
+
+END()
diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h
index 44517a0092..8fa8befec3 100644
--- a/library/cpp/testing/unittest/registar.h
+++ b/library/cpp/testing/unittest/registar.h
@@ -654,7 +654,7 @@ public: \
UNIT_FAIL_IMPL("exception-free assertion failed", Sprintf("%s throws %s\nException message: %s", #A, (::TStringBuilder() << C).data(), CurrentExceptionMessage().data())); \
} \
} while (false)
-
+
#define UNIT_ASSERT_NO_EXCEPTION(A) UNIT_ASSERT_NO_EXCEPTION_C(A, "")
namespace NPrivate {