diff options
author | alexcrush <alexcrush@yandex-team.ru> | 2022-02-10 16:50:33 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:33 +0300 |
commit | 34f0683c2d7731f2f9f59966c12e602f405fa0d6 (patch) | |
tree | 9af7dd74efcfa3d8aa7b40bd757ad8f2d89f6902 | |
parent | a1d67d6a31f789aa011250c3edce5751c0cadad2 (diff) | |
download | ydb-34f0683c2d7731f2f9f59966c12e602f405fa0d6.tar.gz |
Restoring authorship annotation for <alexcrush@yandex-team.ru>. Commit 1 of 2.
-rw-r--r-- | library/cpp/messagebus/handler.cpp | 6 | ||||
-rw-r--r-- | library/cpp/messagebus/handler.h | 2 | ||||
-rw-r--r-- | library/cpp/messagebus/oldmodule/module.cpp | 14 | ||||
-rw-r--r-- | library/cpp/messagebus/remote_connection.h | 2 | ||||
-rw-r--r-- | library/cpp/messagebus/test/ut/messagebus_ut.cpp | 108 | ||||
-rw-r--r-- | library/cpp/protobuf/json/json2proto.cpp | 94 | ||||
-rw-r--r-- | library/cpp/protobuf/json/json2proto.h | 18 | ||||
-rw-r--r-- | library/cpp/protobuf/json/string_transform.h | 2 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/json2proto_ut.cpp | 64 | ||||
-rw-r--r-- | library/cpp/protobuf/json/ut/proto2json_ut.cpp | 16 | ||||
-rw-r--r-- | util/stream/zlib.cpp | 32 | ||||
-rw-r--r-- | util/stream/zlib.h | 20 | ||||
-rw-r--r-- | util/stream/zlib_ut.cpp | 62 |
13 files changed, 220 insertions, 220 deletions
diff --git a/library/cpp/messagebus/handler.cpp b/library/cpp/messagebus/handler.cpp index 333bd52934..4f40db8776 100644 --- a/library/cpp/messagebus/handler.cpp +++ b/library/cpp/messagebus/handler.cpp @@ -30,7 +30,7 @@ void TOnMessageContext::ForgetRequest() { TNetAddr TOnMessageContext::GetPeerAddrNetAddr() const { return Ident.GetNetAddr(); } - -bool TOnMessageContext::IsConnectionAlive() const { + +bool TOnMessageContext::IsConnectionAlive() const { return !!Ident.Connection && Ident.Connection->IsAlive(); -} +} diff --git a/library/cpp/messagebus/handler.h b/library/cpp/messagebus/handler.h index 60002c68a6..21b39a20bc 100644 --- a/library/cpp/messagebus/handler.h +++ b/library/cpp/messagebus/handler.h @@ -113,7 +113,7 @@ namespace NBus { } TNetAddr GetPeerAddrNetAddr() const; - + bool IsConnectionAlive() const; }; diff --git a/library/cpp/messagebus/oldmodule/module.cpp b/library/cpp/messagebus/oldmodule/module.cpp index 24bd778799..6917b893c3 100644 --- a/library/cpp/messagebus/oldmodule/module.cpp +++ b/library/cpp/messagebus/oldmodule/module.cpp @@ -209,7 +209,7 @@ namespace NBus { { } }; - + struct TJobRunner: public TAtomicRefCount<TJobRunner>, public NActor::TActor<TJobRunner>, public NActor::TQueueInActor<TJobRunner, TJobResponseMessage>, @@ -759,8 +759,8 @@ TBusSession* TMyModule::CreateExtSession(TBusMessageQueue& queue) { return strReturn; } -} - +} + void TBusModuleImpl::AddJob(TJobRunner* jobRunner) { TWhatThreadDoesAcquireGuard<TMutex> G(Lock, "modules: acquiring lock for AddJob"); Jobs.push_back(jobRunner); @@ -875,7 +875,7 @@ void TModuleClientHandler::OnError(TAutoPtr<TBusMessage> msg, EMessageStatus sta job->UnRef(); } } - -void TModuleClientHandler::OnClientConnectionEvent(const TClientConnectionEvent& event) { - Module->OnClientConnectionEvent(event); -} + +void TModuleClientHandler::OnClientConnectionEvent(const TClientConnectionEvent& event) { + Module->OnClientConnectionEvent(event); +} diff --git a/library/cpp/messagebus/remote_connection.h b/library/cpp/messagebus/remote_connection.h index 4538947368..719dbe5f3d 100644 --- a/library/cpp/messagebus/remote_connection.h +++ b/library/cpp/messagebus/remote_connection.h @@ -204,7 +204,7 @@ namespace NBus { struct TWriterData { TAtomic Down; - + NEventLoop::TChannelPtr Channel; ui32 SocketVersion; diff --git a/library/cpp/messagebus/test/ut/messagebus_ut.cpp b/library/cpp/messagebus/test/ut/messagebus_ut.cpp index 040f9b7702..4fef8d5ba6 100644 --- a/library/cpp/messagebus/test/ut/messagebus_ut.cpp +++ b/library/cpp/messagebus/test/ut/messagebus_ut.cpp @@ -310,7 +310,7 @@ Y_UNIT_TEST_SUITE(TMessageBusTests) { TExampleProtocol Proto; TSystemEvent MessageReceivedEvent; // 1 wait for 1 message TBusServerSessionPtr Session; - TMutex Lock_; + TMutex Lock_; TDeque<TAutoPtr<TOnMessageContext>> DelayedMessages; TDelayReplyServer() @@ -328,52 +328,52 @@ Y_UNIT_TEST_SUITE(TMessageBusTests) { void OnMessage(TOnMessageContext& mess) override { Y_VERIFY(mess.IsConnectionAlive(), "connection should be alive here"); - TAutoPtr<TOnMessageContext> delayedMsg(new TOnMessageContext); - delayedMsg->Swap(mess); - auto g(Guard(Lock_)); - DelayedMessages.push_back(delayedMsg); + TAutoPtr<TOnMessageContext> delayedMsg(new TOnMessageContext); + delayedMsg->Swap(mess); + auto g(Guard(Lock_)); + DelayedMessages.push_back(delayedMsg); MessageReceivedEvent.Signal(); - } + } - bool CheckClientIsAlive() { - auto g(Guard(Lock_)); + bool CheckClientIsAlive() { + auto g(Guard(Lock_)); for (auto& delayedMessage : DelayedMessages) { if (!delayedMessage->IsConnectionAlive()) { - return false; - } - } - return true; - } - - bool CheckClientIsDead() const { - auto g(Guard(Lock_)); + return false; + } + } + return true; + } + + bool CheckClientIsDead() const { + auto g(Guard(Lock_)); for (const auto& delayedMessage : DelayedMessages) { if (delayedMessage->IsConnectionAlive()) { - return false; - } - } - return true; - } - - void ReplyToDelayedMessages() { - while (true) { - TOnMessageContext msg; - { - auto g(Guard(Lock_)); - if (DelayedMessages.empty()) { - break; - } - DelayedMessages.front()->Swap(msg); - DelayedMessages.pop_front(); - } - TAutoPtr<TBusMessage> reply(new TExampleResponse(&Proto.ResponseCount)); - msg.SendReplyMove(reply); - } - } - - size_t GetDelayedMessageCount() const { - auto g(Guard(Lock_)); - return DelayedMessages.size(); + return false; + } + } + return true; + } + + void ReplyToDelayedMessages() { + while (true) { + TOnMessageContext msg; + { + auto g(Guard(Lock_)); + if (DelayedMessages.empty()) { + break; + } + DelayedMessages.front()->Swap(msg); + DelayedMessages.pop_front(); + } + TAutoPtr<TBusMessage> reply(new TExampleResponse(&Proto.ResponseCount)); + msg.SendReplyMove(reply); + } + } + + size_t GetDelayedMessageCount() const { + auto g(Guard(Lock_)); + return DelayedMessages.size(); } void OnError(TAutoPtr<TBusMessage> mess, EMessageStatus status) override { @@ -397,10 +397,10 @@ Y_UNIT_TEST_SUITE(TMessageBusTests) { client.Destroy(); - UNIT_WAIT_FOR(server.CheckClientIsDead()); - - server.ReplyToDelayedMessages(); + UNIT_WAIT_FOR(server.CheckClientIsDead()); + server.ReplyToDelayedMessages(); + // wait until all server message are delivered UNIT_WAIT_FOR(0 == server.Session->GetInFlight()); } @@ -654,23 +654,23 @@ Y_UNIT_TEST_SUITE(TMessageBusTests) { client.SendMessages(2, &addr); - for (size_t i = 0; i < 5; ++i) { - // One MessageReceivedEvent indicates one message, we need to wait for two - UNIT_ASSERT(server.MessageReceivedEvent.WaitT(TDuration::Seconds(5))); - if (server.GetDelayedMessageCount() == 2) { - break; - } - } + for (size_t i = 0; i < 5; ++i) { + // One MessageReceivedEvent indicates one message, we need to wait for two + UNIT_ASSERT(server.MessageReceivedEvent.WaitT(TDuration::Seconds(5))); + if (server.GetDelayedMessageCount() == 2) { + break; + } + } UNIT_ASSERT_VALUES_EQUAL(server.GetDelayedMessageCount(), 2); size_t inFlight = client.Session->GetInFlight(addr); // 4 is for messagebus1 that adds inFlight counter twice for some reason UNIT_ASSERT(inFlight == 2 || inFlight == 4); - UNIT_ASSERT(server.CheckClientIsAlive()); - - server.ReplyToDelayedMessages(); + UNIT_ASSERT(server.CheckClientIsAlive()); + server.ReplyToDelayedMessages(); + client.WaitReplies(); } diff --git a/library/cpp/protobuf/json/json2proto.cpp b/library/cpp/protobuf/json/json2proto.cpp index 640c10f5a5..dbbd07e002 100644 --- a/library/cpp/protobuf/json/json2proto.cpp +++ b/library/cpp/protobuf/json/json2proto.cpp @@ -51,15 +51,15 @@ static TString GetFieldName(const google::protobuf::FieldDescriptor& field, } TString name = field.name(); - switch (config.FieldNameMode) { - case NProtobufJson::TJson2ProtoConfig::FieldNameOriginalCase: - break; - case NProtobufJson::TJson2ProtoConfig::FieldNameLowerCase: - name.to_lower(); - break; - case NProtobufJson::TJson2ProtoConfig::FieldNameUpperCase: - name.to_upper(); - break; + switch (config.FieldNameMode) { + case NProtobufJson::TJson2ProtoConfig::FieldNameOriginalCase: + break; + case NProtobufJson::TJson2ProtoConfig::FieldNameLowerCase: + name.to_lower(); + break; + case NProtobufJson::TJson2ProtoConfig::FieldNameUpperCase: + name.to_upper(); + break; case NProtobufJson::TJson2ProtoConfig::FieldNameCamelCase: if (!name.empty()) { name[0] = AsciiToLower(name[0]); @@ -73,43 +73,43 @@ static TString GetFieldName(const google::protobuf::FieldDescriptor& field, break; default: Y_VERIFY_DEBUG(false, "Unknown FieldNameMode."); - } - return name; -} - + } + return name; +} + static void -JsonString2Field(const NJson::TJsonValue& json, - google::protobuf::Message& proto, - const google::protobuf::FieldDescriptor& field, +JsonString2Field(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); - + if (!json.IsString() && !config.CastRobust) { ythrow yexception() << "Invalid type of JSON field '" << field.name() << "': " - << "IsString() failed while " - << "CPPTYPE_STRING is expected."; - } + << "IsString() failed while " + << "CPPTYPE_STRING is expected."; + } TString value = json.GetStringRobust(); - for (size_t i = 0, endI = config.StringTransforms.size(); i < endI; ++i) { + for (size_t i = 0, endI = config.StringTransforms.size(); i < endI; ++i) { Y_ASSERT(!!config.StringTransforms[i]); - if (!!config.StringTransforms[i]) { - if (field.type() == google::protobuf::FieldDescriptor::TYPE_BYTES) { - config.StringTransforms[i]->TransformBytes(value); - } else { - config.StringTransforms[i]->Transform(value); - } - } - } - - if (field.is_repeated()) - reflection->AddString(&proto, &field, value); - else - reflection->SetString(&proto, &field, value); -} - + if (!!config.StringTransforms[i]) { + if (field.type() == google::protobuf::FieldDescriptor::TYPE_BYTES) { + config.StringTransforms[i]->TransformBytes(value); + } else { + config.StringTransforms[i]->Transform(value); + } + } + } + + if (field.is_repeated()) + reflection->AddString(&proto, &field, value); + else + reflection->SetString(&proto, &field, value); +} + static const NProtoBuf::EnumValueDescriptor* FindEnumValue(const NProtoBuf::EnumDescriptor* enumField, TStringBuf target, bool (*equals)(TStringBuf, TStringBuf)) { @@ -122,7 +122,7 @@ FindEnumValue(const NProtoBuf::EnumDescriptor* enumField, return nullptr; } -static void +static void JsonEnum2Field(const NJson::TJsonValue& json, google::protobuf::Message& proto, const google::protobuf::FieldDescriptor& field, @@ -170,7 +170,7 @@ JsonEnum2Field(const NJson::TJsonValue& json, static void Json2SingleField(const NJson::TJsonValue& json, google::protobuf::Message& proto, - const google::protobuf::FieldDescriptor& field, + const google::protobuf::FieldDescriptor& field, const NProtobufJson::TJson2ProtoConfig& config, bool isMapValue = false) { using namespace google::protobuf; @@ -206,7 +206,7 @@ Json2SingleField(const NJson::TJsonValue& json, JsonString2Field(fieldJson, proto, field, config); break; } - + case FieldDescriptor::CPPTYPE_ENUM: { JsonEnum2Field(fieldJson, proto, field, config); break; @@ -314,15 +314,15 @@ Json2RepeatedFieldValue(const NJson::TJsonValue& jsonValue, static void Json2RepeatedField(const NJson::TJsonValue& json, google::protobuf::Message& proto, - const google::protobuf::FieldDescriptor& field, + const google::protobuf::FieldDescriptor& field, const NProtobufJson::TJson2ProtoConfig& config) { using namespace google::protobuf; TString name = GetFieldName(field, config); - if (!json.Has(name)) + if (!json.Has(name)) return; - const NJson::TJsonValue& fieldJson = json[name]; + const NJson::TJsonValue& fieldJson = json[name]; if (fieldJson.GetType() == NJson::JSON_UNDEFINED || fieldJson.GetType() == NJson::JSON_NULL) return; @@ -337,7 +337,7 @@ 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 " - << name + << name << "(actual type is " << static_cast<int>(fieldJson.GetType()) << ")."; } @@ -351,7 +351,7 @@ Json2RepeatedField(const NJson::TJsonValue& json, const TString& key = x.first; const NJson::TJsonValue& jsonValue = x.second; Json2RepeatedFieldValue(jsonValue, proto, field, config, reflection, key); - } + } } else { if (config.ReplaceRepeatedFields) { reflection->ClearField(&proto, &field); diff --git a/library/cpp/protobuf/json/json2proto.h b/library/cpp/protobuf/json/json2proto.h index 4c33498dfa..ac4e941fae 100644 --- a/library/cpp/protobuf/json/json2proto.h +++ b/library/cpp/protobuf/json/json2proto.h @@ -1,8 +1,8 @@ #pragma once -#include "string_transform.h" +#include "string_transform.h" #include "name_generator.h" - + #include <library/cpp/json/json_reader.h> #include <library/cpp/json/json_value.h> @@ -29,25 +29,25 @@ namespace NProtobufJson { FieldNameSnakeCase, // ABC -> a_b_c, UserID -> user_i_d FieldNameSnakeCaseDense // ABC -> abc, UserID -> user_id }; - + enum EnumValueMode { EnumCaseSensetive = 0, // default EnumCaseInsensetive, EnumSnakeCaseInsensitive }; - + TSelf& SetFieldNameMode(FldNameMode mode) { Y_ENSURE(mode == FieldNameOriginalCase || !UseJsonName, "FieldNameMode and UseJsonName are mutually exclusive"); FieldNameMode = mode; return *this; } - + TSelf& SetUseJsonName(bool jsonName) { Y_ENSURE(!jsonName || FieldNameMode == FieldNameOriginalCase, "FieldNameMode and UseJsonName are mutually exclusive"); UseJsonName = jsonName; return *this; } - + TSelf& AddStringTransform(TStringTransformPtr transform) { StringTransforms.push_back(transform); return *this; @@ -57,7 +57,7 @@ namespace NProtobufJson { CastFromString = cast; return *this; } - + TSelf& SetDoNotCastEmptyStrings(bool cast) { DoNotCastEmptyStrings = cast; return *this; @@ -109,7 +109,7 @@ namespace NProtobufJson { /// Use 'json_name' protobuf option for field name, mutually exclusive /// with FieldNameMode. bool UseJsonName = false; - + /// Transforms will be applied only to string values (== protobuf fields of string / bytes type). TVector<TStringTransformPtr> StringTransforms; @@ -163,7 +163,7 @@ namespace NProtobufJson { /// @throw yexception void Json2Proto(const NJson::TJsonValue& json, google::protobuf::Message& proto, const TJson2ProtoConfig& config = TJson2ProtoConfig()); - + /// @throw yexception void Json2Proto(const TStringBuf& json, google::protobuf::Message& proto, const TJson2ProtoConfig& config = TJson2ProtoConfig()); diff --git a/library/cpp/protobuf/json/string_transform.h b/library/cpp/protobuf/json/string_transform.h index e4b296bc01..1f1859514b 100644 --- a/library/cpp/protobuf/json/string_transform.h +++ b/library/cpp/protobuf/json/string_transform.h @@ -27,7 +27,7 @@ namespace NProtobufJson { return Transform(str); } }; - + using TStringTransformPtr = TIntrusivePtr<IStringTransform>; template <bool quote, bool tounicode> diff --git a/library/cpp/protobuf/json/ut/json2proto_ut.cpp b/library/cpp/protobuf/json/ut/json2proto_ut.cpp index 0dfe57bc7a..c659cfcc50 100644 --- a/library/cpp/protobuf/json/ut/json2proto_ut.cpp +++ b/library/cpp/protobuf/json/ut/json2proto_ut.cpp @@ -317,55 +317,55 @@ Y_UNIT_TEST(TestInvalidEnum) { UNIT_ASSERT_EXCEPTION(Json2Proto(json, proto), yexception); } } - + Y_UNIT_TEST(TestFieldNameMode) { // Original case 1 { TString modelStr(R"_({"String":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value"); } - + // Original case 2 { TString modelStr(R"_({"String":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameOriginalCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value"); } - + // Lowercase { TString modelStr(R"_({"string":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameLowerCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value"); } - + // Uppercase { TString modelStr(R"_({"STRING":"value"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameUpperCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value"); } - + // Camelcase { TString modelStr(R"_({"string":"value"})_"); @@ -433,25 +433,25 @@ Y_UNIT_TEST(TestFieldNameMode) { // Original case, repeated { TString modelStr(R"_({"I32":[1,2]})_"); - + TFlatRepeated proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameOriginalCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatRepeated>(modelStr, config)); UNIT_ASSERT(proto.I32Size() == 2); UNIT_ASSERT(proto.GetI32(0) == 1); UNIT_ASSERT(proto.GetI32(1) == 2); } - + // Lower case, repeated { TString modelStr(R"_({"i32":[1,2]})_"); - + TFlatRepeated proto; TJson2ProtoConfig config; config.FieldNameMode = TJson2ProtoConfig::FieldNameLowerCase; - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatRepeated>(modelStr, config)); UNIT_ASSERT(proto.I32Size() == 2); UNIT_ASSERT(proto.GetI32(0) == 1); @@ -491,7 +491,7 @@ Y_UNIT_TEST(TestFieldNameMode) { config.SetFieldNameMode(TJson2ProtoConfig::FieldNameLowerCase), yexception, "mutually exclusive"); } } // TestFieldNameMode - + class TStringTransform: public IStringTransform { public: int GetType() const override { @@ -501,7 +501,7 @@ public: str = "transformed_any"; } }; - + class TBytesTransform: public IStringTransform { public: int GetType() const override { @@ -519,7 +519,7 @@ Y_UNIT_TEST(TestInvalidJson) { TFlatOptional proto; UNIT_ASSERT_EXCEPTION(Json2Proto(val, proto), yexception); } - + Y_UNIT_TEST(TestInvalidRepeatedFieldWithMapAsObject) { TCompositeRepeated proto; TJson2ProtoConfig config; @@ -531,37 +531,37 @@ Y_UNIT_TEST(TestStringTransforms) { // Check that strings and bytes are transformed { TString modelStr(R"_({"String":"value_str", "Bytes": "value_bytes"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.AddStringTransform(new TStringTransform); - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "transformed_any"); UNIT_ASSERT(proto.GetBytes() == "transformed_any"); } - + // Check that bytes are transformed, strings are left intact { TString modelStr(R"_({"String":"value_str", "Bytes": "value_bytes"})_"); - + TFlatOptional proto; TJson2ProtoConfig config; config.AddStringTransform(new TBytesTransform); - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatOptional>(modelStr, config)); UNIT_ASSERT(proto.GetString() == "value_str"); UNIT_ASSERT(proto.GetBytes() == "transformed_bytes"); } - + // Check that repeated bytes are transformed, repeated strings are left intact { TString modelStr(R"_({"String":["value_str", "str2"], "Bytes": ["value_bytes", "bytes2"]})_"); - + TFlatRepeated proto; TJson2ProtoConfig config; config.AddStringTransform(new TBytesTransform); - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TFlatRepeated>(modelStr, config)); UNIT_ASSERT(proto.StringSize() == 2); UNIT_ASSERT(proto.GetString(0) == "value_str"); @@ -570,15 +570,15 @@ Y_UNIT_TEST(TestStringTransforms) { UNIT_ASSERT(proto.GetBytes(0) == "transformed_bytes"); UNIT_ASSERT(proto.GetBytes(1) == "transformed_bytes"); } - + // Check that bytes are transformed, strings are left intact in composed messages { TString modelStr(R"_({"Part": {"String":"value_str", "Bytes": "value_bytes"}})_"); - + TCompositeOptional proto; TJson2ProtoConfig config; config.AddStringTransform(new TBytesTransform); - + UNIT_ASSERT_NO_EXCEPTION(proto = Json2Proto<TCompositeOptional>(modelStr, config)); UNIT_ASSERT(proto.GetPart().GetString() == "value_str"); UNIT_ASSERT(proto.GetPart().GetBytes() == "transformed_bytes"); diff --git a/library/cpp/protobuf/json/ut/proto2json_ut.cpp b/library/cpp/protobuf/json/ut/proto2json_ut.cpp index 07e52d7f2f..31264e4a74 100644 --- a/library/cpp/protobuf/json/ut/proto2json_ut.cpp +++ b/library/cpp/protobuf/json/ut/proto2json_ut.cpp @@ -631,37 +631,37 @@ public: str = "bytes"; } }; - + Y_UNIT_TEST(TestBytesTransform) { // Test that string field is not changed { TString modelStr(R"_({"String":"value"})_"); - + TFlatOptional proto; proto.SetString(R"_(value)_"); TProto2JsonConfig config; config.StringTransforms.push_back(new TBytesTransform()); TStringStream jsonStr; - + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config)); UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr); } - + // Test that bytes field is changed { TString modelStr(R"_({"Bytes":"bytes"})_"); - + TFlatOptional proto; proto.SetBytes(R"_(value)_"); TProto2JsonConfig config; config.StringTransforms.push_back(new TBytesTransform()); TStringStream jsonStr; - + UNIT_ASSERT_NO_EXCEPTION(Proto2Json(proto, jsonStr, config)); UNIT_ASSERT_JSON_STRINGS_EQUAL(jsonStr.Str(), modelStr); - } + } } - + Y_UNIT_TEST(TestFieldNameMode) { // Original case 1 { diff --git a/util/stream/zlib.cpp b/util/stream/zlib.cpp index 60f4e9439f..cb45dd1e39 100644 --- a/util/stream/zlib.cpp +++ b/util/stream/zlib.cpp @@ -97,10 +97,10 @@ public: inflateEnd(Z()); } - void SetAllowMultipleStreams(bool allowMultipleStreams) { - AllowMultipleStreams_ = allowMultipleStreams; - } - + void SetAllowMultipleStreams(bool allowMultipleStreams) { + AllowMultipleStreams_ = allowMultipleStreams; + } + inline size_t Read(void* buf, size_t size) { Z()->next_out = (unsigned char*)buf; Z()->avail_out = size; @@ -119,12 +119,12 @@ public: } case Z_STREAM_END: { - if (AllowMultipleStreams_) { - if (inflateReset(Z()) != Z_OK) { - ythrow TZLibDecompressorError() << "inflate reset error(" << GetErrMsg() << ")"; - } - } else { - return size - Z()->avail_out; + if (AllowMultipleStreams_) { + if (inflateReset(Z()) != Z_OK) { + ythrow TZLibDecompressorError() << "inflate reset error(" << GetErrMsg() << ")"; + } + } else { + return size - Z()->avail_out; } [[fallthrough]]; @@ -150,14 +150,14 @@ private: inline bool FillInputBuffer() { return Next(&Z()->next_in, &Z()->avail_in); } - + void SetDict() { if (inflateSetDictionary(Z(), (const Bytef*)Dict.data(), Dict.size()) != Z_OK) { ythrow TZLibCompressorError() << "can not set inflate dictionary"; } } - bool AllowMultipleStreams_ = true; + bool AllowMultipleStreams_ = true; TStringBuf Dict; }; @@ -328,10 +328,10 @@ TZLibDecompress::TZLibDecompress(IInputStream* input, ZLib::StreamType type, siz { } -void TZLibDecompress::SetAllowMultipleStreams(bool allowMultipleStreams) { - Impl_->SetAllowMultipleStreams(allowMultipleStreams); -} - +void TZLibDecompress::SetAllowMultipleStreams(bool allowMultipleStreams) { + Impl_->SetAllowMultipleStreams(allowMultipleStreams); +} + TZLibDecompress::~TZLibDecompress() = default; size_t TZLibDecompress::DoRead(void* buf, size_t size) { diff --git a/util/stream/zlib.h b/util/stream/zlib.h index e7de7c81b7..02192b8dc2 100644 --- a/util/stream/zlib.h +++ b/util/stream/zlib.h @@ -51,17 +51,17 @@ public: TZLibDecompress(IInputStream* input, ZLib::StreamType type = ZLib::Auto, size_t buflen = ZLib::ZLIB_BUF_LEN, TStringBuf dict = {}); - /** - * Allows/disallows multiple sequential compressed streams. Allowed by default. - * - * If multiple streams are allowed, their decompressed content will be concatenated. - * If multiple streams are disabled, then only first stream is decompressed. After that end + /** + * Allows/disallows multiple sequential compressed streams. Allowed by default. + * + * If multiple streams are allowed, their decompressed content will be concatenated. + * If multiple streams are disabled, then only first stream is decompressed. After that end * of IInputStream will have happen, i.e. method Read() will return 0. - * - * @param allowMultipleStreams - flag to allow (true) or disable (false) multiple streams. - */ - void SetAllowMultipleStreams(bool allowMultipleStreams); - + * + * @param allowMultipleStreams - flag to allow (true) or disable (false) multiple streams. + */ + void SetAllowMultipleStreams(bool allowMultipleStreams); + ~TZLibDecompress() override; protected: diff --git a/util/stream/zlib_ut.cpp b/util/stream/zlib_ut.cpp index 2290b4a9de..b8a9e03dae 100644 --- a/util/stream/zlib_ut.cpp +++ b/util/stream/zlib_ut.cpp @@ -74,7 +74,7 @@ Y_UNIT_TEST_SUITE(TZLibTest) { UNIT_ASSERT_EQUAL(d.ReadAll(), DATA); } } - + Y_UNIT_TEST(Dictionary) { static constexpr TStringBuf data = "<html><body></body></html>"; static constexpr TStringBuf dict = "</<html><body>"; @@ -91,26 +91,26 @@ Y_UNIT_TEST_SUITE(TZLibTest) { } Y_UNIT_TEST(DecompressTwoStreams) { - // Check that Decompress(Compress(X) + Compress(Y)) == X + Y - TTempFile tmpFile(ZDATA); - { + // Check that Decompress(Compress(X) + Compress(Y)) == X + Y + TTempFile tmpFile(ZDATA); + { TUnbufferedFileOutput o(ZDATA); - TZLibCompress c1(&o, ZLib::ZLib); + TZLibCompress c1(&o, ZLib::ZLib); c1.Write(DATA.data(), DATA.size()); - c1.Finish(); - TZLibCompress c2(&o, ZLib::ZLib); + c1.Finish(); + TZLibCompress c2(&o, ZLib::ZLib); c2.Write(DATA2.data(), DATA2.size()); - c2.Finish(); - o.Finish(); - } - { + c2.Finish(); + o.Finish(); + } + { TUnbufferedFileInput i(ZDATA); - TZLibDecompress d(&i); - + TZLibDecompress d(&i); + UNIT_ASSERT_EQUAL(d.ReadAll(), DATA + DATA2); - } - } - + } + } + Y_UNIT_TEST(CompressionExceptionSegfault) { TVector<char> buf(512 * 1024); EntropyPool().Load(buf.data(), buf.size()); @@ -127,26 +127,26 @@ Y_UNIT_TEST_SUITE(TZLibTest) { } Y_UNIT_TEST(DecompressFirstOfTwoStreams) { - // Check that Decompress(Compress(X) + Compress(Y)) == X when single stream is allowed - TTempFile tmpFile(ZDATA); - { + // Check that Decompress(Compress(X) + Compress(Y)) == X when single stream is allowed + TTempFile tmpFile(ZDATA); + { TUnbufferedFileOutput o(ZDATA); - TZLibCompress c1(&o, ZLib::ZLib); + TZLibCompress c1(&o, ZLib::ZLib); c1.Write(DATA.data(), DATA.size()); - c1.Finish(); - TZLibCompress c2(&o, ZLib::ZLib); + c1.Finish(); + TZLibCompress c2(&o, ZLib::ZLib); c2.Write(DATA2.data(), DATA2.size()); - c2.Finish(); - o.Finish(); - } - { + c2.Finish(); + o.Finish(); + } + { TUnbufferedFileInput i(ZDATA); - TZLibDecompress d(&i); - d.SetAllowMultipleStreams(false); - + TZLibDecompress d(&i); + d.SetAllowMultipleStreams(false); + UNIT_ASSERT_EQUAL(d.ReadAll(), DATA); - } - } + } + } Y_UNIT_TEST(CompressFlush) { TString data = ""; |