diff options
author | bidzilya <bidzilya@yandex-team.ru> | 2022-02-10 16:50:46 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:46 +0300 |
commit | a175286682787b2d1213734c5be7458aaf594c1c (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library | |
parent | df9835cb1b90255cbbd11b71ab3609ec1ff75107 (diff) | |
download | ydb-a175286682787b2d1213734c5be7458aaf594c1c.tar.gz |
Restoring authorship annotation for <bidzilya@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library')
-rw-r--r-- | library/cpp/packers/proto_packer.cpp | 2 | ||||
-rw-r--r-- | library/cpp/packers/proto_packer.h | 98 | ||||
-rw-r--r-- | library/cpp/packers/region_packer.cpp | 2 | ||||
-rw-r--r-- | library/cpp/packers/ut/proto_packer_ut.cpp | 190 | ||||
-rw-r--r-- | library/cpp/packers/ut/test.proto | 22 | ||||
-rw-r--r-- | library/cpp/packers/ut/ya.make | 4 | ||||
-rw-r--r-- | library/cpp/packers/ya.make | 4 | ||||
-rw-r--r-- | library/cpp/yt/string/format-inl.h | 6 |
8 files changed, 164 insertions, 164 deletions
diff --git a/library/cpp/packers/proto_packer.cpp b/library/cpp/packers/proto_packer.cpp index 457202d1e5..ddca0d5b3b 100644 --- a/library/cpp/packers/proto_packer.cpp +++ b/library/cpp/packers/proto_packer.cpp @@ -1 +1 @@ -#include "proto_packer.h" +#include "proto_packer.h" diff --git a/library/cpp/packers/proto_packer.h b/library/cpp/packers/proto_packer.h index bf40c6c2cd..5a3d008e29 100644 --- a/library/cpp/packers/proto_packer.h +++ b/library/cpp/packers/proto_packer.h @@ -1,50 +1,50 @@ -#pragma once - -#include "packers.h" - -#include <util/generic/yexception.h> - -namespace NPackers { - template <typename TProtoMessage> - class TProtoMessagePacker { - public: - void UnpackLeaf(const char* bufferPtr, TProtoMessage& protoMessage) const { - const size_t protoMessageByteSize = GetProtoMessageByteSize(bufferPtr); - const size_t skipBytesCount = ProtoMessageByteSizePacker.SkipLeaf(bufferPtr); - - if (!protoMessage.ParseFromArray(static_cast<const void*>(bufferPtr + skipBytesCount), protoMessageByteSize)) { - ythrow yexception() << "Cannot unpack leaf with proto message"; - } - } - - void PackLeaf(char* bufferPtr, const TProtoMessage& protoMessage, const size_t totalByteSize) const { - const size_t protoMessageByteSize = protoMessage.ByteSize(); - const size_t skipBytesCount = totalByteSize - protoMessageByteSize; - - ProtoMessageByteSizePacker.PackLeaf(bufferPtr, protoMessageByteSize, skipBytesCount); - - if (!protoMessage.SerializeToArray(static_cast<void*>(bufferPtr + skipBytesCount), protoMessageByteSize)) { - ythrow yexception() << "Cannot pack leaf with proto message"; - } - } - - size_t MeasureLeaf(const TProtoMessage& protoMessage) const { - const size_t protoMessageByteSize = protoMessage.ByteSize(); - return ProtoMessageByteSizePacker.MeasureLeaf(protoMessageByteSize) + protoMessageByteSize; - } - - size_t SkipLeaf(const char* bufferPtr) const { - const size_t protoMessageByteSize = GetProtoMessageByteSize(bufferPtr); - return ProtoMessageByteSizePacker.SkipLeaf(bufferPtr) + protoMessageByteSize; - } - - private: - TIntegralPacker<size_t> ProtoMessageByteSizePacker; - - size_t GetProtoMessageByteSize(const char* bufferPtr) const { - size_t result; - ProtoMessageByteSizePacker.UnpackLeaf(bufferPtr, result); - return result; - } - }; +#pragma once + +#include "packers.h" + +#include <util/generic/yexception.h> + +namespace NPackers { + template <typename TProtoMessage> + class TProtoMessagePacker { + public: + void UnpackLeaf(const char* bufferPtr, TProtoMessage& protoMessage) const { + const size_t protoMessageByteSize = GetProtoMessageByteSize(bufferPtr); + const size_t skipBytesCount = ProtoMessageByteSizePacker.SkipLeaf(bufferPtr); + + if (!protoMessage.ParseFromArray(static_cast<const void*>(bufferPtr + skipBytesCount), protoMessageByteSize)) { + ythrow yexception() << "Cannot unpack leaf with proto message"; + } + } + + void PackLeaf(char* bufferPtr, const TProtoMessage& protoMessage, const size_t totalByteSize) const { + const size_t protoMessageByteSize = protoMessage.ByteSize(); + const size_t skipBytesCount = totalByteSize - protoMessageByteSize; + + ProtoMessageByteSizePacker.PackLeaf(bufferPtr, protoMessageByteSize, skipBytesCount); + + if (!protoMessage.SerializeToArray(static_cast<void*>(bufferPtr + skipBytesCount), protoMessageByteSize)) { + ythrow yexception() << "Cannot pack leaf with proto message"; + } + } + + size_t MeasureLeaf(const TProtoMessage& protoMessage) const { + const size_t protoMessageByteSize = protoMessage.ByteSize(); + return ProtoMessageByteSizePacker.MeasureLeaf(protoMessageByteSize) + protoMessageByteSize; + } + + size_t SkipLeaf(const char* bufferPtr) const { + const size_t protoMessageByteSize = GetProtoMessageByteSize(bufferPtr); + return ProtoMessageByteSizePacker.SkipLeaf(bufferPtr) + protoMessageByteSize; + } + + private: + TIntegralPacker<size_t> ProtoMessageByteSizePacker; + + size_t GetProtoMessageByteSize(const char* bufferPtr) const { + size_t result; + ProtoMessageByteSizePacker.UnpackLeaf(bufferPtr, result); + return result; + } + }; } diff --git a/library/cpp/packers/region_packer.cpp b/library/cpp/packers/region_packer.cpp index f40f8dd7da..3d8b20c371 100644 --- a/library/cpp/packers/region_packer.cpp +++ b/library/cpp/packers/region_packer.cpp @@ -1 +1 @@ -#include "region_packer.h" +#include "region_packer.h" diff --git a/library/cpp/packers/ut/proto_packer_ut.cpp b/library/cpp/packers/ut/proto_packer_ut.cpp index 325eb3d542..e4151ba68c 100644 --- a/library/cpp/packers/ut/proto_packer_ut.cpp +++ b/library/cpp/packers/ut/proto_packer_ut.cpp @@ -1,104 +1,104 @@ -#include "proto_packer.h" - +#include "proto_packer.h" + #include <library/cpp/packers/ut/test.pb.h> #include <library/cpp/testing/unittest/registar.h> - -#include <util/generic/string.h> - -using namespace NPackers; -using namespace NProtoPackerTest; - -void FillRequiredFields(TTestMessage& msg) { - msg.SetRequiredString("required_string"); - msg.SetRequiredInt32(42); -} - -void FillOptionalFields(TTestMessage& msg) { - msg.SetOptionalString("optional_string"); - msg.SetOptionalInt32(43); -} - -void FillRepeatedFields(TTestMessage& msg) { - msg.ClearRepeatedStrings(); - for (ui32 idx = 0; idx < 5; ++idx) { - msg.AddRepeatedStrings("repeated_string" + ToString(idx)); - } -} - + +#include <util/generic/string.h> + +using namespace NPackers; +using namespace NProtoPackerTest; + +void FillRequiredFields(TTestMessage& msg) { + msg.SetRequiredString("required_string"); + msg.SetRequiredInt32(42); +} + +void FillOptionalFields(TTestMessage& msg) { + msg.SetOptionalString("optional_string"); + msg.SetOptionalInt32(43); +} + +void FillRepeatedFields(TTestMessage& msg) { + msg.ClearRepeatedStrings(); + for (ui32 idx = 0; idx < 5; ++idx) { + msg.AddRepeatedStrings("repeated_string" + ToString(idx)); + } +} + // do not want to use google/protobuf/util/message_differencer because of warnings bool operator==(const TTestMessage& lhs, const TTestMessage& rhs) { - if (lhs.GetRequiredString() != rhs.GetRequiredString() || - lhs.GetRequiredInt32() != rhs.GetRequiredInt32() || - lhs.HasOptionalString() != rhs.HasOptionalString() || - (lhs.HasOptionalString() && lhs.GetOptionalString() != rhs.GetOptionalString()) || - lhs.HasOptionalInt32() != rhs.HasOptionalInt32() || - (lhs.HasOptionalInt32() && lhs.GetOptionalInt32() != rhs.GetOptionalInt32()) || - lhs.RepeatedStringsSize() != rhs.RepeatedStringsSize()) - { - return false; - } - for (ui32 idx = 0; idx < lhs.RepeatedStringsSize(); ++idx) { - if (lhs.GetRepeatedStrings(idx) != rhs.GetRepeatedStrings(idx)) { - return false; - } - } - return true; -} - + if (lhs.GetRequiredString() != rhs.GetRequiredString() || + lhs.GetRequiredInt32() != rhs.GetRequiredInt32() || + lhs.HasOptionalString() != rhs.HasOptionalString() || + (lhs.HasOptionalString() && lhs.GetOptionalString() != rhs.GetOptionalString()) || + lhs.HasOptionalInt32() != rhs.HasOptionalInt32() || + (lhs.HasOptionalInt32() && lhs.GetOptionalInt32() != rhs.GetOptionalInt32()) || + lhs.RepeatedStringsSize() != rhs.RepeatedStringsSize()) + { + return false; + } + for (ui32 idx = 0; idx < lhs.RepeatedStringsSize(); ++idx) { + if (lhs.GetRepeatedStrings(idx) != rhs.GetRepeatedStrings(idx)) { + return false; + } + } + return true; +} + Y_UNIT_TEST_SUITE(ProtoPackerTestSuite) { - TProtoMessagePacker<TTestMessage> Packer; - TString Buffer; - - void DoPackUnpackTest(const TTestMessage& msg) { - const ui32 msgByteSize = Packer.MeasureLeaf(msg); - Buffer.resize(msgByteSize); - - Packer.PackLeaf(Buffer.begin(), msg, msgByteSize); - - TTestMessage checkMsg; - Packer.UnpackLeaf(Buffer.begin(), checkMsg); - - UNIT_ASSERT_EQUAL(msg, checkMsg); - } - + TProtoMessagePacker<TTestMessage> Packer; + TString Buffer; + + void DoPackUnpackTest(const TTestMessage& msg) { + const ui32 msgByteSize = Packer.MeasureLeaf(msg); + Buffer.resize(msgByteSize); + + Packer.PackLeaf(Buffer.begin(), msg, msgByteSize); + + TTestMessage checkMsg; + Packer.UnpackLeaf(Buffer.begin(), checkMsg); + + UNIT_ASSERT_EQUAL(msg, checkMsg); + } + Y_UNIT_TEST(TestPackUnpackOnlyRequired) { - TTestMessage msg; - FillRequiredFields(msg); - DoPackUnpackTest(msg); - } - + TTestMessage msg; + FillRequiredFields(msg); + DoPackUnpackTest(msg); + } + Y_UNIT_TEST(TestPackUnpackRequiredAndOptional) { - TTestMessage msg; - FillRequiredFields(msg); - FillOptionalFields(msg); - DoPackUnpackTest(msg); - } - + TTestMessage msg; + FillRequiredFields(msg); + FillOptionalFields(msg); + DoPackUnpackTest(msg); + } + Y_UNIT_TEST(TestPackUnpackAll) { - TTestMessage msg; - FillRequiredFields(msg); - FillOptionalFields(msg); - FillRepeatedFields(msg); - DoPackUnpackTest(msg); - } - + TTestMessage msg; + FillRequiredFields(msg); + FillOptionalFields(msg); + FillRepeatedFields(msg); + DoPackUnpackTest(msg); + } + Y_UNIT_TEST(TestSkipLeaf) { - TTestMessage msgFirst; - FillRequiredFields(msgFirst); - TTestMessage msgSecond; - FillRequiredFields(msgSecond); - FillOptionalFields(msgSecond); - - const ui32 msgFirstByteSize = Packer.MeasureLeaf(msgFirst); - const ui32 msgSecondByteSize = Packer.MeasureLeaf(msgSecond); - - Buffer.resize(msgFirstByteSize + msgSecondByteSize); - Packer.PackLeaf(Buffer.begin(), msgFirst, msgFirstByteSize); - Packer.PackLeaf(Buffer.begin() + msgFirstByteSize, msgSecond, msgSecondByteSize); - - TTestMessage checkMsg; - Packer.UnpackLeaf(Buffer.begin() + Packer.SkipLeaf(Buffer.begin()), checkMsg); - - UNIT_ASSERT_EQUAL(msgSecond, checkMsg); - } -} + TTestMessage msgFirst; + FillRequiredFields(msgFirst); + TTestMessage msgSecond; + FillRequiredFields(msgSecond); + FillOptionalFields(msgSecond); + + const ui32 msgFirstByteSize = Packer.MeasureLeaf(msgFirst); + const ui32 msgSecondByteSize = Packer.MeasureLeaf(msgSecond); + + Buffer.resize(msgFirstByteSize + msgSecondByteSize); + Packer.PackLeaf(Buffer.begin(), msgFirst, msgFirstByteSize); + Packer.PackLeaf(Buffer.begin() + msgFirstByteSize, msgSecond, msgSecondByteSize); + + TTestMessage checkMsg; + Packer.UnpackLeaf(Buffer.begin() + Packer.SkipLeaf(Buffer.begin()), checkMsg); + + UNIT_ASSERT_EQUAL(msgSecond, checkMsg); + } +} diff --git a/library/cpp/packers/ut/test.proto b/library/cpp/packers/ut/test.proto index 439498b917..c872616bcc 100644 --- a/library/cpp/packers/ut/test.proto +++ b/library/cpp/packers/ut/test.proto @@ -1,11 +1,11 @@ -package NProtoPackerTest; - -message TTestMessage { - required string RequiredString = 1; - optional string OptionalString = 2; - - required int32 RequiredInt32 = 3; - optional int32 OptionalInt32 = 4; - - repeated string RepeatedStrings = 5; -} +package NProtoPackerTest; + +message TTestMessage { + required string RequiredString = 1; + optional string OptionalString = 2; + + required int32 RequiredInt32 = 3; + optional int32 OptionalInt32 = 4; + + repeated string RepeatedStrings = 5; +} diff --git a/library/cpp/packers/ut/ya.make b/library/cpp/packers/ut/ya.make index a3db381ed3..1c024ffd94 100644 --- a/library/cpp/packers/ut/ya.make +++ b/library/cpp/packers/ut/ya.make @@ -4,9 +4,9 @@ OWNER(velavokr) SRCS( packers_ut.cpp - proto_packer_ut.cpp + proto_packer_ut.cpp region_packer_ut.cpp - test.proto + test.proto ) END() diff --git a/library/cpp/packers/ya.make b/library/cpp/packers/ya.make index bb86d9b00b..e1ec4972ed 100644 --- a/library/cpp/packers/ya.make +++ b/library/cpp/packers/ya.make @@ -4,8 +4,8 @@ OWNER(velavokr) SRCS( packers.cpp - proto_packer.cpp - region_packer.cpp + proto_packer.cpp + region_packer.cpp ) END() diff --git a/library/cpp/yt/string/format-inl.h b/library/cpp/yt/string/format-inl.h index f47c1acf33..5484d4a216 100644 --- a/library/cpp/yt/string/format-inl.h +++ b/library/cpp/yt/string/format-inl.h @@ -378,10 +378,10 @@ struct TValueFormatter<THashMultiMap<K, V>> }; // TEnumIndexedVector -template <class E, class T> -struct TValueFormatter<TEnumIndexedVector<E, T>> +template <class E, class T> +struct TValueFormatter<TEnumIndexedVector<E, T>> { - static void Do(TStringBuilderBase* builder, const TEnumIndexedVector<E, T>& collection, TStringBuf format) + static void Do(TStringBuilderBase* builder, const TEnumIndexedVector<E, T>& collection, TStringBuf format) { builder->AppendChar('{'); bool firstItem = true; |