From 5876ce9e3d834e436a13ac49b8736034d942b5d1 Mon Sep 17 00:00:00 2001 From: Ydot Date: Sun, 6 Nov 2022 21:07:46 +0300 Subject: [PATCH] init --- .gitmodules | 12 + CMakeLists.txt | 11 + FlameGraph | 1 + bench/CMakeLists.txt | 7 + bench/main.cpp | 75 +++ benchmark | 1 + flame_from_bench.sh | 3 + gen_data.sh | 1 + googletest | 1 + messages/messge.pb.cc | 1006 ++++++++++++++++++++++++++++++ messages/messge.pb.h | 1107 ++++++++++++++++++++++++++++++++++ messages/messge.proto | 20 + proto_gen/CMakeLists.txt | 11 + proto_gen/lib/CMakeLists.txt | 15 + proto_gen/lib/gen_data.cpp | 54 ++ proto_gen/lib/gen_data.h | 21 + proto_gen/main.cpp | 50 ++ proto_gen/opts.h | 57 ++ protobuf | 1 + 19 files changed, 2454 insertions(+) create mode 100644 .gitmodules create mode 100644 CMakeLists.txt create mode 160000 FlameGraph create mode 100644 bench/CMakeLists.txt create mode 100644 bench/main.cpp create mode 160000 benchmark create mode 100755 flame_from_bench.sh create mode 100755 gen_data.sh create mode 160000 googletest create mode 100644 messages/messge.pb.cc create mode 100644 messages/messge.pb.h create mode 100644 messages/messge.proto create mode 100644 proto_gen/CMakeLists.txt create mode 100644 proto_gen/lib/CMakeLists.txt create mode 100644 proto_gen/lib/gen_data.cpp create mode 100644 proto_gen/lib/gen_data.h create mode 100644 proto_gen/main.cpp create mode 100644 proto_gen/opts.h create mode 160000 protobuf diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 0000000..4f024db --- /dev/null +++ b/.gitmodules @@ -0,0 +1,12 @@ +[submodule "FlameGraph"] + path = FlameGraph + url = git@github.com:brendangregg/FlameGraph.git +[submodule "protobuf"] + path = protobuf + url = git@github.com:protocolbuffers/protobuf.git +[submodule "googletest"] + path = googletest + url = git@github.com:google/googletest.git +[submodule "benchmark"] + path = benchmark + url = git@github.com:google/benchmark.git diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..dca1ea5 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.22) + +set(PROTO_DIR ${CMAKE_CURRENT_LIST_DIR}/protobuf) +set(PROTO_MSG ${CMAKE_CURRENT_LIST_DIR}/messages) + +add_subdirectory(proto_gen) +add_subdirectory(bench) + +add_subdirectory(protobuf) +add_subdirectory(googletest) +add_subdirectory(benchmark) diff --git a/FlameGraph b/FlameGraph new file mode 160000 index 0000000..d9fcc27 --- /dev/null +++ b/FlameGraph @@ -0,0 +1 @@ +Subproject commit d9fcc272b6a08c3e3e5b7919040f0ab5f8952d65 diff --git a/bench/CMakeLists.txt b/bench/CMakeLists.txt new file mode 100644 index 0000000..39e121a --- /dev/null +++ b/bench/CMakeLists.txt @@ -0,0 +1,7 @@ +project(bench) + +add_executable(${PROJECT_NAME}) + +target_sources(${PROJECT_NAME} PRIVATE main.cpp) + +target_link_libraries(${PROJECT_NAME} PRIVATE benchmark::benchmark gen_proto_lib protobuf::libprotobuf) \ No newline at end of file diff --git a/bench/main.cpp b/bench/main.cpp new file mode 100644 index 0000000..9f31ee8 --- /dev/null +++ b/bench/main.cpp @@ -0,0 +1,75 @@ +#include "messge.pb.h" +#include +#include +#include + +template +class TSingletone { +public: + template + TSingletone(TArgs... args) { + if (val == nullptr) { + val = new T(std::forward(args)...); + } + } + + T* operator*() { + return val; + } + + static T* val; +}; + +template +T* TSingletone::val = nullptr; + + +class TEnvHolder { +public: + TEnvHolder() { + // Init + + NGenProto::TGenOpts opts; + opts.NumsCount = 100; + opts.StringsCount = 100; + opts.StringSize = 100; + opts.FloatCount = 100; + opts.FilesCount = 2000; + opts.SetsOfFilesCount = 100; + + report = NGenProto::GenReport(opts); + + std::string out; + report.SerializeToString(&out); + } + + tutorial::TReport report; +}; + +static void BM_ParseProtoFromFile(benchmark::State& state) { + + const auto& env = *TSingletone(); + for (auto _ : state) { + std::ifstream in("out.txt"); + + tutorial::TReport a; + tutorial::TReport res; + + a.ParseFromIstream(&in); + + std::sort(a.mutable_setsoffiles()->begin(), a.mutable_setsoffiles()->end(), + [](const auto& a, const auto& b) {return a.hash() > b.hash();} + ); + + for (size_t i = 0; i < a.setsoffiles_size() / 2; i++) { + *res.add_setsoffiles() = a.setsoffiles(i); + } + + std::ofstream out("res.txt"); + res.SerializeToOstream(&out); + } + +} +// Register the function as a benchmark +BENCHMARK(BM_ParseProtoFromFile); +BENCHMARK_MAIN(); \ No newline at end of file diff --git a/benchmark b/benchmark new file mode 160000 index 0000000..398a8ac --- /dev/null +++ b/benchmark @@ -0,0 +1 @@ +Subproject commit 398a8ac2e8e0b852fa1568dc1c8ebdfc743a380a diff --git a/flame_from_bench.sh b/flame_from_bench.sh new file mode 100755 index 0000000..89588b0 --- /dev/null +++ b/flame_from_bench.sh @@ -0,0 +1,3 @@ +sudo perf record -g ./build/bench/bench +sudo perf script > perf.script +./FlameGraph/stackcollapse-perf.pl perf.script | ./FlameGraph/flamegraph.pl > flamegraph.svg \ No newline at end of file diff --git a/gen_data.sh b/gen_data.sh new file mode 100755 index 0000000..c241df2 --- /dev/null +++ b/gen_data.sh @@ -0,0 +1 @@ +./build/proto_gen/proto_gen --seed=13 --nums_cnt=100 --strings_cnt=100 --string_size=1000 --float_cnt=10 --files_cnt=100 --sets_cnt=100 --out=./out.txt \ No newline at end of file diff --git a/googletest b/googletest new file mode 160000 index 0000000..a4f02ef --- /dev/null +++ b/googletest @@ -0,0 +1 @@ +Subproject commit a4f02ef38981350c9d673b9909559c7a86420d7a diff --git a/messages/messge.pb.cc b/messages/messge.pb.cc new file mode 100644 index 0000000..3a2a7b0 --- /dev/null +++ b/messages/messge.pb.cc @@ -0,0 +1,1006 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: messge.proto + +#include "messge.pb.h" + +#include +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/extension_set.h" +#include "google/protobuf/wire_format_lite.h" +#include "google/protobuf/descriptor.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/reflection_ops.h" +#include "google/protobuf/wire_format.h" +// @@protoc_insertion_point(includes) + +// Must be included last. +#include "google/protobuf/port_def.inc" +PROTOBUF_PRAGMA_INIT_SEG +namespace _pb = ::PROTOBUF_NAMESPACE_ID; +namespace _pbi = ::PROTOBUF_NAMESPACE_ID::internal; +namespace tutorial { +PROTOBUF_CONSTEXPR TFile::TFile( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_._has_bits_)*/{} + , /*decltype(_impl_._cached_size_)*/{} + , /*decltype(_impl_.weights_)*/{} + , /*decltype(_impl_.hosts_)*/{} + , /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}}} {} +struct TFileDefaultTypeInternal { + PROTOBUF_CONSTEXPR TFileDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~TFileDefaultTypeInternal() {} + union { + TFile _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 TFileDefaultTypeInternal _TFile_default_instance_; +PROTOBUF_CONSTEXPR TFileSet::TFileSet( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_._has_bits_)*/{} + , /*decltype(_impl_._cached_size_)*/{} + , /*decltype(_impl_.files_)*/{} + , /*decltype(_impl_.hash_)*/::int64_t{0}} {} +struct TFileSetDefaultTypeInternal { + PROTOBUF_CONSTEXPR TFileSetDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~TFileSetDefaultTypeInternal() {} + union { + TFileSet _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 TFileSetDefaultTypeInternal _TFileSet_default_instance_; +PROTOBUF_CONSTEXPR TReport::TReport( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_.nums_)*/{} + , /*decltype(_impl_.strings_)*/{} + , /*decltype(_impl_.setsoffiles_)*/{} + , /*decltype(_impl_._cached_size_)*/{}} {} +struct TReportDefaultTypeInternal { + PROTOBUF_CONSTEXPR TReportDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {} + ~TReportDefaultTypeInternal() {} + union { + TReport _instance; + }; +}; + +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT + PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 TReportDefaultTypeInternal _TReport_default_instance_; +} // namespace tutorial +static ::_pb::Metadata file_level_metadata_messge_2eproto[3]; +static constexpr const ::_pb::EnumDescriptor** + file_level_enum_descriptors_messge_2eproto = nullptr; +static constexpr const ::_pb::ServiceDescriptor** + file_level_service_descriptors_messge_2eproto = nullptr; +const ::uint32_t TableStruct_messge_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE( + protodesc_cold) = { + PROTOBUF_FIELD_OFFSET(::tutorial::TFile, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::tutorial::TFile, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + ~0u, // no _split_ + ~0u, // no sizeof(Split) + PROTOBUF_FIELD_OFFSET(::tutorial::TFile, _impl_.weights_), + PROTOBUF_FIELD_OFFSET(::tutorial::TFile, _impl_.name_), + PROTOBUF_FIELD_OFFSET(::tutorial::TFile, _impl_.hosts_), + ~0u, + 0, + ~0u, + PROTOBUF_FIELD_OFFSET(::tutorial::TFileSet, _impl_._has_bits_), + PROTOBUF_FIELD_OFFSET(::tutorial::TFileSet, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + ~0u, // no _split_ + ~0u, // no sizeof(Split) + PROTOBUF_FIELD_OFFSET(::tutorial::TFileSet, _impl_.files_), + PROTOBUF_FIELD_OFFSET(::tutorial::TFileSet, _impl_.hash_), + ~0u, + 0, + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::tutorial::TReport, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + ~0u, // no _inlined_string_donated_ + ~0u, // no _split_ + ~0u, // no sizeof(Split) + PROTOBUF_FIELD_OFFSET(::tutorial::TReport, _impl_.nums_), + PROTOBUF_FIELD_OFFSET(::tutorial::TReport, _impl_.strings_), + PROTOBUF_FIELD_OFFSET(::tutorial::TReport, _impl_.setsoffiles_), +}; + +static const ::_pbi::MigrationSchema + schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, 11, -1, sizeof(::tutorial::TFile)}, + { 14, 24, -1, sizeof(::tutorial::TFileSet)}, + { 26, -1, -1, sizeof(::tutorial::TReport)}, +}; + +static const ::_pb::Message* const file_default_instances[] = { + &::tutorial::_TFile_default_instance_._instance, + &::tutorial::_TFileSet_default_instance_._instance, + &::tutorial::_TReport_default_instance_._instance, +}; +const char descriptor_table_protodef_messge_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + "\n\014messge.proto\022\010tutorial\"5\n\005TFile\022\017\n\007Wei" + "ghts\030\001 \003(\002\022\014\n\004Name\030\002 \002(\t\022\r\n\005Hosts\030\003 \003(\005\"" + "8\n\010TFileSet\022\036\n\005Files\030\001 \003(\0132\017.tutorial.TF" + "ile\022\014\n\004Hash\030\002 \002(\003\"Q\n\007TReport\022\014\n\004Nums\030\001 \003" + "(\005\022\017\n\007Strings\030\002 \003(\t\022\'\n\013SetsOfFiles\030\003 \003(\013" + "2\022.tutorial.TFileSet" +}; +static ::absl::once_flag descriptor_table_messge_2eproto_once; +const ::_pbi::DescriptorTable descriptor_table_messge_2eproto = { + false, + false, + 220, + descriptor_table_protodef_messge_2eproto, + "messge.proto", + &descriptor_table_messge_2eproto_once, + nullptr, + 0, + 3, + schemas, + file_default_instances, + TableStruct_messge_2eproto::offsets, + file_level_metadata_messge_2eproto, + file_level_enum_descriptors_messge_2eproto, + file_level_service_descriptors_messge_2eproto, +}; + +// This function exists to be marked as weak. +// It can significantly speed up compilation by breaking up LLVM's SCC +// in the .pb.cc translation units. Large translation units see a +// reduction of more than 35% of walltime for optimized builds. Without +// the weak attribute all the messages in the file, including all the +// vtables and everything they use become part of the same SCC through +// a cycle like: +// GetMetadata -> descriptor table -> default instances -> +// vtables -> GetMetadata +// By adding a weak function here we break the connection from the +// individual vtables back into the descriptor table. +PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_messge_2eproto_getter() { + return &descriptor_table_messge_2eproto; +} +// Force running AddDescriptors() at dynamic initialization time. +PROTOBUF_ATTRIBUTE_INIT_PRIORITY2 +static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_messge_2eproto(&descriptor_table_messge_2eproto); +namespace tutorial { +// =================================================================== + +class TFile::_Internal { + public: + using HasBits = decltype(std::declval()._impl_._has_bits_); + static constexpr ::int32_t kHasBitsOffset = + 8 * PROTOBUF_FIELD_OFFSET(TFile, _impl_._has_bits_); + static void set_has_name(HasBits* has_bits) { + (*has_bits)[0] |= 1u; + } + static bool MissingRequiredFields(const HasBits& has_bits) { + return ((has_bits[0] & 0x00000001) ^ 0x00000001) != 0; + } +}; + +TFile::TFile(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned) + : ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) { + SharedCtor(arena, is_message_owned); + // @@protoc_insertion_point(arena_constructor:tutorial.TFile) +} +TFile::TFile(const TFile& from) + : ::PROTOBUF_NAMESPACE_ID::Message() { + TFile* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_._has_bits_){from._impl_._has_bits_} + , /*decltype(_impl_._cached_size_)*/{} + , decltype(_impl_.weights_){from._impl_.weights_} + , decltype(_impl_.hosts_){from._impl_.hosts_} + , decltype(_impl_.name_){}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _impl_.name_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.name_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (from._internal_has_name()) { + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); + } + // @@protoc_insertion_point(copy_constructor:tutorial.TFile) +} + +inline void TFile::SharedCtor( + ::_pb::Arena* arena, bool is_message_owned) { + (void)arena; + (void)is_message_owned; + new (&_impl_) Impl_{ + decltype(_impl_._has_bits_){} + , /*decltype(_impl_._cached_size_)*/{} + , decltype(_impl_.weights_){arena} + , decltype(_impl_.hosts_){arena} + , decltype(_impl_.name_){} + }; + _impl_.name_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.name_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING +} + +TFile::~TFile() { + // @@protoc_insertion_point(destructor:tutorial.TFile) + if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void TFile::SharedDtor() { + GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); + _impl_.weights_.~RepeatedField(); + _impl_.hosts_.~RepeatedField(); + _impl_.name_.Destroy(); +} + +void TFile::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void TFile::Clear() { +// @@protoc_insertion_point(message_clear_start:tutorial.TFile) + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.weights_.Clear(); + _impl_.hosts_.Clear(); + cached_has_bits = _impl_._has_bits_[0]; + if (cached_has_bits & 0x00000001u) { + _impl_.name_.ClearNonDefaultToEmpty(); + } + _impl_._has_bits_.Clear(); + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* TFile::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { + +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + _Internal::HasBits has_bits{}; + while (!ctx->Done(&ptr)) { + ::uint32_t tag; + ptr = ::_pbi::ReadTag(ptr, &tag); + switch (tag >> 3) { + // repeated float Weights = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 13)) { + ptr -= 1; + do { + ptr += 1; + _internal_add_weights(::PROTOBUF_NAMESPACE_ID::internal::UnalignedLoad(ptr)); + ptr += sizeof(float); + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<13>(ptr)); + } else if (static_cast<::uint8_t>(tag) == 10) { + ptr = ::PROTOBUF_NAMESPACE_ID::internal::PackedFloatParser(_internal_mutable_weights(), ptr, ctx); + CHK_(ptr); + } else { + goto handle_unusual; + } + continue; + // required string Name = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { + auto str = _internal_mutable_name(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + #ifndef NDEBUG + ::_pbi::VerifyUTF8(str, "tutorial.TFile.Name"); + #endif // !NDEBUG + } else { + goto handle_unusual; + } + continue; + // repeated int32 Hosts = 3; + case 3: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 24)) { + ptr -= 1; + do { + ptr += 1; + _internal_add_hosts(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr)); + CHK_(ptr); + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<24>(ptr)); + } else if (static_cast<::uint8_t>(tag) == 26) { + ptr = ::PROTOBUF_NAMESPACE_ID::internal::PackedInt32Parser(_internal_mutable_hosts(), ptr, ctx); + CHK_(ptr); + } else { + goto handle_unusual; + } + continue; + default: + goto handle_unusual; + } // switch + handle_unusual: + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); + ctx->SetLastTag(tag); + goto message_done; + } + ptr = UnknownFieldParse( + tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + _impl_._has_bits_.Or(has_bits); + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +::uint8_t* TFile::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + + // @@protoc_insertion_point(serialize_to_array_start:tutorial.TFile) + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + // repeated float Weights = 1; + for (int i = 0, n = this->_internal_weights_size(); i < n; i++) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteFloatToArray(1, this->_internal_weights(i), target); + } + + cached_has_bits = _impl_._has_bits_[0]; + // required string Name = 2; + if (cached_has_bits & 0x00000001u) { + ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( + this->_internal_name().data(), static_cast(this->_internal_name().length()), + ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, + "tutorial.TFile.Name"); + target = stream->WriteStringMaybeAliased( + 2, this->_internal_name(), target); + } + + // repeated int32 Hosts = 3; + for (int i = 0, n = this->_internal_hosts_size(); i < n; i++) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteInt32ToArray(3, this->_internal_hosts(i), target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:tutorial.TFile) + return target; +} + +::size_t TFile::ByteSizeLong() const { + +// @@protoc_insertion_point(message_byte_size_start:tutorial.TFile) + ::size_t total_size = 0; + + // required string Name = 2; + if (_internal_has_name()) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_name()); + } + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // repeated float Weights = 1; + { + unsigned int count = static_cast(this->_internal_weights_size()); + ::size_t data_size = 4UL * count; + total_size += 1 * + ::_pbi::FromIntSize(this->_internal_weights_size()); + total_size += data_size; + } + + // repeated int32 Hosts = 3; + { + ::size_t data_size = ::_pbi::WireFormatLite:: + Int32Size(this->_impl_.hosts_); + total_size += 1 * + ::_pbi::FromIntSize(this->_internal_hosts_size()); + total_size += data_size; + } + + return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); +} + +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TFile::_class_data_ = { + ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, + TFile::MergeImpl +}; +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TFile::GetClassData() const { return &_class_data_; } + + +void TFile::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + + // @@protoc_insertion_point(class_specific_merge_from_start:tutorial.TFile) + GOOGLE_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + _this->_impl_.weights_.MergeFrom(from._impl_.weights_); + _this->_impl_.hosts_.MergeFrom(from._impl_.hosts_); + if (from._internal_has_name()) { + _this->_internal_set_name(from._internal_name()); + } + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); +} + +void TFile::CopyFrom(const TFile& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:tutorial.TFile) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool TFile::IsInitialized() const { + if (_Internal::MissingRequiredFields(_impl_._has_bits_)) return false; + return true; +} + +void TFile::InternalSwap(TFile* other) { + using std::swap; + auto* lhs_arena = GetArenaForAllocation(); + auto* rhs_arena = other->GetArenaForAllocation(); + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); + _impl_.weights_.InternalSwap(&other->_impl_.weights_); + _impl_.hosts_.InternalSwap(&other->_impl_.hosts_); + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( + &_impl_.name_, lhs_arena, + &other->_impl_.name_, rhs_arena + ); +} + +::PROTOBUF_NAMESPACE_ID::Metadata TFile::GetMetadata() const { + + return ::_pbi::AssignDescriptors( + &descriptor_table_messge_2eproto_getter, &descriptor_table_messge_2eproto_once, + file_level_metadata_messge_2eproto[0]); +} +// =================================================================== + +class TFileSet::_Internal { + public: + using HasBits = decltype(std::declval()._impl_._has_bits_); + static constexpr ::int32_t kHasBitsOffset = + 8 * PROTOBUF_FIELD_OFFSET(TFileSet, _impl_._has_bits_); + static void set_has_hash(HasBits* has_bits) { + (*has_bits)[0] |= 1u; + } + static bool MissingRequiredFields(const HasBits& has_bits) { + return ((has_bits[0] & 0x00000001) ^ 0x00000001) != 0; + } +}; + +TFileSet::TFileSet(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned) + : ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) { + SharedCtor(arena, is_message_owned); + // @@protoc_insertion_point(arena_constructor:tutorial.TFileSet) +} +TFileSet::TFileSet(const TFileSet& from) + : ::PROTOBUF_NAMESPACE_ID::Message() { + TFileSet* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_._has_bits_){from._impl_._has_bits_} + , /*decltype(_impl_._cached_size_)*/{} + , decltype(_impl_.files_){from._impl_.files_} + , decltype(_impl_.hash_){}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + _this->_impl_.hash_ = from._impl_.hash_; + // @@protoc_insertion_point(copy_constructor:tutorial.TFileSet) +} + +inline void TFileSet::SharedCtor( + ::_pb::Arena* arena, bool is_message_owned) { + (void)arena; + (void)is_message_owned; + new (&_impl_) Impl_{ + decltype(_impl_._has_bits_){} + , /*decltype(_impl_._cached_size_)*/{} + , decltype(_impl_.files_){arena} + , decltype(_impl_.hash_){::int64_t{0}} + }; +} + +TFileSet::~TFileSet() { + // @@protoc_insertion_point(destructor:tutorial.TFileSet) + if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void TFileSet::SharedDtor() { + GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); + _impl_.files_.~RepeatedPtrField(); +} + +void TFileSet::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void TFileSet::Clear() { +// @@protoc_insertion_point(message_clear_start:tutorial.TFileSet) + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.files_.Clear(); + _impl_.hash_ = ::int64_t{0}; + _impl_._has_bits_.Clear(); + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* TFileSet::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { + +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + _Internal::HasBits has_bits{}; + while (!ctx->Done(&ptr)) { + ::uint32_t tag; + ptr = ::_pbi::ReadTag(ptr, &tag); + switch (tag >> 3) { + // repeated .tutorial.TFile Files = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 10)) { + ptr -= 1; + do { + ptr += 1; + ptr = ctx->ParseMessage(_internal_add_files(), ptr); + CHK_(ptr); + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr)); + } else { + goto handle_unusual; + } + continue; + // required int64 Hash = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 16)) { + _Internal::set_has_hash(&has_bits); + _impl_.hash_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); + CHK_(ptr); + } else { + goto handle_unusual; + } + continue; + default: + goto handle_unusual; + } // switch + handle_unusual: + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); + ctx->SetLastTag(tag); + goto message_done; + } + ptr = UnknownFieldParse( + tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + _impl_._has_bits_.Or(has_bits); + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +::uint8_t* TFileSet::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + + // @@protoc_insertion_point(serialize_to_array_start:tutorial.TFileSet) + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + // repeated .tutorial.TFile Files = 1; + for (unsigned i = 0, + n = static_cast(this->_internal_files_size()); i < n; i++) { + const auto& repfield = this->_internal_files(i); + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: + InternalWriteMessage(1, repfield, repfield.GetCachedSize(), target, stream); + } + + cached_has_bits = _impl_._has_bits_[0]; + // required int64 Hash = 2; + if (cached_has_bits & 0x00000001u) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteInt64ToArray(2, this->_internal_hash(), target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:tutorial.TFileSet) + return target; +} + +::size_t TFileSet::ByteSizeLong() const { + +// @@protoc_insertion_point(message_byte_size_start:tutorial.TFileSet) + ::size_t total_size = 0; + + // required int64 Hash = 2; + if (_internal_has_hash()) { + total_size += ::_pbi::WireFormatLite::Int64SizePlusOne(this->_internal_hash()); + } + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // repeated .tutorial.TFile Files = 1; + total_size += 1UL * this->_internal_files_size(); + for (const auto& msg : this->_impl_.files_) { + total_size += + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(msg); + } + + return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); +} + +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TFileSet::_class_data_ = { + ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, + TFileSet::MergeImpl +}; +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TFileSet::GetClassData() const { return &_class_data_; } + + +void TFileSet::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + + // @@protoc_insertion_point(class_specific_merge_from_start:tutorial.TFileSet) + GOOGLE_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + _this->_impl_.files_.MergeFrom(from._impl_.files_); + if (from._internal_has_hash()) { + _this->_internal_set_hash(from._internal_hash()); + } + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); +} + +void TFileSet::CopyFrom(const TFileSet& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:tutorial.TFileSet) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool TFileSet::IsInitialized() const { + if (_Internal::MissingRequiredFields(_impl_._has_bits_)) return false; + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(_impl_.files_)) + return false; + return true; +} + +void TFileSet::InternalSwap(TFileSet* other) { + using std::swap; + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]); + _impl_.files_.InternalSwap(&other->_impl_.files_); + swap(_impl_.hash_, other->_impl_.hash_); +} + +::PROTOBUF_NAMESPACE_ID::Metadata TFileSet::GetMetadata() const { + + return ::_pbi::AssignDescriptors( + &descriptor_table_messge_2eproto_getter, &descriptor_table_messge_2eproto_once, + file_level_metadata_messge_2eproto[1]); +} +// =================================================================== + +class TReport::_Internal { + public: +}; + +TReport::TReport(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned) + : ::PROTOBUF_NAMESPACE_ID::Message(arena, is_message_owned) { + SharedCtor(arena, is_message_owned); + // @@protoc_insertion_point(arena_constructor:tutorial.TReport) +} +TReport::TReport(const TReport& from) + : ::PROTOBUF_NAMESPACE_ID::Message() { + TReport* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.nums_){from._impl_.nums_} + , decltype(_impl_.strings_){from._impl_.strings_} + , decltype(_impl_.setsoffiles_){from._impl_.setsoffiles_} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + // @@protoc_insertion_point(copy_constructor:tutorial.TReport) +} + +inline void TReport::SharedCtor( + ::_pb::Arena* arena, bool is_message_owned) { + (void)arena; + (void)is_message_owned; + new (&_impl_) Impl_{ + decltype(_impl_.nums_){arena} + , decltype(_impl_.strings_){arena} + , decltype(_impl_.setsoffiles_){arena} + , /*decltype(_impl_._cached_size_)*/{} + }; +} + +TReport::~TReport() { + // @@protoc_insertion_point(destructor:tutorial.TReport) + if (auto *arena = _internal_metadata_.DeleteReturnArena<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void TReport::SharedDtor() { + GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); + _impl_.nums_.~RepeatedField(); + _impl_.strings_.~RepeatedPtrField(); + _impl_.setsoffiles_.~RepeatedPtrField(); +} + +void TReport::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void TReport::Clear() { +// @@protoc_insertion_point(message_clear_start:tutorial.TReport) + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.nums_.Clear(); + _impl_.strings_.Clear(); + _impl_.setsoffiles_.Clear(); + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* TReport::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) { + +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + while (!ctx->Done(&ptr)) { + ::uint32_t tag; + ptr = ::_pbi::ReadTag(ptr, &tag); + switch (tag >> 3) { + // repeated int32 Nums = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 8)) { + ptr -= 1; + do { + ptr += 1; + _internal_add_nums(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr)); + CHK_(ptr); + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<8>(ptr)); + } else if (static_cast<::uint8_t>(tag) == 10) { + ptr = ::PROTOBUF_NAMESPACE_ID::internal::PackedInt32Parser(_internal_mutable_nums(), ptr, ctx); + CHK_(ptr); + } else { + goto handle_unusual; + } + continue; + // repeated string Strings = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 18)) { + ptr -= 1; + do { + ptr += 1; + auto str = _internal_add_strings(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + #ifndef NDEBUG + ::_pbi::VerifyUTF8(str, "tutorial.TReport.Strings"); + #endif // !NDEBUG + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<18>(ptr)); + } else { + goto handle_unusual; + } + continue; + // repeated .tutorial.TFileSet SetsOfFiles = 3; + case 3: + if (PROTOBUF_PREDICT_TRUE(static_cast<::uint8_t>(tag) == 26)) { + ptr -= 1; + do { + ptr += 1; + ptr = ctx->ParseMessage(_internal_add_setsoffiles(), ptr); + CHK_(ptr); + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<26>(ptr)); + } else { + goto handle_unusual; + } + continue; + default: + goto handle_unusual; + } // switch + handle_unusual: + if ((tag == 0) || ((tag & 7) == 4)) { + CHK_(ptr); + ctx->SetLastTag(tag); + goto message_done; + } + ptr = UnknownFieldParse( + tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +::uint8_t* TReport::_InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + + // @@protoc_insertion_point(serialize_to_array_start:tutorial.TReport) + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + // repeated int32 Nums = 1; + for (int i = 0, n = this->_internal_nums_size(); i < n; i++) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteInt32ToArray(1, this->_internal_nums(i), target); + } + + // repeated string Strings = 2; + for (int i = 0, n = this->_internal_strings_size(); i < n; i++) { + const auto& s = this->_internal_strings(i); + ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::VerifyUTF8StringNamedField( + s.data(), static_cast(s.length()), + ::PROTOBUF_NAMESPACE_ID::internal::WireFormat::SERIALIZE, + "tutorial.TReport.Strings"); + target = stream->WriteString(2, s, target); + } + + // repeated .tutorial.TFileSet SetsOfFiles = 3; + for (unsigned i = 0, + n = static_cast(this->_internal_setsoffiles_size()); i < n; i++) { + const auto& repfield = this->_internal_setsoffiles(i); + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: + InternalWriteMessage(3, repfield, repfield.GetCachedSize(), target, stream); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray( + _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance), target, stream); + } + // @@protoc_insertion_point(serialize_to_array_end:tutorial.TReport) + return target; +} + +::size_t TReport::ByteSizeLong() const { + +// @@protoc_insertion_point(message_byte_size_start:tutorial.TReport) + ::size_t total_size = 0; + + ::uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // repeated int32 Nums = 1; + { + ::size_t data_size = ::_pbi::WireFormatLite:: + Int32Size(this->_impl_.nums_); + total_size += 1 * + ::_pbi::FromIntSize(this->_internal_nums_size()); + total_size += data_size; + } + + // repeated string Strings = 2; + total_size += 1 * + ::PROTOBUF_NAMESPACE_ID::internal::FromIntSize(_impl_.strings_.size()); + for (int i = 0, n = _impl_.strings_.size(); i < n; i++) { + total_size += ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + _impl_.strings_.Get(i)); + } + + // repeated .tutorial.TFileSet SetsOfFiles = 3; + total_size += 1UL * this->_internal_setsoffiles_size(); + for (const auto& msg : this->_impl_.setsoffiles_) { + total_size += + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(msg); + } + + return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_); +} + +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData TReport::_class_data_ = { + ::PROTOBUF_NAMESPACE_ID::Message::CopyWithSourceCheck, + TReport::MergeImpl +}; +const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*TReport::GetClassData() const { return &_class_data_; } + + +void TReport::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg) { + auto* const _this = static_cast(&to_msg); + auto& from = static_cast(from_msg); + + // @@protoc_insertion_point(class_specific_merge_from_start:tutorial.TReport) + GOOGLE_DCHECK_NE(&from, _this); + ::uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + _this->_impl_.nums_.MergeFrom(from._impl_.nums_); + _this->_impl_.strings_.MergeFrom(from._impl_.strings_); + _this->_impl_.setsoffiles_.MergeFrom(from._impl_.setsoffiles_); + _this->_internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); +} + +void TReport::CopyFrom(const TReport& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:tutorial.TReport) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool TReport::IsInitialized() const { + if (!::PROTOBUF_NAMESPACE_ID::internal::AllAreInitialized(_impl_.setsoffiles_)) + return false; + return true; +} + +void TReport::InternalSwap(TReport* other) { + using std::swap; + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + _impl_.nums_.InternalSwap(&other->_impl_.nums_); + _impl_.strings_.InternalSwap(&other->_impl_.strings_); + _impl_.setsoffiles_.InternalSwap(&other->_impl_.setsoffiles_); +} + +::PROTOBUF_NAMESPACE_ID::Metadata TReport::GetMetadata() const { + + return ::_pbi::AssignDescriptors( + &descriptor_table_messge_2eproto_getter, &descriptor_table_messge_2eproto_once, + file_level_metadata_messge_2eproto[2]); +} +// @@protoc_insertion_point(namespace_scope) +} // namespace tutorial +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_NOINLINE ::tutorial::TFile* +Arena::CreateMaybeMessage< ::tutorial::TFile >(Arena* arena) { + return Arena::CreateMessageInternal< ::tutorial::TFile >(arena); +} +template<> PROTOBUF_NOINLINE ::tutorial::TFileSet* +Arena::CreateMaybeMessage< ::tutorial::TFileSet >(Arena* arena) { + return Arena::CreateMessageInternal< ::tutorial::TFileSet >(arena); +} +template<> PROTOBUF_NOINLINE ::tutorial::TReport* +Arena::CreateMaybeMessage< ::tutorial::TReport >(Arena* arena) { + return Arena::CreateMessageInternal< ::tutorial::TReport >(arena); +} +PROTOBUF_NAMESPACE_CLOSE +// @@protoc_insertion_point(global_scope) +#include "google/protobuf/port_undef.inc" diff --git a/messages/messge.pb.h b/messages/messge.pb.h new file mode 100644 index 0000000..f568e41 --- /dev/null +++ b/messages/messge.pb.h @@ -0,0 +1,1107 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: messge.proto + +#ifndef GOOGLE_PROTOBUF_INCLUDED_messge_2eproto_2epb_2eh +#define GOOGLE_PROTOBUF_INCLUDED_messge_2eproto_2epb_2eh + +#include +#include +#include + +#include "google/protobuf/port_def.inc" +#if PROTOBUF_VERSION < 3021000 +#error "This file was generated by a newer version of protoc which is" +#error "incompatible with your Protocol Buffer headers. Please update" +#error "your headers." +#endif // PROTOBUF_VERSION + +#if 3021009 < PROTOBUF_MIN_PROTOC_VERSION +#error "This file was generated by an older version of protoc which is" +#error "incompatible with your Protocol Buffer headers. Please" +#error "regenerate this file with a newer version of protoc." +#endif // PROTOBUF_MIN_PROTOC_VERSION +#include "google/protobuf/port_undef.inc" +#include "google/protobuf/io/coded_stream.h" +#include "google/protobuf/arena.h" +#include "google/protobuf/arenastring.h" +#include "google/protobuf/generated_message_util.h" +#include "google/protobuf/metadata_lite.h" +#include "google/protobuf/generated_message_reflection.h" +#include "google/protobuf/message.h" +#include "google/protobuf/repeated_field.h" // IWYU pragma: export +#include "google/protobuf/extension_set.h" // IWYU pragma: export +#include "google/protobuf/unknown_field_set.h" +// @@protoc_insertion_point(includes) + +// Must be included last. +#include "google/protobuf/port_def.inc" + +#define PROTOBUF_INTERNAL_EXPORT_messge_2eproto + +PROTOBUF_NAMESPACE_OPEN +namespace internal { +class AnyMetadata; +} // namespace internal +PROTOBUF_NAMESPACE_CLOSE + +// Internal implementation detail -- do not use these members. +struct TableStruct_messge_2eproto { + static const ::uint32_t offsets[]; +}; +extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable + descriptor_table_messge_2eproto; +namespace tutorial { +class TFile; +struct TFileDefaultTypeInternal; +extern TFileDefaultTypeInternal _TFile_default_instance_; +class TFileSet; +struct TFileSetDefaultTypeInternal; +extern TFileSetDefaultTypeInternal _TFileSet_default_instance_; +class TReport; +struct TReportDefaultTypeInternal; +extern TReportDefaultTypeInternal _TReport_default_instance_; +} // namespace tutorial +PROTOBUF_NAMESPACE_OPEN +template <> +::tutorial::TFile* Arena::CreateMaybeMessage<::tutorial::TFile>(Arena*); +template <> +::tutorial::TFileSet* Arena::CreateMaybeMessage<::tutorial::TFileSet>(Arena*); +template <> +::tutorial::TReport* Arena::CreateMaybeMessage<::tutorial::TReport>(Arena*); +PROTOBUF_NAMESPACE_CLOSE + +namespace tutorial { + +// =================================================================== + + +// ------------------------------------------------------------------- + +class TFile final : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:tutorial.TFile) */ { + public: + inline TFile() : TFile(nullptr) {} + ~TFile() override; + explicit PROTOBUF_CONSTEXPR TFile(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + TFile(const TFile& from); + TFile(TFile&& from) noexcept + : TFile() { + *this = ::std::move(from); + } + + inline TFile& operator=(const TFile& from) { + CopyFrom(from); + return *this; + } + inline TFile& operator=(TFile&& from) noexcept { + if (this == &from) return *this; + if (GetOwningArena() == from.GetOwningArena() + #ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetOwningArena() != nullptr + #endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); + } + inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const TFile& default_instance() { + return *internal_default_instance(); + } + static inline const TFile* internal_default_instance() { + return reinterpret_cast( + &_TFile_default_instance_); + } + static constexpr int kIndexInFileMessages = + 0; + + friend void swap(TFile& a, TFile& b) { + a.Swap(&b); + } + inline void Swap(TFile* other) { + if (other == this) return; + #ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() != nullptr && + GetOwningArena() == other->GetOwningArena()) { + #else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() == other->GetOwningArena()) { + #endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(TFile* other) { + if (other == this) return; + GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + TFile* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage(arena); + } + using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; + void CopyFrom(const TFile& from); + using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; + void MergeFrom( const TFile& from) { + TFile::MergeImpl(*this, from); + } + private: + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); + public: + PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; + bool IsInitialized() const final; + + ::size_t ByteSizeLong() const final; + const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned); + void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(TFile* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { + return "tutorial.TFile"; + } + protected: + explicit TFile(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned = false); + public: + + static const ClassData _class_data_; + const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kWeightsFieldNumber = 1, + kHostsFieldNumber = 3, + kNameFieldNumber = 2, + }; + // repeated float Weights = 1; + int weights_size() const; + private: + int _internal_weights_size() const; + public: + void clear_weights(); + private: + float _internal_weights(int index) const; + const ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >& + _internal_weights() const; + void _internal_add_weights(float value); + ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >* + _internal_mutable_weights(); + public: + float weights(int index) const; + void set_weights(int index, float value); + void add_weights(float value); + const ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >& + weights() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >* + mutable_weights(); + + // repeated int32 Hosts = 3; + int hosts_size() const; + private: + int _internal_hosts_size() const; + public: + void clear_hosts(); + private: + ::int32_t _internal_hosts(int index) const; + const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >& + _internal_hosts() const; + void _internal_add_hosts(::int32_t value); + ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >* + _internal_mutable_hosts(); + public: + ::int32_t hosts(int index) const; + void set_hosts(int index, ::int32_t value); + void add_hosts(::int32_t value); + const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >& + hosts() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >* + mutable_hosts(); + + // required string Name = 2; + bool has_name() const; + private: + bool _internal_has_name() const; + public: + void clear_name(); + const std::string& name() const; + template + void set_name(ArgT0&& arg0, ArgT... args); + std::string* mutable_name(); + PROTOBUF_NODISCARD std::string* release_name(); + void set_allocated_name(std::string* name); + private: + const std::string& _internal_name() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_name(const std::string& value); + std::string* _internal_mutable_name(); + public: + + // @@protoc_insertion_point(class_scope:tutorial.TFile) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + ::PROTOBUF_NAMESPACE_ID::RepeatedField< float > weights_; + ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t > hosts_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_messge_2eproto; +};// ------------------------------------------------------------------- + +class TFileSet final : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:tutorial.TFileSet) */ { + public: + inline TFileSet() : TFileSet(nullptr) {} + ~TFileSet() override; + explicit PROTOBUF_CONSTEXPR TFileSet(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + TFileSet(const TFileSet& from); + TFileSet(TFileSet&& from) noexcept + : TFileSet() { + *this = ::std::move(from); + } + + inline TFileSet& operator=(const TFileSet& from) { + CopyFrom(from); + return *this; + } + inline TFileSet& operator=(TFileSet&& from) noexcept { + if (this == &from) return *this; + if (GetOwningArena() == from.GetOwningArena() + #ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetOwningArena() != nullptr + #endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); + } + inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const TFileSet& default_instance() { + return *internal_default_instance(); + } + static inline const TFileSet* internal_default_instance() { + return reinterpret_cast( + &_TFileSet_default_instance_); + } + static constexpr int kIndexInFileMessages = + 1; + + friend void swap(TFileSet& a, TFileSet& b) { + a.Swap(&b); + } + inline void Swap(TFileSet* other) { + if (other == this) return; + #ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() != nullptr && + GetOwningArena() == other->GetOwningArena()) { + #else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() == other->GetOwningArena()) { + #endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(TFileSet* other) { + if (other == this) return; + GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + TFileSet* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage(arena); + } + using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; + void CopyFrom(const TFileSet& from); + using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; + void MergeFrom( const TFileSet& from) { + TFileSet::MergeImpl(*this, from); + } + private: + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); + public: + PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; + bool IsInitialized() const final; + + ::size_t ByteSizeLong() const final; + const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned); + void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(TFileSet* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { + return "tutorial.TFileSet"; + } + protected: + explicit TFileSet(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned = false); + public: + + static const ClassData _class_data_; + const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kFilesFieldNumber = 1, + kHashFieldNumber = 2, + }; + // repeated .tutorial.TFile Files = 1; + int files_size() const; + private: + int _internal_files_size() const; + public: + void clear_files(); + ::tutorial::TFile* mutable_files(int index); + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::TFile >* + mutable_files(); + private: + const ::tutorial::TFile& _internal_files(int index) const; + ::tutorial::TFile* _internal_add_files(); + public: + const ::tutorial::TFile& files(int index) const; + ::tutorial::TFile* add_files(); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::TFile >& + files() const; + + // required int64 Hash = 2; + bool has_hash() const; + private: + bool _internal_has_hash() const; + public: + void clear_hash(); + ::int64_t hash() const; + void set_hash(::int64_t value); + private: + ::int64_t _internal_hash() const; + void _internal_set_hash(::int64_t value); + public: + + // @@protoc_insertion_point(class_scope:tutorial.TFileSet) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::TFile > files_; + ::int64_t hash_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_messge_2eproto; +};// ------------------------------------------------------------------- + +class TReport final : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:tutorial.TReport) */ { + public: + inline TReport() : TReport(nullptr) {} + ~TReport() override; + explicit PROTOBUF_CONSTEXPR TReport(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + TReport(const TReport& from); + TReport(TReport&& from) noexcept + : TReport() { + *this = ::std::move(from); + } + + inline TReport& operator=(const TReport& from) { + CopyFrom(from); + return *this; + } + inline TReport& operator=(TReport&& from) noexcept { + if (this == &from) return *this; + if (GetOwningArena() == from.GetOwningArena() + #ifdef PROTOBUF_FORCE_COPY_IN_MOVE + && GetOwningArena() != nullptr + #endif // !PROTOBUF_FORCE_COPY_IN_MOVE + ) { + InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + inline const ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet& unknown_fields() const { + return _internal_metadata_.unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(::PROTOBUF_NAMESPACE_ID::UnknownFieldSet::default_instance); + } + inline ::PROTOBUF_NAMESPACE_ID::UnknownFieldSet* mutable_unknown_fields() { + return _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return default_instance().GetMetadata().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return default_instance().GetMetadata().reflection; + } + static const TReport& default_instance() { + return *internal_default_instance(); + } + static inline const TReport* internal_default_instance() { + return reinterpret_cast( + &_TReport_default_instance_); + } + static constexpr int kIndexInFileMessages = + 2; + + friend void swap(TReport& a, TReport& b) { + a.Swap(&b); + } + inline void Swap(TReport* other) { + if (other == this) return; + #ifdef PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() != nullptr && + GetOwningArena() == other->GetOwningArena()) { + #else // PROTOBUF_FORCE_COPY_IN_SWAP + if (GetOwningArena() == other->GetOwningArena()) { + #endif // !PROTOBUF_FORCE_COPY_IN_SWAP + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(TReport* other) { + if (other == this) return; + GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + TReport* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage(arena); + } + using ::PROTOBUF_NAMESPACE_ID::Message::CopyFrom; + void CopyFrom(const TReport& from); + using ::PROTOBUF_NAMESPACE_ID::Message::MergeFrom; + void MergeFrom( const TReport& from) { + TReport::MergeImpl(*this, from); + } + private: + static void MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOBUF_NAMESPACE_ID::Message& from_msg); + public: + PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final; + bool IsInitialized() const final; + + ::size_t ByteSizeLong() const final; + const char* _InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) final; + ::uint8_t* _InternalSerialize( + ::uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _impl_._cached_size_.Get(); } + + private: + void SharedCtor(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned); + void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(TReport* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::absl::string_view FullMessageName() { + return "tutorial.TReport"; + } + protected: + explicit TReport(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned = false); + public: + + static const ClassData _class_data_; + const ::PROTOBUF_NAMESPACE_ID::Message::ClassData*GetClassData() const final; + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kNumsFieldNumber = 1, + kStringsFieldNumber = 2, + kSetsOfFilesFieldNumber = 3, + }; + // repeated int32 Nums = 1; + int nums_size() const; + private: + int _internal_nums_size() const; + public: + void clear_nums(); + private: + ::int32_t _internal_nums(int index) const; + const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >& + _internal_nums() const; + void _internal_add_nums(::int32_t value); + ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >* + _internal_mutable_nums(); + public: + ::int32_t nums(int index) const; + void set_nums(int index, ::int32_t value); + void add_nums(::int32_t value); + const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >& + nums() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >* + mutable_nums(); + + // repeated string Strings = 2; + int strings_size() const; + private: + int _internal_strings_size() const; + public: + void clear_strings(); + const std::string& strings(int index) const; + std::string* mutable_strings(int index); + void set_strings(int index, const std::string& value); + void set_strings(int index, std::string&& value); + void set_strings(int index, const char* value); + void set_strings(int index, const char* value, ::size_t size); + std::string* add_strings(); + void add_strings(const std::string& value); + void add_strings(std::string&& value); + void add_strings(const char* value); + void add_strings(const char* value, ::size_t size); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& strings() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* mutable_strings(); + private: + const std::string& _internal_strings(int index) const; + std::string* _internal_add_strings(); + public: + + // repeated .tutorial.TFileSet SetsOfFiles = 3; + int setsoffiles_size() const; + private: + int _internal_setsoffiles_size() const; + public: + void clear_setsoffiles(); + ::tutorial::TFileSet* mutable_setsoffiles(int index); + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::TFileSet >* + mutable_setsoffiles(); + private: + const ::tutorial::TFileSet& _internal_setsoffiles(int index) const; + ::tutorial::TFileSet* _internal_add_setsoffiles(); + public: + const ::tutorial::TFileSet& setsoffiles(int index) const; + ::tutorial::TFileSet* add_setsoffiles(); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::TFileSet >& + setsoffiles() const; + + // @@protoc_insertion_point(class_scope:tutorial.TReport) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t > nums_; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField strings_; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::TFileSet > setsoffiles_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_messge_2eproto; +}; +// =================================================================== + + + + +// =================================================================== + + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// ------------------------------------------------------------------- + +// TFile + +// repeated float Weights = 1; +inline int TFile::_internal_weights_size() const { + return _impl_.weights_.size(); +} +inline int TFile::weights_size() const { + return _internal_weights_size(); +} +inline void TFile::clear_weights() { + _impl_.weights_.Clear(); +} +inline float TFile::_internal_weights(int index) const { + return _impl_.weights_.Get(index); +} +inline float TFile::weights(int index) const { + // @@protoc_insertion_point(field_get:tutorial.TFile.Weights) + return _internal_weights(index); +} +inline void TFile::set_weights(int index, float value) { + _impl_.weights_.Set(index, value); + // @@protoc_insertion_point(field_set:tutorial.TFile.Weights) +} +inline void TFile::_internal_add_weights(float value) { + _impl_.weights_.Add(value); +} +inline void TFile::add_weights(float value) { + _internal_add_weights(value); + // @@protoc_insertion_point(field_add:tutorial.TFile.Weights) +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >& +TFile::_internal_weights() const { + return _impl_.weights_; +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >& +TFile::weights() const { + // @@protoc_insertion_point(field_list:tutorial.TFile.Weights) + return _internal_weights(); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >* +TFile::_internal_mutable_weights() { + return &_impl_.weights_; +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedField< float >* +TFile::mutable_weights() { + // @@protoc_insertion_point(field_mutable_list:tutorial.TFile.Weights) + return _internal_mutable_weights(); +} + +// required string Name = 2; +inline bool TFile::_internal_has_name() const { + bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0; + return value; +} +inline bool TFile::has_name() const { + return _internal_has_name(); +} +inline void TFile::clear_name() { + _impl_.name_.ClearToEmpty(); + _impl_._has_bits_[0] &= ~0x00000001u; +} +inline const std::string& TFile::name() const { + // @@protoc_insertion_point(field_get:tutorial.TFile.Name) + return _internal_name(); +} +template +inline PROTOBUF_ALWAYS_INLINE +void TFile::set_name(ArgT0&& arg0, ArgT... args) { + _impl_._has_bits_[0] |= 0x00000001u; + _impl_.name_.Set(static_cast(arg0), args..., GetArenaForAllocation()); + // @@protoc_insertion_point(field_set:tutorial.TFile.Name) +} +inline std::string* TFile::mutable_name() { + std::string* _s = _internal_mutable_name(); + // @@protoc_insertion_point(field_mutable:tutorial.TFile.Name) + return _s; +} +inline const std::string& TFile::_internal_name() const { + return _impl_.name_.Get(); +} +inline void TFile::_internal_set_name(const std::string& value) { + _impl_._has_bits_[0] |= 0x00000001u; + _impl_.name_.Set(value, GetArenaForAllocation()); +} +inline std::string* TFile::_internal_mutable_name() { + _impl_._has_bits_[0] |= 0x00000001u; + return _impl_.name_.Mutable(GetArenaForAllocation()); +} +inline std::string* TFile::release_name() { + // @@protoc_insertion_point(field_release:tutorial.TFile.Name) + if (!_internal_has_name()) { + return nullptr; + } + _impl_._has_bits_[0] &= ~0x00000001u; + auto* p = _impl_.name_.Release(); +#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.name_.Set("", GetArenaForAllocation()); +#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + return p; +} +inline void TFile::set_allocated_name(std::string* name) { + if (name != nullptr) { + _impl_._has_bits_[0] |= 0x00000001u; + } else { + _impl_._has_bits_[0] &= ~0x00000001u; + } + _impl_.name_.SetAllocated(name, GetArenaForAllocation()); +#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.name_.IsDefault()) { + _impl_.name_.Set("", GetArenaForAllocation()); + } +#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:tutorial.TFile.Name) +} + +// repeated int32 Hosts = 3; +inline int TFile::_internal_hosts_size() const { + return _impl_.hosts_.size(); +} +inline int TFile::hosts_size() const { + return _internal_hosts_size(); +} +inline void TFile::clear_hosts() { + _impl_.hosts_.Clear(); +} +inline ::int32_t TFile::_internal_hosts(int index) const { + return _impl_.hosts_.Get(index); +} +inline ::int32_t TFile::hosts(int index) const { + // @@protoc_insertion_point(field_get:tutorial.TFile.Hosts) + return _internal_hosts(index); +} +inline void TFile::set_hosts(int index, ::int32_t value) { + _impl_.hosts_.Set(index, value); + // @@protoc_insertion_point(field_set:tutorial.TFile.Hosts) +} +inline void TFile::_internal_add_hosts(::int32_t value) { + _impl_.hosts_.Add(value); +} +inline void TFile::add_hosts(::int32_t value) { + _internal_add_hosts(value); + // @@protoc_insertion_point(field_add:tutorial.TFile.Hosts) +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >& +TFile::_internal_hosts() const { + return _impl_.hosts_; +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >& +TFile::hosts() const { + // @@protoc_insertion_point(field_list:tutorial.TFile.Hosts) + return _internal_hosts(); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >* +TFile::_internal_mutable_hosts() { + return &_impl_.hosts_; +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >* +TFile::mutable_hosts() { + // @@protoc_insertion_point(field_mutable_list:tutorial.TFile.Hosts) + return _internal_mutable_hosts(); +} + +// ------------------------------------------------------------------- + +// TFileSet + +// repeated .tutorial.TFile Files = 1; +inline int TFileSet::_internal_files_size() const { + return _impl_.files_.size(); +} +inline int TFileSet::files_size() const { + return _internal_files_size(); +} +inline void TFileSet::clear_files() { + _impl_.files_.Clear(); +} +inline ::tutorial::TFile* TFileSet::mutable_files(int index) { + // @@protoc_insertion_point(field_mutable:tutorial.TFileSet.Files) + return _impl_.files_.Mutable(index); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::TFile >* +TFileSet::mutable_files() { + // @@protoc_insertion_point(field_mutable_list:tutorial.TFileSet.Files) + return &_impl_.files_; +} +inline const ::tutorial::TFile& TFileSet::_internal_files(int index) const { + return _impl_.files_.Get(index); +} +inline const ::tutorial::TFile& TFileSet::files(int index) const { + // @@protoc_insertion_point(field_get:tutorial.TFileSet.Files) + return _internal_files(index); +} +inline ::tutorial::TFile* TFileSet::_internal_add_files() { + return _impl_.files_.Add(); +} +inline ::tutorial::TFile* TFileSet::add_files() { + ::tutorial::TFile* _add = _internal_add_files(); + // @@protoc_insertion_point(field_add:tutorial.TFileSet.Files) + return _add; +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::TFile >& +TFileSet::files() const { + // @@protoc_insertion_point(field_list:tutorial.TFileSet.Files) + return _impl_.files_; +} + +// required int64 Hash = 2; +inline bool TFileSet::_internal_has_hash() const { + bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0; + return value; +} +inline bool TFileSet::has_hash() const { + return _internal_has_hash(); +} +inline void TFileSet::clear_hash() { + _impl_.hash_ = ::int64_t{0}; + _impl_._has_bits_[0] &= ~0x00000001u; +} +inline ::int64_t TFileSet::_internal_hash() const { + return _impl_.hash_; +} +inline ::int64_t TFileSet::hash() const { + // @@protoc_insertion_point(field_get:tutorial.TFileSet.Hash) + return _internal_hash(); +} +inline void TFileSet::_internal_set_hash(::int64_t value) { + _impl_._has_bits_[0] |= 0x00000001u; + _impl_.hash_ = value; +} +inline void TFileSet::set_hash(::int64_t value) { + _internal_set_hash(value); + // @@protoc_insertion_point(field_set:tutorial.TFileSet.Hash) +} + +// ------------------------------------------------------------------- + +// TReport + +// repeated int32 Nums = 1; +inline int TReport::_internal_nums_size() const { + return _impl_.nums_.size(); +} +inline int TReport::nums_size() const { + return _internal_nums_size(); +} +inline void TReport::clear_nums() { + _impl_.nums_.Clear(); +} +inline ::int32_t TReport::_internal_nums(int index) const { + return _impl_.nums_.Get(index); +} +inline ::int32_t TReport::nums(int index) const { + // @@protoc_insertion_point(field_get:tutorial.TReport.Nums) + return _internal_nums(index); +} +inline void TReport::set_nums(int index, ::int32_t value) { + _impl_.nums_.Set(index, value); + // @@protoc_insertion_point(field_set:tutorial.TReport.Nums) +} +inline void TReport::_internal_add_nums(::int32_t value) { + _impl_.nums_.Add(value); +} +inline void TReport::add_nums(::int32_t value) { + _internal_add_nums(value); + // @@protoc_insertion_point(field_add:tutorial.TReport.Nums) +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >& +TReport::_internal_nums() const { + return _impl_.nums_; +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >& +TReport::nums() const { + // @@protoc_insertion_point(field_list:tutorial.TReport.Nums) + return _internal_nums(); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >* +TReport::_internal_mutable_nums() { + return &_impl_.nums_; +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::int32_t >* +TReport::mutable_nums() { + // @@protoc_insertion_point(field_mutable_list:tutorial.TReport.Nums) + return _internal_mutable_nums(); +} + +// repeated string Strings = 2; +inline int TReport::_internal_strings_size() const { + return _impl_.strings_.size(); +} +inline int TReport::strings_size() const { + return _internal_strings_size(); +} +inline void TReport::clear_strings() { + _impl_.strings_.Clear(); +} +inline std::string* TReport::add_strings() { + std::string* _s = _internal_add_strings(); + // @@protoc_insertion_point(field_add_mutable:tutorial.TReport.Strings) + return _s; +} +inline const std::string& TReport::_internal_strings(int index) const { + return _impl_.strings_.Get(index); +} +inline const std::string& TReport::strings(int index) const { + // @@protoc_insertion_point(field_get:tutorial.TReport.Strings) + return _internal_strings(index); +} +inline std::string* TReport::mutable_strings(int index) { + // @@protoc_insertion_point(field_mutable:tutorial.TReport.Strings) + return _impl_.strings_.Mutable(index); +} +inline void TReport::set_strings(int index, const std::string& value) { + _impl_.strings_.Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set:tutorial.TReport.Strings) +} +inline void TReport::set_strings(int index, std::string&& value) { + _impl_.strings_.Mutable(index)->assign(std::move(value)); + // @@protoc_insertion_point(field_set:tutorial.TReport.Strings) +} +inline void TReport::set_strings(int index, const char* value) { + GOOGLE_DCHECK(value != nullptr); _impl_.strings_.Mutable(index)->assign(value); + // @@protoc_insertion_point(field_set_char:tutorial.TReport.Strings) +} +inline void TReport::set_strings(int index, const char* value, ::size_t size) { + _impl_.strings_.Mutable(index)->assign( + reinterpret_cast(value), size); + // @@protoc_insertion_point(field_set_pointer:tutorial.TReport.Strings) +} +inline std::string* TReport::_internal_add_strings() { + return _impl_.strings_.Add(); +} +inline void TReport::add_strings(const std::string& value) { + _impl_.strings_.Add()->assign(value); + // @@protoc_insertion_point(field_add:tutorial.TReport.Strings) +} +inline void TReport::add_strings(std::string&& value) { + _impl_.strings_.Add(std::move(value)); + // @@protoc_insertion_point(field_add:tutorial.TReport.Strings) +} +inline void TReport::add_strings(const char* value) { + GOOGLE_DCHECK(value != nullptr); _impl_.strings_.Add()->assign(value); + // @@protoc_insertion_point(field_add_char:tutorial.TReport.Strings) +} +inline void TReport::add_strings(const char* value, ::size_t size) { + _impl_.strings_.Add()->assign(reinterpret_cast(value), size); + // @@protoc_insertion_point(field_add_pointer:tutorial.TReport.Strings) +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField& +TReport::strings() const { + // @@protoc_insertion_point(field_list:tutorial.TReport.Strings) + return _impl_.strings_; +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField* +TReport::mutable_strings() { + // @@protoc_insertion_point(field_mutable_list:tutorial.TReport.Strings) + return &_impl_.strings_; +} + +// repeated .tutorial.TFileSet SetsOfFiles = 3; +inline int TReport::_internal_setsoffiles_size() const { + return _impl_.setsoffiles_.size(); +} +inline int TReport::setsoffiles_size() const { + return _internal_setsoffiles_size(); +} +inline void TReport::clear_setsoffiles() { + _impl_.setsoffiles_.Clear(); +} +inline ::tutorial::TFileSet* TReport::mutable_setsoffiles(int index) { + // @@protoc_insertion_point(field_mutable:tutorial.TReport.SetsOfFiles) + return _impl_.setsoffiles_.Mutable(index); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::TFileSet >* +TReport::mutable_setsoffiles() { + // @@protoc_insertion_point(field_mutable_list:tutorial.TReport.SetsOfFiles) + return &_impl_.setsoffiles_; +} +inline const ::tutorial::TFileSet& TReport::_internal_setsoffiles(int index) const { + return _impl_.setsoffiles_.Get(index); +} +inline const ::tutorial::TFileSet& TReport::setsoffiles(int index) const { + // @@protoc_insertion_point(field_get:tutorial.TReport.SetsOfFiles) + return _internal_setsoffiles(index); +} +inline ::tutorial::TFileSet* TReport::_internal_add_setsoffiles() { + return _impl_.setsoffiles_.Add(); +} +inline ::tutorial::TFileSet* TReport::add_setsoffiles() { + ::tutorial::TFileSet* _add = _internal_add_setsoffiles(); + // @@protoc_insertion_point(field_add:tutorial.TReport.SetsOfFiles) + return _add; +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::tutorial::TFileSet >& +TReport::setsoffiles() const { + // @@protoc_insertion_point(field_list:tutorial.TReport.SetsOfFiles) + return _impl_.setsoffiles_; +} + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // __GNUC__ + +// @@protoc_insertion_point(namespace_scope) +} // namespace tutorial + + +// @@protoc_insertion_point(global_scope) + +#include "google/protobuf/port_undef.inc" + +#endif // GOOGLE_PROTOBUF_INCLUDED_messge_2eproto_2epb_2eh diff --git a/messages/messge.proto b/messages/messge.proto new file mode 100644 index 0000000..9f760e7 --- /dev/null +++ b/messages/messge.proto @@ -0,0 +1,20 @@ +syntax = "proto2"; + +package tutorial; + +message TFile { + repeated float Weights = 1; + required string Name = 2; + repeated int32 Hosts = 3; +} + +message TFileSet { + repeated TFile Files = 1; + required int64 Hash = 2; +} + +message TReport { + repeated int32 Nums = 1; + repeated string Strings = 2; + repeated TFileSet SetsOfFiles = 3; +} \ No newline at end of file diff --git a/proto_gen/CMakeLists.txt b/proto_gen/CMakeLists.txt new file mode 100644 index 0000000..234e1e8 --- /dev/null +++ b/proto_gen/CMakeLists.txt @@ -0,0 +1,11 @@ +project(proto_gen) + +set(CMAKE_CXX_STANDARD 14) + +add_executable(${PROJECT_NAME}) +add_subdirectory(lib) + +target_sources(${PROJECT_NAME} PRIVATE main.cpp) +target_include_directories(${PROJECT_NAME} PRIVATE ${PROTO_MSG} ./lib) +target_link_libraries(${PROJECT_NAME} PRIVATE protobuf::libprotobuf gen_proto_lib) + diff --git a/proto_gen/lib/CMakeLists.txt b/proto_gen/lib/CMakeLists.txt new file mode 100644 index 0000000..f02a551 --- /dev/null +++ b/proto_gen/lib/CMakeLists.txt @@ -0,0 +1,15 @@ +project(gen_proto_lib) + +add_library(${PROJECT_NAME}) + +target_sources(${PROJECT_NAME} PRIVATE gen_data.cpp ${PROTO_MSG}/messge.pb.cc) +target_include_directories( + ${PROJECT_NAME} PUBLIC ${PROTO_MSG} + PUBLIC + # where top-level project will look for the library's public headers + $ + # where external projects will look for the library's public headers + $ +) + +target_link_libraries(${PROJECT_NAME} PRIVATE protobuf::libprotobuf) \ No newline at end of file diff --git a/proto_gen/lib/gen_data.cpp b/proto_gen/lib/gen_data.cpp new file mode 100644 index 0000000..2dffc92 --- /dev/null +++ b/proto_gen/lib/gen_data.cpp @@ -0,0 +1,54 @@ +#include "gen_data.h" + +namespace NGenProto { + +using namespace tutorial; + +TReport GenReport(const TGenOpts& opts) { + TReport res; + + for (size_t i = 0; i < opts.SetsOfFilesCount; i++) { + GenFileSet(res.add_setsoffiles(), opts); + } + + for (size_t i = 0; i < opts.NumsCount; i++) { + res.add_nums(rand()%1000); + } + + for (size_t i = 0; i < opts.StringsCount; i++) { + res.add_strings(GenString(opts.StringSize)); + } + + return res; +} + +void GenFile(TFile* val, const TGenOpts& opts) { + for (size_t i = 0; i < opts.FloatCount; i++) { + val->add_weights(0.1f); + } + + val->set_name(GenString(opts.StringSize)); + + for (size_t i = 0; i < opts.NumsCount; i++) { + val->add_hosts(rand() % 1000); + } +} + +void GenFileSet(TFileSet* val, const TGenOpts& opts) { + val->set_hash(rand()%1000); + + for (size_t i = 0; i < opts.FilesCount; i++) { + GenFile(val->add_files(), opts); + } +} + +std::string GenString(size_t size) { + std::string s; + for (size_t i = 0; i < size; i++) { + s += (char)(rand()%128); + } + + return s; +} + +} diff --git a/proto_gen/lib/gen_data.h b/proto_gen/lib/gen_data.h new file mode 100644 index 0000000..1ff8eae --- /dev/null +++ b/proto_gen/lib/gen_data.h @@ -0,0 +1,21 @@ +#pragma once +#include "messge.pb.h" +#include + +namespace NGenProto { + +struct TGenOpts { + size_t NumsCount = 0; + size_t StringsCount = 0; + size_t FloatCount = 0; + size_t StringSize = 0; + size_t FilesCount = 0; + size_t SetsOfFilesCount = 0; +}; + +std::string GenString(size_t size); +tutorial::TReport GenReport(const TGenOpts& opts); +void GenFileSet(tutorial::TFileSet* val, const TGenOpts& opts); +void GenFile(tutorial::TFile* val, const TGenOpts& opts); + +} \ No newline at end of file diff --git a/proto_gen/main.cpp b/proto_gen/main.cpp new file mode 100644 index 0000000..458e0e1 --- /dev/null +++ b/proto_gen/main.cpp @@ -0,0 +1,50 @@ +#include +#include +#include + +#include "messge.pb.h" +#include "opts.h" +#include "gen_data.h" + +using namespace tutorial; +using namespace NGenProto; + +int main(int argc, char** argv) { + TOpts opts; + std::string seed; + std::string outputFile; + std::string numsCount; + std::string stringsCount; + std::string stringSize; + std::string floatCount; + std::string filesInSetCount; + std::string setsOfFilesCount; + + opts.AddOpt("seed", &seed); + opts.AddOpt("out", &outputFile); + opts.AddOpt("nums_cnt", &numsCount); + opts.AddOpt("strings_cnt", &stringsCount); + opts.AddOpt("string_size", &stringSize); + opts.AddOpt("float_cnt", &floatCount); + opts.AddOpt("files_cnt", &filesInSetCount); + opts.AddOpt("sets_cnt", &setsOfFilesCount); + + opts.Parse(argc, argv); + + TGenOpts genOpt; + genOpt.NumsCount = stoui(numsCount); + genOpt.StringsCount = stoui(stringsCount); + genOpt.StringSize = stoui(stringSize); + genOpt.FloatCount = stoui(floatCount); + genOpt.SetsOfFilesCount = stoui(setsOfFilesCount); + genOpt.FilesCount = stoui(filesInSetCount); + + srand(stoui(seed)); + + TReport report = GenReport(genOpt); + + std::ofstream out(outputFile); + + out << report.SerializeAsString(); + out.close(); +} \ No newline at end of file diff --git a/proto_gen/opts.h b/proto_gen/opts.h new file mode 100644 index 0000000..a0861f2 --- /dev/null +++ b/proto_gen/opts.h @@ -0,0 +1,57 @@ +#pragma once +#include +#include +#include +#include +#include + +inline unsigned int stoui(const std::string& s) +{ + std::istringstream reader(s); + unsigned int val = 0; + reader >> val; + return val; +} + +class TOpts { +public: + void AddOpt(const std::string& name, std::string* storeVal) { + opts[name] = storeVal; + } + + void Parse(int argc, char** argv) { + if (argc != opts.size() + 1) + throw std::runtime_error("Not enought args"); + + for (size_t i = 1; i < argc; i++) { + ProcessOneArg(argv[i]); + } + } + +private: + std::map opts; + + void ProcessOneArg(std::string arg) { + if (arg.size() < 5) { + throw std::runtime_error("arg should be --="); + } + + if (arg[0] != '-' || arg[1] != '-') { + throw std::runtime_error("arg should be --="); + } + + auto pos = arg.find('=', 2); + + if (pos == std::string::npos || pos + 1 == arg.size()) { + throw std::runtime_error("arg should be --="); + } + + std::string argName = arg.substr(2, pos - 2); + + if (opts.count(argName) == 0) { + throw std::runtime_error("No such argument registered"); + } + + *opts[argName] = arg.substr(pos+1, arg.size() - pos); + } +}; \ No newline at end of file diff --git a/protobuf b/protobuf new file mode 160000 index 0000000..7043b88 --- /dev/null +++ b/protobuf @@ -0,0 +1 @@ +Subproject commit 7043b882a337fe51dc22c2dc92768f16425de36b