From 7e7c66756502e768da8bf9ae2e0a1969b1d0c4e1 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Thu, 14 Oct 2021 01:11:27 +0300 Subject: [PATCH 1/3] added *.proto file --- lesson_7/exercise_2.proto | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 lesson_7/exercise_2.proto diff --git a/lesson_7/exercise_2.proto b/lesson_7/exercise_2.proto new file mode 100644 index 0000000..b922236 --- /dev/null +++ b/lesson_7/exercise_2.proto @@ -0,0 +1,7 @@ +syntax = "proto3"; + +message SearchRequest { + string query = 1; + int32 page_number = 2; + int32 result_per_page = 3; +} \ No newline at end of file -- 2.40.1 From 567b8b15d0dd67068f94c9c346a54e0da7b26017 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Thu, 14 Oct 2021 18:50:43 +0300 Subject: [PATCH 2/3] exercise_1_2 --- lesson_7/exercise_2.proto | 20 +- lesson_7/main.cpp | 51 ++ lesson_7/src-gen/exercise_2.pb.cc | 950 +++++++++++++++++++++++++++ lesson_7/src-gen/exercise_2.pb.h | 1009 +++++++++++++++++++++++++++++ lesson_7/student.bin | 4 + 5 files changed, 2030 insertions(+), 4 deletions(-) create mode 100644 lesson_7/main.cpp create mode 100644 lesson_7/src-gen/exercise_2.pb.cc create mode 100644 lesson_7/src-gen/exercise_2.pb.h create mode 100644 lesson_7/student.bin diff --git a/lesson_7/exercise_2.proto b/lesson_7/exercise_2.proto index b922236..238329b 100644 --- a/lesson_7/exercise_2.proto +++ b/lesson_7/exercise_2.proto @@ -1,7 +1,19 @@ syntax = "proto3"; -message SearchRequest { - string query = 1; - int32 page_number = 2; - int32 result_per_page = 3; +package exercise_2; + +message FullName { + string name = 1; + string surname = 2; + optional string patronymic = 3; +} + +message Student { + FullName name = 1; + repeated uint32 grades = 2; + uint32 avg_score = 3; +} + +message StudentsGroup { + repeated Student students = 1; } \ No newline at end of file diff --git a/lesson_7/main.cpp b/lesson_7/main.cpp new file mode 100644 index 0000000..976839a --- /dev/null +++ b/lesson_7/main.cpp @@ -0,0 +1,51 @@ +/* + * main.cpp + * + * Created on: 14 окт. 2021 г. + * Author: alexander + */ + +#include +#include +#include +#include "src-gen/exercise_2.pb.h" + +int main() +{ +// exercise_2::FullName fn; +// fn.set_name("Alexander"); +// fn.set_surname("Zhirov"); +// fn.set_patronymic("Alexandrovich"); +// +// exercise_2::Student s; +// s.set_allocated_name(&fn); +// s.add_grades(5); +// s.add_grades(2); +// s.add_grades(4); +// s.add_grades(3); +// s.add_grades(4); +// s.add_grades(3); +// s.add_grades(4); +// s.add_grades(3); +// s.set_avg_score(std::accumulate(s.grades().begin(), s.grades().end(), 0) / s.grades().size()); +// +// exercise_2::StudentsGroup sg; +// *sg.add_students() = s; +// +// std::ofstream out("student.bin", std::ios_base::binary); +// sg.SerializeToOstream(&out); + + exercise_2::StudentsGroup sg; + std::ifstream in("student.bin", std::ios_base::binary); + if (sg.ParseFromIstream(&in)) + { + std::cout << sg.students(0).name().surname() << std::endl; + std::cout << sg.students(0).avg_score() << std::endl; + } + else + { + std::cout << "Error!" << std::endl; + } + + return 0; +} diff --git a/lesson_7/src-gen/exercise_2.pb.cc b/lesson_7/src-gen/exercise_2.pb.cc new file mode 100644 index 0000000..fac9e60 --- /dev/null +++ b/lesson_7/src-gen/exercise_2.pb.cc @@ -0,0 +1,950 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: exercise_2.proto + +#include "exercise_2.pb.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include +extern PROTOBUF_INTERNAL_EXPORT_exercise_5f2_2eproto ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_FullName_exercise_5f2_2eproto; +extern PROTOBUF_INTERNAL_EXPORT_exercise_5f2_2eproto ::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<1> scc_info_Student_exercise_5f2_2eproto; +namespace exercise_2 { +class FullNameDefaultTypeInternal { + public: + ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; +} _FullName_default_instance_; +class StudentDefaultTypeInternal { + public: + ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; +} _Student_default_instance_; +class StudentsGroupDefaultTypeInternal { + public: + ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; +} _StudentsGroup_default_instance_; +} // namespace exercise_2 +static void InitDefaultsscc_info_FullName_exercise_5f2_2eproto() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + { + void* ptr = &::exercise_2::_FullName_default_instance_; + new (ptr) ::exercise_2::FullName(); + ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); + } + ::exercise_2::FullName::InitAsDefaultInstance(); +} + +::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_FullName_exercise_5f2_2eproto = + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, InitDefaultsscc_info_FullName_exercise_5f2_2eproto}, {}}; + +static void InitDefaultsscc_info_Student_exercise_5f2_2eproto() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + { + void* ptr = &::exercise_2::_Student_default_instance_; + new (ptr) ::exercise_2::Student(); + ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); + } + ::exercise_2::Student::InitAsDefaultInstance(); +} + +::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<1> scc_info_Student_exercise_5f2_2eproto = + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 1, 0, InitDefaultsscc_info_Student_exercise_5f2_2eproto}, { + &scc_info_FullName_exercise_5f2_2eproto.base,}}; + +static void InitDefaultsscc_info_StudentsGroup_exercise_5f2_2eproto() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + { + void* ptr = &::exercise_2::_StudentsGroup_default_instance_; + new (ptr) ::exercise_2::StudentsGroup(); + ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); + } + ::exercise_2::StudentsGroup::InitAsDefaultInstance(); +} + +::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<1> scc_info_StudentsGroup_exercise_5f2_2eproto = + {{ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 1, 0, InitDefaultsscc_info_StudentsGroup_exercise_5f2_2eproto}, { + &scc_info_Student_exercise_5f2_2eproto.base,}}; + +static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_exercise_5f2_2eproto[3]; +static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const** file_level_enum_descriptors_exercise_5f2_2eproto = nullptr; +static constexpr ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor const** file_level_service_descriptors_exercise_5f2_2eproto = nullptr; + +const ::PROTOBUF_NAMESPACE_ID::uint32 TableStruct_exercise_5f2_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + PROTOBUF_FIELD_OFFSET(::exercise_2::FullName, _has_bits_), + PROTOBUF_FIELD_OFFSET(::exercise_2::FullName, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + PROTOBUF_FIELD_OFFSET(::exercise_2::FullName, name_), + PROTOBUF_FIELD_OFFSET(::exercise_2::FullName, surname_), + PROTOBUF_FIELD_OFFSET(::exercise_2::FullName, patronymic_), + ~0u, + ~0u, + 0, + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::exercise_2::Student, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + PROTOBUF_FIELD_OFFSET(::exercise_2::Student, name_), + PROTOBUF_FIELD_OFFSET(::exercise_2::Student, grades_), + PROTOBUF_FIELD_OFFSET(::exercise_2::Student, avg_score_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::exercise_2::StudentsGroup, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + PROTOBUF_FIELD_OFFSET(::exercise_2::StudentsGroup, students_), +}; +static const ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + { 0, 8, sizeof(::exercise_2::FullName)}, + { 11, -1, sizeof(::exercise_2::Student)}, + { 19, -1, sizeof(::exercise_2::StudentsGroup)}, +}; + +static ::PROTOBUF_NAMESPACE_ID::Message const * const file_default_instances[] = { + reinterpret_cast(&::exercise_2::_FullName_default_instance_), + reinterpret_cast(&::exercise_2::_Student_default_instance_), + reinterpret_cast(&::exercise_2::_StudentsGroup_default_instance_), +}; + +const char descriptor_table_protodef_exercise_5f2_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = + "\n\020exercise_2.proto\022\nexercise_2\"Q\n\010FullNa" + "me\022\014\n\004name\030\001 \001(\t\022\017\n\007surname\030\002 \001(\t\022\027\n\npat" + "ronymic\030\003 \001(\tH\000\210\001\001B\r\n\013_patronymic\"P\n\007Stu" + "dent\022\"\n\004name\030\001 \001(\0132\024.exercise_2.FullName" + "\022\016\n\006grades\030\002 \003(\r\022\021\n\tavg_score\030\003 \001(\r\"6\n\rS" + "tudentsGroup\022%\n\010students\030\001 \003(\0132\023.exercis" + "e_2.Studentb\006proto3" + ; +static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable*const descriptor_table_exercise_5f2_2eproto_deps[1] = { +}; +static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase*const descriptor_table_exercise_5f2_2eproto_sccs[3] = { + &scc_info_FullName_exercise_5f2_2eproto.base, + &scc_info_Student_exercise_5f2_2eproto.base, + &scc_info_StudentsGroup_exercise_5f2_2eproto.base, +}; +static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_exercise_5f2_2eproto_once; +const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_exercise_5f2_2eproto = { + false, false, descriptor_table_protodef_exercise_5f2_2eproto, "exercise_2.proto", 259, + &descriptor_table_exercise_5f2_2eproto_once, descriptor_table_exercise_5f2_2eproto_sccs, descriptor_table_exercise_5f2_2eproto_deps, 3, 0, + schemas, file_default_instances, TableStruct_exercise_5f2_2eproto::offsets, + file_level_metadata_exercise_5f2_2eproto, 3, file_level_enum_descriptors_exercise_5f2_2eproto, file_level_service_descriptors_exercise_5f2_2eproto, +}; + +// Force running AddDescriptors() at dynamic initialization time. +static bool dynamic_init_dummy_exercise_5f2_2eproto = (static_cast(::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_exercise_5f2_2eproto)), true); +namespace exercise_2 { + +// =================================================================== + +void FullName::InitAsDefaultInstance() { +} +class FullName::_Internal { + public: + using HasBits = decltype(std::declval()._has_bits_); + static void set_has_patronymic(HasBits* has_bits) { + (*has_bits)[0] |= 1u; + } +}; + +FullName::FullName(::PROTOBUF_NAMESPACE_ID::Arena* arena) + : ::PROTOBUF_NAMESPACE_ID::Message(arena) { + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:exercise_2.FullName) +} +FullName::FullName(const FullName& from) + : ::PROTOBUF_NAMESPACE_ID::Message(), + _has_bits_(from._has_bits_) { + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + if (!from._internal_name().empty()) { + name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_name(), + GetArena()); + } + surname_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + if (!from._internal_surname().empty()) { + surname_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_surname(), + GetArena()); + } + patronymic_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + if (from._internal_has_patronymic()) { + patronymic_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_patronymic(), + GetArena()); + } + // @@protoc_insertion_point(copy_constructor:exercise_2.FullName) +} + +void FullName::SharedCtor() { + ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_FullName_exercise_5f2_2eproto.base); + name_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + surname_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + patronymic_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); +} + +FullName::~FullName() { + // @@protoc_insertion_point(destructor:exercise_2.FullName) + SharedDtor(); + _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +void FullName::SharedDtor() { + GOOGLE_DCHECK(GetArena() == nullptr); + name_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + surname_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + patronymic_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); +} + +void FullName::ArenaDtor(void* object) { + FullName* _this = reinterpret_cast< FullName* >(object); + (void)_this; +} +void FullName::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { +} +void FullName::SetCachedSize(int size) const { + _cached_size_.Set(size); +} +const FullName& FullName::default_instance() { + ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_FullName_exercise_5f2_2eproto.base); + return *internal_default_instance(); +} + + +void FullName::Clear() { +// @@protoc_insertion_point(message_clear_start:exercise_2.FullName) + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); + surname_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 0x00000001u) { + patronymic_.ClearNonDefaultToEmpty(); + } + _has_bits_.Clear(); + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* FullName::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + _Internal::HasBits has_bits{}; + ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; + while (!ctx->Done(&ptr)) { + ::PROTOBUF_NAMESPACE_ID::uint32 tag; + ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); + CHK_(ptr); + switch (tag >> 3) { + // string name = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { + auto str = _internal_mutable_name(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "exercise_2.FullName.name")); + CHK_(ptr); + } else goto handle_unusual; + continue; + // string surname = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { + auto str = _internal_mutable_surname(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "exercise_2.FullName.surname")); + CHK_(ptr); + } else goto handle_unusual; + continue; + // string patronymic = 3; + case 3: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 26)) { + auto str = _internal_mutable_patronymic(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "exercise_2.FullName.patronymic")); + CHK_(ptr); + } else goto handle_unusual; + continue; + default: { + handle_unusual: + if ((tag & 7) == 4 || tag == 0) { + ctx->SetLastTag(tag); + goto success; + } + ptr = UnknownFieldParse(tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + continue; + } + } // switch + } // while +success: + _has_bits_.Or(has_bits); + return ptr; +failure: + ptr = nullptr; + goto success; +#undef CHK_ +} + +::PROTOBUF_NAMESPACE_ID::uint8* FullName::_InternalSerialize( + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:exercise_2.FullName) + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // string name = 1; + if (this->name().size() > 0) { + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + this->_internal_name().data(), static_cast(this->_internal_name().length()), + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, + "exercise_2.FullName.name"); + target = stream->WriteStringMaybeAliased( + 1, this->_internal_name(), target); + } + + // string surname = 2; + if (this->surname().size() > 0) { + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + this->_internal_surname().data(), static_cast(this->_internal_surname().length()), + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, + "exercise_2.FullName.surname"); + target = stream->WriteStringMaybeAliased( + 2, this->_internal_surname(), target); + } + + // string patronymic = 3; + if (_internal_has_patronymic()) { + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + this->_internal_patronymic().data(), static_cast(this->_internal_patronymic().length()), + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, + "exercise_2.FullName.patronymic"); + target = stream->WriteStringMaybeAliased( + 3, this->_internal_patronymic(), target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::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:exercise_2.FullName) + return target; +} + +size_t FullName::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:exercise_2.FullName) + size_t total_size = 0; + + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // string name = 1; + if (this->name().size() > 0) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_name()); + } + + // string surname = 2; + if (this->surname().size() > 0) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_surname()); + } + + // string patronymic = 3; + cached_has_bits = _has_bits_[0]; + if (cached_has_bits & 0x00000001u) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_patronymic()); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } + int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); + SetCachedSize(cached_size); + return total_size; +} + +void FullName::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:exercise_2.FullName) + GOOGLE_DCHECK_NE(&from, this); + const FullName* source = + ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( + &from); + if (source == nullptr) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:exercise_2.FullName) + ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:exercise_2.FullName) + MergeFrom(*source); + } +} + +void FullName::MergeFrom(const FullName& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:exercise_2.FullName) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + if (from.name().size() > 0) { + _internal_set_name(from._internal_name()); + } + if (from.surname().size() > 0) { + _internal_set_surname(from._internal_surname()); + } + if (from._internal_has_patronymic()) { + _internal_set_patronymic(from._internal_patronymic()); + } +} + +void FullName::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:exercise_2.FullName) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void FullName::CopyFrom(const FullName& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:exercise_2.FullName) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool FullName::IsInitialized() const { + return true; +} + +void FullName::InternalSwap(FullName* other) { + using std::swap; + _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); + swap(_has_bits_[0], other->_has_bits_[0]); + name_.Swap(&other->name_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); + surname_.Swap(&other->surname_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); + patronymic_.Swap(&other->patronymic_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} + +::PROTOBUF_NAMESPACE_ID::Metadata FullName::GetMetadata() const { + return GetMetadataStatic(); +} + + +// =================================================================== + +void Student::InitAsDefaultInstance() { + ::exercise_2::_Student_default_instance_._instance.get_mutable()->name_ = const_cast< ::exercise_2::FullName*>( + ::exercise_2::FullName::internal_default_instance()); +} +class Student::_Internal { + public: + static const ::exercise_2::FullName& name(const Student* msg); +}; + +const ::exercise_2::FullName& +Student::_Internal::name(const Student* msg) { + return *msg->name_; +} +Student::Student(::PROTOBUF_NAMESPACE_ID::Arena* arena) + : ::PROTOBUF_NAMESPACE_ID::Message(arena), + grades_(arena) { + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:exercise_2.Student) +} +Student::Student(const Student& from) + : ::PROTOBUF_NAMESPACE_ID::Message(), + grades_(from.grades_) { + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + if (from._internal_has_name()) { + name_ = new ::exercise_2::FullName(*from.name_); + } else { + name_ = nullptr; + } + avg_score_ = from.avg_score_; + // @@protoc_insertion_point(copy_constructor:exercise_2.Student) +} + +void Student::SharedCtor() { + ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_Student_exercise_5f2_2eproto.base); + ::memset(&name_, 0, static_cast( + reinterpret_cast(&avg_score_) - + reinterpret_cast(&name_)) + sizeof(avg_score_)); +} + +Student::~Student() { + // @@protoc_insertion_point(destructor:exercise_2.Student) + SharedDtor(); + _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +void Student::SharedDtor() { + GOOGLE_DCHECK(GetArena() == nullptr); + if (this != internal_default_instance()) delete name_; +} + +void Student::ArenaDtor(void* object) { + Student* _this = reinterpret_cast< Student* >(object); + (void)_this; +} +void Student::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { +} +void Student::SetCachedSize(int size) const { + _cached_size_.Set(size); +} +const Student& Student::default_instance() { + ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_Student_exercise_5f2_2eproto.base); + return *internal_default_instance(); +} + + +void Student::Clear() { +// @@protoc_insertion_point(message_clear_start:exercise_2.Student) + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + grades_.Clear(); + if (GetArena() == nullptr && name_ != nullptr) { + delete name_; + } + name_ = nullptr; + avg_score_ = 0u; + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* Student::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; + while (!ctx->Done(&ptr)) { + ::PROTOBUF_NAMESPACE_ID::uint32 tag; + ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); + CHK_(ptr); + switch (tag >> 3) { + // .exercise_2.FullName name = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { + ptr = ctx->ParseMessage(_internal_mutable_name(), ptr); + CHK_(ptr); + } else goto handle_unusual; + continue; + // repeated uint32 grades = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { + ptr = ::PROTOBUF_NAMESPACE_ID::internal::PackedUInt32Parser(_internal_mutable_grades(), ptr, ctx); + CHK_(ptr); + } else if (static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 16) { + _internal_add_grades(::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr)); + CHK_(ptr); + } else goto handle_unusual; + continue; + // uint32 avg_score = 3; + case 3: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 24)) { + avg_score_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + CHK_(ptr); + } else goto handle_unusual; + continue; + default: { + handle_unusual: + if ((tag & 7) == 4 || tag == 0) { + ctx->SetLastTag(tag); + goto success; + } + ptr = UnknownFieldParse(tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + continue; + } + } // switch + } // while +success: + return ptr; +failure: + ptr = nullptr; + goto success; +#undef CHK_ +} + +::PROTOBUF_NAMESPACE_ID::uint8* Student::_InternalSerialize( + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:exercise_2.Student) + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // .exercise_2.FullName name = 1; + if (this->has_name()) { + target = stream->EnsureSpace(target); + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: + InternalWriteMessage( + 1, _Internal::name(this), target, stream); + } + + // repeated uint32 grades = 2; + { + int byte_size = _grades_cached_byte_size_.load(std::memory_order_relaxed); + if (byte_size > 0) { + target = stream->WriteUInt32Packed( + 2, _internal_grades(), byte_size, target); + } + } + + // uint32 avg_score = 3; + if (this->avg_score() != 0) { + target = stream->EnsureSpace(target); + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt32ToArray(3, this->_internal_avg_score(), target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::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:exercise_2.Student) + return target; +} + +size_t Student::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:exercise_2.Student) + size_t total_size = 0; + + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // repeated uint32 grades = 2; + { + size_t data_size = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: + UInt32Size(this->grades_); + if (data_size > 0) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::Int32Size( + static_cast<::PROTOBUF_NAMESPACE_ID::int32>(data_size)); + } + int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(data_size); + _grades_cached_byte_size_.store(cached_size, + std::memory_order_relaxed); + total_size += data_size; + } + + // .exercise_2.FullName name = 1; + if (this->has_name()) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize( + *name_); + } + + // uint32 avg_score = 3; + if (this->avg_score() != 0) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt32Size( + this->_internal_avg_score()); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } + int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); + SetCachedSize(cached_size); + return total_size; +} + +void Student::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:exercise_2.Student) + GOOGLE_DCHECK_NE(&from, this); + const Student* source = + ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( + &from); + if (source == nullptr) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:exercise_2.Student) + ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:exercise_2.Student) + MergeFrom(*source); + } +} + +void Student::MergeFrom(const Student& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:exercise_2.Student) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + grades_.MergeFrom(from.grades_); + if (from.has_name()) { + _internal_mutable_name()->::exercise_2::FullName::MergeFrom(from._internal_name()); + } + if (from.avg_score() != 0) { + _internal_set_avg_score(from._internal_avg_score()); + } +} + +void Student::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:exercise_2.Student) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void Student::CopyFrom(const Student& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:exercise_2.Student) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool Student::IsInitialized() const { + return true; +} + +void Student::InternalSwap(Student* other) { + using std::swap; + _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); + grades_.InternalSwap(&other->grades_); + ::PROTOBUF_NAMESPACE_ID::internal::memswap< + PROTOBUF_FIELD_OFFSET(Student, avg_score_) + + sizeof(Student::avg_score_) + - PROTOBUF_FIELD_OFFSET(Student, name_)>( + reinterpret_cast(&name_), + reinterpret_cast(&other->name_)); +} + +::PROTOBUF_NAMESPACE_ID::Metadata Student::GetMetadata() const { + return GetMetadataStatic(); +} + + +// =================================================================== + +void StudentsGroup::InitAsDefaultInstance() { +} +class StudentsGroup::_Internal { + public: +}; + +StudentsGroup::StudentsGroup(::PROTOBUF_NAMESPACE_ID::Arena* arena) + : ::PROTOBUF_NAMESPACE_ID::Message(arena), + students_(arena) { + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:exercise_2.StudentsGroup) +} +StudentsGroup::StudentsGroup(const StudentsGroup& from) + : ::PROTOBUF_NAMESPACE_ID::Message(), + students_(from.students_) { + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + // @@protoc_insertion_point(copy_constructor:exercise_2.StudentsGroup) +} + +void StudentsGroup::SharedCtor() { + ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_StudentsGroup_exercise_5f2_2eproto.base); +} + +StudentsGroup::~StudentsGroup() { + // @@protoc_insertion_point(destructor:exercise_2.StudentsGroup) + SharedDtor(); + _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +void StudentsGroup::SharedDtor() { + GOOGLE_DCHECK(GetArena() == nullptr); +} + +void StudentsGroup::ArenaDtor(void* object) { + StudentsGroup* _this = reinterpret_cast< StudentsGroup* >(object); + (void)_this; +} +void StudentsGroup::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena*) { +} +void StudentsGroup::SetCachedSize(int size) const { + _cached_size_.Set(size); +} +const StudentsGroup& StudentsGroup::default_instance() { + ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_StudentsGroup_exercise_5f2_2eproto.base); + return *internal_default_instance(); +} + + +void StudentsGroup::Clear() { +// @@protoc_insertion_point(message_clear_start:exercise_2.StudentsGroup) + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + students_.Clear(); + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char* StudentsGroup::_InternalParse(const char* ptr, ::PROTOBUF_NAMESPACE_ID::internal::ParseContext* ctx) { +#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) goto failure + ::PROTOBUF_NAMESPACE_ID::Arena* arena = GetArena(); (void)arena; + while (!ctx->Done(&ptr)) { + ::PROTOBUF_NAMESPACE_ID::uint32 tag; + ptr = ::PROTOBUF_NAMESPACE_ID::internal::ReadTag(ptr, &tag); + CHK_(ptr); + switch (tag >> 3) { + // repeated .exercise_2.Student students = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 10)) { + ptr -= 1; + do { + ptr += 1; + ptr = ctx->ParseMessage(_internal_add_students(), ptr); + CHK_(ptr); + if (!ctx->DataAvailable(ptr)) break; + } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<10>(ptr)); + } else goto handle_unusual; + continue; + default: { + handle_unusual: + if ((tag & 7) == 4 || tag == 0) { + ctx->SetLastTag(tag); + goto success; + } + ptr = UnknownFieldParse(tag, + _internal_metadata_.mutable_unknown_fields<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(), + ptr, ctx); + CHK_(ptr != nullptr); + continue; + } + } // switch + } // while +success: + return ptr; +failure: + ptr = nullptr; + goto success; +#undef CHK_ +} + +::PROTOBUF_NAMESPACE_ID::uint8* StudentsGroup::_InternalSerialize( + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:exercise_2.StudentsGroup) + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + // repeated .exercise_2.Student students = 1; + for (unsigned int i = 0, + n = static_cast(this->_internal_students_size()); i < n; i++) { + target = stream->EnsureSpace(target); + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: + InternalWriteMessage(1, this->_internal_students(i), target, stream); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = ::PROTOBUF_NAMESPACE_ID::internal::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:exercise_2.StudentsGroup) + return target; +} + +size_t StudentsGroup::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:exercise_2.StudentsGroup) + size_t total_size = 0; + + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // repeated .exercise_2.Student students = 1; + total_size += 1UL * this->_internal_students_size(); + for (const auto& msg : this->students_) { + total_size += + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(msg); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + return ::PROTOBUF_NAMESPACE_ID::internal::ComputeUnknownFieldsSize( + _internal_metadata_, total_size, &_cached_size_); + } + int cached_size = ::PROTOBUF_NAMESPACE_ID::internal::ToCachedSize(total_size); + SetCachedSize(cached_size); + return total_size; +} + +void StudentsGroup::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { +// @@protoc_insertion_point(generalized_merge_from_start:exercise_2.StudentsGroup) + GOOGLE_DCHECK_NE(&from, this); + const StudentsGroup* source = + ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated( + &from); + if (source == nullptr) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:exercise_2.StudentsGroup) + ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:exercise_2.StudentsGroup) + MergeFrom(*source); + } +} + +void StudentsGroup::MergeFrom(const StudentsGroup& from) { +// @@protoc_insertion_point(class_specific_merge_from_start:exercise_2.StudentsGroup) + GOOGLE_DCHECK_NE(&from, this); + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + (void) cached_has_bits; + + students_.MergeFrom(from.students_); +} + +void StudentsGroup::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) { +// @@protoc_insertion_point(generalized_copy_from_start:exercise_2.StudentsGroup) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void StudentsGroup::CopyFrom(const StudentsGroup& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:exercise_2.StudentsGroup) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool StudentsGroup::IsInitialized() const { + return true; +} + +void StudentsGroup::InternalSwap(StudentsGroup* other) { + using std::swap; + _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); + students_.InternalSwap(&other->students_); +} + +::PROTOBUF_NAMESPACE_ID::Metadata StudentsGroup::GetMetadata() const { + return GetMetadataStatic(); +} + + +// @@protoc_insertion_point(namespace_scope) +} // namespace exercise_2 +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_NOINLINE ::exercise_2::FullName* Arena::CreateMaybeMessage< ::exercise_2::FullName >(Arena* arena) { + return Arena::CreateMessageInternal< ::exercise_2::FullName >(arena); +} +template<> PROTOBUF_NOINLINE ::exercise_2::Student* Arena::CreateMaybeMessage< ::exercise_2::Student >(Arena* arena) { + return Arena::CreateMessageInternal< ::exercise_2::Student >(arena); +} +template<> PROTOBUF_NOINLINE ::exercise_2::StudentsGroup* Arena::CreateMaybeMessage< ::exercise_2::StudentsGroup >(Arena* arena) { + return Arena::CreateMessageInternal< ::exercise_2::StudentsGroup >(arena); +} +PROTOBUF_NAMESPACE_CLOSE + +// @@protoc_insertion_point(global_scope) +#include diff --git a/lesson_7/src-gen/exercise_2.pb.h b/lesson_7/src-gen/exercise_2.pb.h new file mode 100644 index 0000000..1be4ace --- /dev/null +++ b/lesson_7/src-gen/exercise_2.pb.h @@ -0,0 +1,1009 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: exercise_2.proto + +#ifndef GOOGLE_PROTOBUF_INCLUDED_exercise_5f2_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_exercise_5f2_2eproto + +#include +#include + +#include +#if PROTOBUF_VERSION < 3012000 +#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 +#if 3012003 < 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 + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include // IWYU pragma: export +#include +// @@protoc_insertion_point(includes) +#include +#define PROTOBUF_INTERNAL_EXPORT_exercise_5f2_2eproto +PROTOBUF_NAMESPACE_OPEN +namespace internal { +class AnyMetadata; +} // namespace internal +PROTOBUF_NAMESPACE_CLOSE + +// Internal implementation detail -- do not use these members. +struct TableStruct_exercise_5f2_2eproto { + static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[] + PROTOBUF_SECTION_VARIABLE(protodesc_cold); + static const ::PROTOBUF_NAMESPACE_ID::internal::AuxiliaryParseTableField aux[] + PROTOBUF_SECTION_VARIABLE(protodesc_cold); + static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[3] + PROTOBUF_SECTION_VARIABLE(protodesc_cold); + static const ::PROTOBUF_NAMESPACE_ID::internal::FieldMetadata field_metadata[]; + static const ::PROTOBUF_NAMESPACE_ID::internal::SerializationTable serialization_table[]; + static const ::PROTOBUF_NAMESPACE_ID::uint32 offsets[]; +}; +extern const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_exercise_5f2_2eproto; +namespace exercise_2 { +class FullName; +class FullNameDefaultTypeInternal; +extern FullNameDefaultTypeInternal _FullName_default_instance_; +class Student; +class StudentDefaultTypeInternal; +extern StudentDefaultTypeInternal _Student_default_instance_; +class StudentsGroup; +class StudentsGroupDefaultTypeInternal; +extern StudentsGroupDefaultTypeInternal _StudentsGroup_default_instance_; +} // namespace exercise_2 +PROTOBUF_NAMESPACE_OPEN +template<> ::exercise_2::FullName* Arena::CreateMaybeMessage<::exercise_2::FullName>(Arena*); +template<> ::exercise_2::Student* Arena::CreateMaybeMessage<::exercise_2::Student>(Arena*); +template<> ::exercise_2::StudentsGroup* Arena::CreateMaybeMessage<::exercise_2::StudentsGroup>(Arena*); +PROTOBUF_NAMESPACE_CLOSE +namespace exercise_2 { + +// =================================================================== + +class FullName PROTOBUF_FINAL : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:exercise_2.FullName) */ { + public: + inline FullName() : FullName(nullptr) {}; + virtual ~FullName(); + + FullName(const FullName& from); + FullName(FullName&& from) noexcept + : FullName() { + *this = ::std::move(from); + } + + inline FullName& operator=(const FullName& from) { + CopyFrom(from); + return *this; + } + inline FullName& operator=(FullName&& from) noexcept { + if (GetArena() == from.GetArena()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return GetMetadataStatic().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return GetMetadataStatic().reflection; + } + static const FullName& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const FullName* internal_default_instance() { + return reinterpret_cast( + &_FullName_default_instance_); + } + static constexpr int kIndexInFileMessages = + 0; + + friend void swap(FullName& a, FullName& b) { + a.Swap(&b); + } + inline void Swap(FullName* other) { + if (other == this) return; + if (GetArena() == other->GetArena()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(FullName* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + inline FullName* New() const final { + return CreateMaybeMessage(nullptr); + } + + FullName* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { + return CreateMaybeMessage(arena); + } + void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; + void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; + void CopyFrom(const FullName& from); + void MergeFrom(const FullName& from); + 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; + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _cached_size_.Get(); } + + private: + inline void SharedCtor(); + inline void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(FullName* other); + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { + return "exercise_2.FullName"; + } + protected: + explicit FullName(::PROTOBUF_NAMESPACE_ID::Arena* arena); + private: + static void ArenaDtor(void* object); + inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); + public: + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + private: + static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { + ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_exercise_5f2_2eproto); + return ::descriptor_table_exercise_5f2_2eproto.file_level_metadata[kIndexInFileMessages]; + } + + public: + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kNameFieldNumber = 1, + kSurnameFieldNumber = 2, + kPatronymicFieldNumber = 3, + }; + // string name = 1; + void clear_name(); + const std::string& name() const; + void set_name(const std::string& value); + void set_name(std::string&& value); + void set_name(const char* value); + void set_name(const char* value, size_t size); + std::string* mutable_name(); + std::string* release_name(); + void set_allocated_name(std::string* name); + private: + const std::string& _internal_name() const; + void _internal_set_name(const std::string& value); + std::string* _internal_mutable_name(); + public: + + // string surname = 2; + void clear_surname(); + const std::string& surname() const; + void set_surname(const std::string& value); + void set_surname(std::string&& value); + void set_surname(const char* value); + void set_surname(const char* value, size_t size); + std::string* mutable_surname(); + std::string* release_surname(); + void set_allocated_surname(std::string* surname); + private: + const std::string& _internal_surname() const; + void _internal_set_surname(const std::string& value); + std::string* _internal_mutable_surname(); + public: + + // string patronymic = 3; + bool has_patronymic() const; + private: + bool _internal_has_patronymic() const; + public: + void clear_patronymic(); + const std::string& patronymic() const; + void set_patronymic(const std::string& value); + void set_patronymic(std::string&& value); + void set_patronymic(const char* value); + void set_patronymic(const char* value, size_t size); + std::string* mutable_patronymic(); + std::string* release_patronymic(); + void set_allocated_patronymic(std::string* patronymic); + private: + const std::string& _internal_patronymic() const; + void _internal_set_patronymic(const std::string& value); + std::string* _internal_mutable_patronymic(); + public: + + // @@protoc_insertion_point(class_scope:exercise_2.FullName) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + ::PROTOBUF_NAMESPACE_ID::internal::HasBits<1> _has_bits_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr surname_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr patronymic_; + friend struct ::TableStruct_exercise_5f2_2eproto; +}; +// ------------------------------------------------------------------- + +class Student PROTOBUF_FINAL : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:exercise_2.Student) */ { + public: + inline Student() : Student(nullptr) {}; + virtual ~Student(); + + Student(const Student& from); + Student(Student&& from) noexcept + : Student() { + *this = ::std::move(from); + } + + inline Student& operator=(const Student& from) { + CopyFrom(from); + return *this; + } + inline Student& operator=(Student&& from) noexcept { + if (GetArena() == from.GetArena()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return GetMetadataStatic().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return GetMetadataStatic().reflection; + } + static const Student& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const Student* internal_default_instance() { + return reinterpret_cast( + &_Student_default_instance_); + } + static constexpr int kIndexInFileMessages = + 1; + + friend void swap(Student& a, Student& b) { + a.Swap(&b); + } + inline void Swap(Student* other) { + if (other == this) return; + if (GetArena() == other->GetArena()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(Student* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + inline Student* New() const final { + return CreateMaybeMessage(nullptr); + } + + Student* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { + return CreateMaybeMessage(arena); + } + void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; + void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; + void CopyFrom(const Student& from); + void MergeFrom(const Student& from); + 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; + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _cached_size_.Get(); } + + private: + inline void SharedCtor(); + inline void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(Student* other); + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { + return "exercise_2.Student"; + } + protected: + explicit Student(::PROTOBUF_NAMESPACE_ID::Arena* arena); + private: + static void ArenaDtor(void* object); + inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); + public: + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + private: + static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { + ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_exercise_5f2_2eproto); + return ::descriptor_table_exercise_5f2_2eproto.file_level_metadata[kIndexInFileMessages]; + } + + public: + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kGradesFieldNumber = 2, + kNameFieldNumber = 1, + kAvgScoreFieldNumber = 3, + }; + // repeated uint32 grades = 2; + int grades_size() const; + private: + int _internal_grades_size() const; + public: + void clear_grades(); + private: + ::PROTOBUF_NAMESPACE_ID::uint32 _internal_grades(int index) const; + const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::uint32 >& + _internal_grades() const; + void _internal_add_grades(::PROTOBUF_NAMESPACE_ID::uint32 value); + ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::uint32 >* + _internal_mutable_grades(); + public: + ::PROTOBUF_NAMESPACE_ID::uint32 grades(int index) const; + void set_grades(int index, ::PROTOBUF_NAMESPACE_ID::uint32 value); + void add_grades(::PROTOBUF_NAMESPACE_ID::uint32 value); + const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::uint32 >& + grades() const; + ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::uint32 >* + mutable_grades(); + + // .exercise_2.FullName name = 1; + bool has_name() const; + private: + bool _internal_has_name() const; + public: + void clear_name(); + const ::exercise_2::FullName& name() const; + ::exercise_2::FullName* release_name(); + ::exercise_2::FullName* mutable_name(); + void set_allocated_name(::exercise_2::FullName* name); + private: + const ::exercise_2::FullName& _internal_name() const; + ::exercise_2::FullName* _internal_mutable_name(); + public: + void unsafe_arena_set_allocated_name( + ::exercise_2::FullName* name); + ::exercise_2::FullName* unsafe_arena_release_name(); + + // uint32 avg_score = 3; + void clear_avg_score(); + ::PROTOBUF_NAMESPACE_ID::uint32 avg_score() const; + void set_avg_score(::PROTOBUF_NAMESPACE_ID::uint32 value); + private: + ::PROTOBUF_NAMESPACE_ID::uint32 _internal_avg_score() const; + void _internal_set_avg_score(::PROTOBUF_NAMESPACE_ID::uint32 value); + public: + + // @@protoc_insertion_point(class_scope:exercise_2.Student) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::uint32 > grades_; + mutable std::atomic _grades_cached_byte_size_; + ::exercise_2::FullName* name_; + ::PROTOBUF_NAMESPACE_ID::uint32 avg_score_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + friend struct ::TableStruct_exercise_5f2_2eproto; +}; +// ------------------------------------------------------------------- + +class StudentsGroup PROTOBUF_FINAL : + public ::PROTOBUF_NAMESPACE_ID::Message /* @@protoc_insertion_point(class_definition:exercise_2.StudentsGroup) */ { + public: + inline StudentsGroup() : StudentsGroup(nullptr) {}; + virtual ~StudentsGroup(); + + StudentsGroup(const StudentsGroup& from); + StudentsGroup(StudentsGroup&& from) noexcept + : StudentsGroup() { + *this = ::std::move(from); + } + + inline StudentsGroup& operator=(const StudentsGroup& from) { + CopyFrom(from); + return *this; + } + inline StudentsGroup& operator=(StudentsGroup&& from) noexcept { + if (GetArena() == from.GetArena()) { + if (this != &from) InternalSwap(&from); + } else { + CopyFrom(from); + } + return *this; + } + + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* descriptor() { + return GetDescriptor(); + } + static const ::PROTOBUF_NAMESPACE_ID::Descriptor* GetDescriptor() { + return GetMetadataStatic().descriptor; + } + static const ::PROTOBUF_NAMESPACE_ID::Reflection* GetReflection() { + return GetMetadataStatic().reflection; + } + static const StudentsGroup& default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const StudentsGroup* internal_default_instance() { + return reinterpret_cast( + &_StudentsGroup_default_instance_); + } + static constexpr int kIndexInFileMessages = + 2; + + friend void swap(StudentsGroup& a, StudentsGroup& b) { + a.Swap(&b); + } + inline void Swap(StudentsGroup* other) { + if (other == this) return; + if (GetArena() == other->GetArena()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(StudentsGroup* other) { + if (other == this) return; + GOOGLE_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + inline StudentsGroup* New() const final { + return CreateMaybeMessage(nullptr); + } + + StudentsGroup* New(::PROTOBUF_NAMESPACE_ID::Arena* arena) const final { + return CreateMaybeMessage(arena); + } + void CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; + void MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message& from) final; + void CopyFrom(const StudentsGroup& from); + void MergeFrom(const StudentsGroup& from); + 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; + ::PROTOBUF_NAMESPACE_ID::uint8* _InternalSerialize( + ::PROTOBUF_NAMESPACE_ID::uint8* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const final; + int GetCachedSize() const final { return _cached_size_.Get(); } + + private: + inline void SharedCtor(); + inline void SharedDtor(); + void SetCachedSize(int size) const final; + void InternalSwap(StudentsGroup* other); + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { + return "exercise_2.StudentsGroup"; + } + protected: + explicit StudentsGroup(::PROTOBUF_NAMESPACE_ID::Arena* arena); + private: + static void ArenaDtor(void* object); + inline void RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena* arena); + public: + + ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadata() const final; + private: + static ::PROTOBUF_NAMESPACE_ID::Metadata GetMetadataStatic() { + ::PROTOBUF_NAMESPACE_ID::internal::AssignDescriptors(&::descriptor_table_exercise_5f2_2eproto); + return ::descriptor_table_exercise_5f2_2eproto.file_level_metadata[kIndexInFileMessages]; + } + + public: + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kStudentsFieldNumber = 1, + }; + // repeated .exercise_2.Student students = 1; + int students_size() const; + private: + int _internal_students_size() const; + public: + void clear_students(); + ::exercise_2::Student* mutable_students(int index); + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::exercise_2::Student >* + mutable_students(); + private: + const ::exercise_2::Student& _internal_students(int index) const; + ::exercise_2::Student* _internal_add_students(); + public: + const ::exercise_2::Student& students(int index) const; + ::exercise_2::Student* add_students(); + const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::exercise_2::Student >& + students() const; + + // @@protoc_insertion_point(class_scope:exercise_2.StudentsGroup) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::exercise_2::Student > students_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + friend struct ::TableStruct_exercise_5f2_2eproto; +}; +// =================================================================== + + +// =================================================================== + +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// FullName + +// string name = 1; +inline void FullName::clear_name() { + name_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline const std::string& FullName::name() const { + // @@protoc_insertion_point(field_get:exercise_2.FullName.name) + return _internal_name(); +} +inline void FullName::set_name(const std::string& value) { + _internal_set_name(value); + // @@protoc_insertion_point(field_set:exercise_2.FullName.name) +} +inline std::string* FullName::mutable_name() { + // @@protoc_insertion_point(field_mutable:exercise_2.FullName.name) + return _internal_mutable_name(); +} +inline const std::string& FullName::_internal_name() const { + return name_.Get(); +} +inline void FullName::_internal_set_name(const std::string& value) { + + name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); +} +inline void FullName::set_name(std::string&& value) { + + name_.Set( + &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); + // @@protoc_insertion_point(field_set_rvalue:exercise_2.FullName.name) +} +inline void FullName::set_name(const char* value) { + GOOGLE_DCHECK(value != nullptr); + + name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), + GetArena()); + // @@protoc_insertion_point(field_set_char:exercise_2.FullName.name) +} +inline void FullName::set_name(const char* value, + size_t size) { + + name_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), GetArena()); + // @@protoc_insertion_point(field_set_pointer:exercise_2.FullName.name) +} +inline std::string* FullName::_internal_mutable_name() { + + return name_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline std::string* FullName::release_name() { + // @@protoc_insertion_point(field_release:exercise_2.FullName.name) + return name_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline void FullName::set_allocated_name(std::string* name) { + if (name != nullptr) { + + } else { + + } + name_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), name, + GetArena()); + // @@protoc_insertion_point(field_set_allocated:exercise_2.FullName.name) +} + +// string surname = 2; +inline void FullName::clear_surname() { + surname_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline const std::string& FullName::surname() const { + // @@protoc_insertion_point(field_get:exercise_2.FullName.surname) + return _internal_surname(); +} +inline void FullName::set_surname(const std::string& value) { + _internal_set_surname(value); + // @@protoc_insertion_point(field_set:exercise_2.FullName.surname) +} +inline std::string* FullName::mutable_surname() { + // @@protoc_insertion_point(field_mutable:exercise_2.FullName.surname) + return _internal_mutable_surname(); +} +inline const std::string& FullName::_internal_surname() const { + return surname_.Get(); +} +inline void FullName::_internal_set_surname(const std::string& value) { + + surname_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); +} +inline void FullName::set_surname(std::string&& value) { + + surname_.Set( + &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); + // @@protoc_insertion_point(field_set_rvalue:exercise_2.FullName.surname) +} +inline void FullName::set_surname(const char* value) { + GOOGLE_DCHECK(value != nullptr); + + surname_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), + GetArena()); + // @@protoc_insertion_point(field_set_char:exercise_2.FullName.surname) +} +inline void FullName::set_surname(const char* value, + size_t size) { + + surname_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), GetArena()); + // @@protoc_insertion_point(field_set_pointer:exercise_2.FullName.surname) +} +inline std::string* FullName::_internal_mutable_surname() { + + return surname_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline std::string* FullName::release_surname() { + // @@protoc_insertion_point(field_release:exercise_2.FullName.surname) + return surname_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline void FullName::set_allocated_surname(std::string* surname) { + if (surname != nullptr) { + + } else { + + } + surname_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), surname, + GetArena()); + // @@protoc_insertion_point(field_set_allocated:exercise_2.FullName.surname) +} + +// string patronymic = 3; +inline bool FullName::_internal_has_patronymic() const { + bool value = (_has_bits_[0] & 0x00000001u) != 0; + return value; +} +inline bool FullName::has_patronymic() const { + return _internal_has_patronymic(); +} +inline void FullName::clear_patronymic() { + patronymic_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); + _has_bits_[0] &= ~0x00000001u; +} +inline const std::string& FullName::patronymic() const { + // @@protoc_insertion_point(field_get:exercise_2.FullName.patronymic) + return _internal_patronymic(); +} +inline void FullName::set_patronymic(const std::string& value) { + _internal_set_patronymic(value); + // @@protoc_insertion_point(field_set:exercise_2.FullName.patronymic) +} +inline std::string* FullName::mutable_patronymic() { + // @@protoc_insertion_point(field_mutable:exercise_2.FullName.patronymic) + return _internal_mutable_patronymic(); +} +inline const std::string& FullName::_internal_patronymic() const { + return patronymic_.Get(); +} +inline void FullName::_internal_set_patronymic(const std::string& value) { + _has_bits_[0] |= 0x00000001u; + patronymic_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); +} +inline void FullName::set_patronymic(std::string&& value) { + _has_bits_[0] |= 0x00000001u; + patronymic_.Set( + &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); + // @@protoc_insertion_point(field_set_rvalue:exercise_2.FullName.patronymic) +} +inline void FullName::set_patronymic(const char* value) { + GOOGLE_DCHECK(value != nullptr); + _has_bits_[0] |= 0x00000001u; + patronymic_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), + GetArena()); + // @@protoc_insertion_point(field_set_char:exercise_2.FullName.patronymic) +} +inline void FullName::set_patronymic(const char* value, + size_t size) { + _has_bits_[0] |= 0x00000001u; + patronymic_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string( + reinterpret_cast(value), size), GetArena()); + // @@protoc_insertion_point(field_set_pointer:exercise_2.FullName.patronymic) +} +inline std::string* FullName::_internal_mutable_patronymic() { + _has_bits_[0] |= 0x00000001u; + return patronymic_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline std::string* FullName::release_patronymic() { + // @@protoc_insertion_point(field_release:exercise_2.FullName.patronymic) + if (!_internal_has_patronymic()) { + return nullptr; + } + _has_bits_[0] &= ~0x00000001u; + return patronymic_.ReleaseNonDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline void FullName::set_allocated_patronymic(std::string* patronymic) { + if (patronymic != nullptr) { + _has_bits_[0] |= 0x00000001u; + } else { + _has_bits_[0] &= ~0x00000001u; + } + patronymic_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), patronymic, + GetArena()); + // @@protoc_insertion_point(field_set_allocated:exercise_2.FullName.patronymic) +} + +// ------------------------------------------------------------------- + +// Student + +// .exercise_2.FullName name = 1; +inline bool Student::_internal_has_name() const { + return this != internal_default_instance() && name_ != nullptr; +} +inline bool Student::has_name() const { + return _internal_has_name(); +} +inline void Student::clear_name() { + if (GetArena() == nullptr && name_ != nullptr) { + delete name_; + } + name_ = nullptr; +} +inline const ::exercise_2::FullName& Student::_internal_name() const { + const ::exercise_2::FullName* p = name_; + return p != nullptr ? *p : *reinterpret_cast( + &::exercise_2::_FullName_default_instance_); +} +inline const ::exercise_2::FullName& Student::name() const { + // @@protoc_insertion_point(field_get:exercise_2.Student.name) + return _internal_name(); +} +inline void Student::unsafe_arena_set_allocated_name( + ::exercise_2::FullName* name) { + if (GetArena() == nullptr) { + delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(name_); + } + name_ = name; + if (name) { + + } else { + + } + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:exercise_2.Student.name) +} +inline ::exercise_2::FullName* Student::release_name() { + + ::exercise_2::FullName* temp = name_; + name_ = nullptr; + if (GetArena() != nullptr) { + temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp); + } + return temp; +} +inline ::exercise_2::FullName* Student::unsafe_arena_release_name() { + // @@protoc_insertion_point(field_release:exercise_2.Student.name) + + ::exercise_2::FullName* temp = name_; + name_ = nullptr; + return temp; +} +inline ::exercise_2::FullName* Student::_internal_mutable_name() { + + if (name_ == nullptr) { + auto* p = CreateMaybeMessage<::exercise_2::FullName>(GetArena()); + name_ = p; + } + return name_; +} +inline ::exercise_2::FullName* Student::mutable_name() { + // @@protoc_insertion_point(field_mutable:exercise_2.Student.name) + return _internal_mutable_name(); +} +inline void Student::set_allocated_name(::exercise_2::FullName* name) { + ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArena(); + if (message_arena == nullptr) { + delete name_; + } + if (name) { + ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = + ::PROTOBUF_NAMESPACE_ID::Arena::GetArena(name); + if (message_arena != submessage_arena) { + name = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( + message_arena, name, submessage_arena); + } + + } else { + + } + name_ = name; + // @@protoc_insertion_point(field_set_allocated:exercise_2.Student.name) +} + +// repeated uint32 grades = 2; +inline int Student::_internal_grades_size() const { + return grades_.size(); +} +inline int Student::grades_size() const { + return _internal_grades_size(); +} +inline void Student::clear_grades() { + grades_.Clear(); +} +inline ::PROTOBUF_NAMESPACE_ID::uint32 Student::_internal_grades(int index) const { + return grades_.Get(index); +} +inline ::PROTOBUF_NAMESPACE_ID::uint32 Student::grades(int index) const { + // @@protoc_insertion_point(field_get:exercise_2.Student.grades) + return _internal_grades(index); +} +inline void Student::set_grades(int index, ::PROTOBUF_NAMESPACE_ID::uint32 value) { + grades_.Set(index, value); + // @@protoc_insertion_point(field_set:exercise_2.Student.grades) +} +inline void Student::_internal_add_grades(::PROTOBUF_NAMESPACE_ID::uint32 value) { + grades_.Add(value); +} +inline void Student::add_grades(::PROTOBUF_NAMESPACE_ID::uint32 value) { + _internal_add_grades(value); + // @@protoc_insertion_point(field_add:exercise_2.Student.grades) +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::uint32 >& +Student::_internal_grades() const { + return grades_; +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::uint32 >& +Student::grades() const { + // @@protoc_insertion_point(field_list:exercise_2.Student.grades) + return _internal_grades(); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::uint32 >* +Student::_internal_mutable_grades() { + return &grades_; +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedField< ::PROTOBUF_NAMESPACE_ID::uint32 >* +Student::mutable_grades() { + // @@protoc_insertion_point(field_mutable_list:exercise_2.Student.grades) + return _internal_mutable_grades(); +} + +// uint32 avg_score = 3; +inline void Student::clear_avg_score() { + avg_score_ = 0u; +} +inline ::PROTOBUF_NAMESPACE_ID::uint32 Student::_internal_avg_score() const { + return avg_score_; +} +inline ::PROTOBUF_NAMESPACE_ID::uint32 Student::avg_score() const { + // @@protoc_insertion_point(field_get:exercise_2.Student.avg_score) + return _internal_avg_score(); +} +inline void Student::_internal_set_avg_score(::PROTOBUF_NAMESPACE_ID::uint32 value) { + + avg_score_ = value; +} +inline void Student::set_avg_score(::PROTOBUF_NAMESPACE_ID::uint32 value) { + _internal_set_avg_score(value); + // @@protoc_insertion_point(field_set:exercise_2.Student.avg_score) +} + +// ------------------------------------------------------------------- + +// StudentsGroup + +// repeated .exercise_2.Student students = 1; +inline int StudentsGroup::_internal_students_size() const { + return students_.size(); +} +inline int StudentsGroup::students_size() const { + return _internal_students_size(); +} +inline void StudentsGroup::clear_students() { + students_.Clear(); +} +inline ::exercise_2::Student* StudentsGroup::mutable_students(int index) { + // @@protoc_insertion_point(field_mutable:exercise_2.StudentsGroup.students) + return students_.Mutable(index); +} +inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::exercise_2::Student >* +StudentsGroup::mutable_students() { + // @@protoc_insertion_point(field_mutable_list:exercise_2.StudentsGroup.students) + return &students_; +} +inline const ::exercise_2::Student& StudentsGroup::_internal_students(int index) const { + return students_.Get(index); +} +inline const ::exercise_2::Student& StudentsGroup::students(int index) const { + // @@protoc_insertion_point(field_get:exercise_2.StudentsGroup.students) + return _internal_students(index); +} +inline ::exercise_2::Student* StudentsGroup::_internal_add_students() { + return students_.Add(); +} +inline ::exercise_2::Student* StudentsGroup::add_students() { + // @@protoc_insertion_point(field_add:exercise_2.StudentsGroup.students) + return _internal_add_students(); +} +inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::exercise_2::Student >& +StudentsGroup::students() const { + // @@protoc_insertion_point(field_list:exercise_2.StudentsGroup.students) + return students_; +} + +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace exercise_2 + +// @@protoc_insertion_point(global_scope) + +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_exercise_5f2_2eproto diff --git a/lesson_7/student.bin b/lesson_7/student.bin new file mode 100644 index 0000000..df909e0 --- /dev/null +++ b/lesson_7/student.bin @@ -0,0 +1,4 @@ + +0 +" + AlexanderZhirov Alexandrovich \ No newline at end of file -- 2.40.1 From 881a266d2e2a66370cddf91166e7077bd29316b9 Mon Sep 17 00:00:00 2001 From: Alexander Zhirov Date: Fri, 15 Oct 2021 03:42:52 +0300 Subject: [PATCH 3/3] lesson_7 --- lesson_7/data.bin | Bin 0 -> 56 bytes lesson_7/exercise_2.hpp | 53 +++++++++++++++++ lesson_7/exercise_3.cpp | 38 ++++++++++++ lesson_7/exercise_3.hpp | 127 ++++++++++++++++++++++++++++++++++++++++ lesson_7/main.cpp | 42 ++----------- 5 files changed, 222 insertions(+), 38 deletions(-) create mode 100644 lesson_7/data.bin create mode 100644 lesson_7/exercise_2.hpp create mode 100644 lesson_7/exercise_3.cpp create mode 100644 lesson_7/exercise_3.hpp diff --git a/lesson_7/data.bin b/lesson_7/data.bin new file mode 100644 index 0000000000000000000000000000000000000000..b04bbbe3f5ce5ffdfd5a922ba70bef3682692718 GIT binary patch literal 56 xcmZQ%fB-HfE>6ds)QZHsl++?2wy2EEqWm%`UZ@a|otc~=#KFqM!VH2E%m7n@3@-ox literal 0 HcmV?d00001 diff --git a/lesson_7/exercise_2.hpp b/lesson_7/exercise_2.hpp new file mode 100644 index 0000000..f79bfef --- /dev/null +++ b/lesson_7/exercise_2.hpp @@ -0,0 +1,53 @@ +/* + * exercise_2.hpp + * + * Created on: 15 окт. 2021 г. + * Author: alexander + */ + +#pragma once + +#include +#include +#include +#include "src-gen/exercise_2.pb.h" + +void exercise_1_2() +{ + exercise_2::FullName fn; + fn.set_name("Alexander"); + fn.set_surname("Zhirov"); + fn.set_patronymic("Alexandrovich"); + + exercise_2::Student s; + *s.mutable_name() = fn; + s.add_grades(5); + s.add_grades(2); + s.add_grades(4); + s.add_grades(3); + s.add_grades(4); + s.add_grades(3); + s.add_grades(4); + s.add_grades(3); + s.set_avg_score(std::accumulate(s.grades().begin(), s.grades().end(), 0) / s.grades().size()); + + exercise_2::StudentsGroup sg; + *sg.add_students() = s; + + std::ofstream out("student.bin", std::ios_base::binary); + sg.SerializeToOstream(&out); + out.close(); + + exercise_2::StudentsGroup new_sg; + std::ifstream in("student.bin", std::ios_base::binary); + if (new_sg.ParseFromIstream(&in)) + { + std::cout << new_sg.students(0).name().surname() << std::endl; + std::cout << new_sg.students(0).avg_score() << std::endl; + } + else + { + std::cout << "Error!" << std::endl; + } + in.close(); +} diff --git a/lesson_7/exercise_3.cpp b/lesson_7/exercise_3.cpp new file mode 100644 index 0000000..bd3f3ca --- /dev/null +++ b/lesson_7/exercise_3.cpp @@ -0,0 +1,38 @@ +/* + * exercise_3.cpp + * + * Created on: 15 окт. 2021 г. + * Author: alexander + */ + +#include "exercise_3.hpp" +#include + +void exercise_3() +{ + exercise_2::FullName fn; + fn.set_name("Alexander"); + fn.set_surname("Zhirov"); + fn.set_patronymic("Alexandrovich"); + + exercise_2::Student s; + *s.mutable_name() = fn; + s.add_grades(5); + s.add_grades(2); + s.add_grades(4); + s.add_grades(3); + s.add_grades(4); + s.add_grades(3); + s.add_grades(4); + s.add_grades(3); + s.set_avg_score(std::accumulate(s.grades().begin(), s.grades().end(), 0) / s.grades().size()); + + SG::StudentsGroup sg; + sg.add_student(s); + sg.Save(); + + SG::StudentsGroup new_sg; + new_sg.Open(); + std:: cout << new_sg.GetAllInfo(fn) << std::endl; +} + diff --git a/lesson_7/exercise_3.hpp b/lesson_7/exercise_3.hpp new file mode 100644 index 0000000..aa0a33a --- /dev/null +++ b/lesson_7/exercise_3.hpp @@ -0,0 +1,127 @@ +/* + * exercise_3.hpp + * + * Created on: 15 окт. 2021 г. + * Author: alexander + */ + +#pragma once + +#include +#include +#include +#include "src-gen/exercise_2.pb.h" + +namespace SG +{ + class IRepository + { + public: + virtual void Open() = 0; // бинарная десериализация в файл + virtual void Save() = 0; // бинарная сериализация в файл + virtual ~IRepository() {}; + }; + + class IMethods + { + public: + virtual double GetAverageScore(const exercise_2::FullName &name) = 0; + virtual std::string GetAllInfo(const exercise_2::FullName &name) = 0; + virtual std::string GetAllInfo() = 0; + virtual ~IMethods() {}; + }; + + class StudentsGroup: public IRepository, public IMethods + { + private: + std::vector m_students; + public: + void add_student(const exercise_2::Student &s) + { + m_students.push_back(s); + } + + double GetAverageScore(const exercise_2::FullName &name) + { + auto it = std::find_if(m_students.begin(), m_students.end(), [&](const exercise_2::Student &s) + { + return tie(s.name().name(), s.name().surname(), s.name().patronymic()) == + tie(name.name(), name.surname(), name.patronymic()); + }); + + if (it == m_students.end()) + { + return 0.0; + } + + return it->avg_score(); + } + + std::string GetAllInfo(const exercise_2::FullName &name) + { + auto it = std::find_if(m_students.begin(), m_students.end(), [&](const exercise_2::Student &s) + { + return tie(s.name().name(), s.name().surname(), s.name().patronymic()) == + tie(name.name(), name.surname(), name.patronymic()); + }); + + if (it == m_students.end()) + { + return {}; + } + + std::string temp = "Имя: " + it->name().name() + ' ' + it->name().surname() + ' ' + it->name().patronymic() + '\n'; + temp += "Оценки: "; + for (int i = 0; i < it->grades().size(); ++i) + { + temp += std::to_string(it->grades(i)) + "; "; + } + temp += '\n'; + temp += "Средний балл: " + std::to_string(it->avg_score()) + "\n\n"; + + return temp; + } + + std::string GetAllInfo() + { + std::string temp; + + std::for_each(m_students.begin(), m_students.end(), [&](const exercise_2::Student &s) + { + temp += GetAllInfo(s.name()); + }); + + return temp; + } + + void Save() + { + std::ofstream out("data.bin", std::ios_base::binary); + auto size = m_students.size(); + out.write(reinterpret_cast(&size), sizeof(size)); + std::for_each(m_students.begin(), m_students.end(), [&](const exercise_2::Student &s) + { + s.SerializeToOstream(&out); + }); + out.close(); + } + + void Open() + { + std::ifstream in("data.bin", std::ios_base::binary); + size_t size = 0; + in.read(reinterpret_cast(&size), sizeof(size)); + while (size--) + { + exercise_2::Student s; + s.ParseFromIstream(&in); + m_students.push_back(std::move(s)); + } + in.close(); + } + + virtual ~StudentsGroup() {}; + }; +} + +void exercise_3(); diff --git a/lesson_7/main.cpp b/lesson_7/main.cpp index 976839a..58b14e7 100644 --- a/lesson_7/main.cpp +++ b/lesson_7/main.cpp @@ -5,47 +5,13 @@ * Author: alexander */ -#include -#include -#include -#include "src-gen/exercise_2.pb.h" +#include "exercise_2.hpp" +#include "exercise_3.hpp" int main() { -// exercise_2::FullName fn; -// fn.set_name("Alexander"); -// fn.set_surname("Zhirov"); -// fn.set_patronymic("Alexandrovich"); -// -// exercise_2::Student s; -// s.set_allocated_name(&fn); -// s.add_grades(5); -// s.add_grades(2); -// s.add_grades(4); -// s.add_grades(3); -// s.add_grades(4); -// s.add_grades(3); -// s.add_grades(4); -// s.add_grades(3); -// s.set_avg_score(std::accumulate(s.grades().begin(), s.grades().end(), 0) / s.grades().size()); -// -// exercise_2::StudentsGroup sg; -// *sg.add_students() = s; -// -// std::ofstream out("student.bin", std::ios_base::binary); -// sg.SerializeToOstream(&out); - - exercise_2::StudentsGroup sg; - std::ifstream in("student.bin", std::ios_base::binary); - if (sg.ParseFromIstream(&in)) - { - std::cout << sg.students(0).name().surname() << std::endl; - std::cout << sg.students(0).avg_score() << std::endl; - } - else - { - std::cout << "Error!" << std::endl; - } + exercise_1_2(); + exercise_3(); return 0; } -- 2.40.1