diff --git a/tcpclient.cpp b/tcpclient.cpp index abebe53..64750ad 100644 --- a/tcpclient.cpp +++ b/tcpclient.cpp @@ -19,10 +19,23 @@ extern "C" { TCPClient::TCPClient() { sock = 0; + family = 0; } -std::expected TCPClient::conn(const std::string address, const int port) { - sock = socket(AF_INET, SOCK_STREAM, 0); +std::expected TCPClient::Connect(const std::string naddress, const int port) { + + struct sockaddr_in sa; + if (inet_pton(AF_INET, address.c_str(), &(sa.sin_addr)) == 1) { + family = AF_INET; + } else if (inet_pton(AF_INET6, address.c_str(), &(sa.sin_addr)) == 1) { + family = AF_INET6; + } else { + int errnocopy = errno; + std::string error = std::strerror(errnocopy); + return std::unexpected("Incorrect address " + naddress); + } + + sock = socket(family, SOCK_STREAM, 0); if (sock < 0) { return std::unexpected("Error opening socket"); } @@ -37,7 +50,7 @@ std::expected TCPClient::conn(const std::string address, cons } struct timeval timeout; - timeout.tv_sec = 3; + timeout.tv_sec = 5; timeout.tv_usec = 0; if (setsockopt(sock, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof timeout) < 0) { @@ -53,7 +66,7 @@ std::expected TCPClient::conn(const std::string address, cons } -std::expected TCPClient::writeBytes(std::span payload) { +std::expected TCPClient::Write(std::span payload) { int n = 0; if ((n = write(sock, payload.data(), payload.size())) < 0) { return std::unexpected("Write error"); @@ -61,7 +74,7 @@ std::expected TCPClient::writeBytes(std::span return n; } -std::expected TCPClient::writeBytes(std::string payload) { +std::expected TCPClient::Write(std::string payload) { int n = 0; if ((n = write(sock, payload.data(), payload.size())) < 0) { return std::unexpected("Write error"); @@ -69,7 +82,7 @@ std::expected TCPClient::writeBytes(std::string payload) { return n; } -std::expected TCPClient::readBytes(std::vector* buffer) { +std::expected TCPClient::Read(std::vector* buffer) { int n = 0; if ((n = read(sock, buffer->data(), buffer->size())) < 0) { return std::unexpected("Read error"); @@ -77,7 +90,7 @@ std::expected TCPClient::readBytes(std::vector* buf return n; } -std::expected TCPClient::readBytes(std::vector* buffer) { +std::expected TCPClient::Read(std::vector* buffer) { return read(sock, buffer->data(), buffer->size()); } diff --git a/tcpclient.hpp b/tcpclient.hpp index 0b7c1bb..4ccf0a1 100644 --- a/tcpclient.hpp +++ b/tcpclient.hpp @@ -8,13 +8,16 @@ class TCPClient { private: int sock; + int family; public: TCPClient(); - std::expected conn(std::string address, const int port); - std::expected writeBytes(std::span payload); - std::expected writeBytes(std::string payload); - std::expected readBytes(std::vector* buffer); - std::expected readBytes(std::vector* buffer); + std::expected Connect(std::string address, const int port); + + std::expected Write(std::span payload); + std::expected Write(std::string payload); + + std::expected Read(std::vector* buffer); + std::expected Read(std::vector* buffer); ~TCPClient() { close(sock); diff --git a/tcpclient_test.cpp b/tcpclient_test.cpp index dc3f007..d63c98f 100644 --- a/tcpclient_test.cpp +++ b/tcpclient_test.cpp @@ -9,12 +9,12 @@ int main( int argc, char** argv) { TCPClient client; - auto res = client.conn("209.51.188.116", 80); + auto res = client.Connect("209.51.188.116", 80); if (!res) { std::cerr << res.error() << std::endl; return 1; } - auto wSize = client.writeBytes("GET / HTTP/1.1\n\n\n"); + auto wSize = client.Write("GET / HTTP/1.1\n\n\n"); if (!wSize) { std::cerr << wSize.error() << std::endl; return 1; @@ -22,7 +22,7 @@ int main( int argc, char** argv) { std::vector buffer; buffer.resize(2048); - auto rSize = client.readBytes(&buffer); + auto rSize = client.Read(&buffer); if (!rSize) { std::cerr << rSize.error() << std::endl; return 1; diff --git a/udpclient.cpp b/udpclient.cpp index f409cbf..671ee99 100644 --- a/udpclient.cpp +++ b/udpclient.cpp @@ -17,24 +17,25 @@ extern "C" { #include #include - UDPClient::UDPClient(void) { sockfd = 0; rmax = 2024; }; -std::expected UDPClient::Bind(std::string hostname, int nport) { +std::expected UDPClient::Bind(std::string naddress, int nport) { port = nport; + address = naddress; - Resolver resolver; - auto resolveRes = resolver.Resolve(hostname); - if (!resolveRes) { - auto msg = std::format("Cannot resolve hostname {}: {}", hostname, resolveRes.error()); - return std::unexpected(msg); + struct sockaddr_in sa; + if (inet_pton(AF_INET, address.c_str(), &(sa.sin_addr)) == 1) { + family = AF_INET; + } else if (inet_pton(AF_INET6, address.c_str(), &(sa.sin_addr)) == 1) { + family = AF_INET6; + } else { + int errnocopy = errno; + std::string error = std::strerror(errnocopy); + return std::unexpected("Incorrect address " + naddress); } - auto addr = resolveRes.value(); - address = addr.GetAddress(); - family = addr.GetFamily(); if ((sockfd = socket(family, SOCK_DGRAM, 0)) < 0) { int errnocopy = errno; diff --git a/udpclient_test.cpp b/udpclient_test.cpp index e26420b..cbce947 100644 --- a/udpclient_test.cpp +++ b/udpclient_test.cpp @@ -4,11 +4,25 @@ #include #include +#include int main(int argc, char** argv) { UDPClient cli; std::string message("Hello"); - auto bindRes = cli.Bind("www.gnu.org", 1025); + + const std::string hostname("www.gnu.org"); + + Resolver resolver; + auto resolveRes = resolver.Resolve(hostname); + if (!resolveRes) { + auto msg = std::format("Cannot resolve hostname {}: {}", hostname, resolveRes.error()); + std::cerr << std::format("Error: {}", msg) << std::endl; + return 1; + } + auto raddr = resolveRes.value(); + auto address = raddr.GetAddress(); + + auto bindRes = cli.Bind(address, 1025); if (!bindRes) { std::cerr << std::format("Error: {}", bindRes.error()) << std::endl; return 1; diff --git a/works/header/header.cpp b/works/header/header.cpp new file mode 100644 index 0000000..f6bd4d1 --- /dev/null +++ b/works/header/header.cpp @@ -0,0 +1,49 @@ + +extern "C" { +#include +} + +#include +#include +#include +#include +#include +#include + +#include + +Header::Header(const uint32_t ipSize) { + pSize = ipSize; +} + +Header::Header(void) { + pSize = 0; +} + +std::string Header::Encode() { + std::string buffer, tmp; + auto magic = htonl(MAGIC); + tmp = std::string(reinterpret_cast(&magic), sizeof(magic)); + buffer.append(tmp); + + auto size = htonl(pSize); + tmp = std::string(reinterpret_cast(&size), sizeof(size)); + buffer.append(tmp); + return buffer; +} + +std::expected Header::Decode(const std::string rawHeader) { + uint32_t tmp; + std::memcpy(&tmp, rawHeader.data(), sizeof(uint32_t)); + auto magic = ntohl(tmp); + if (magic != MAGIC) { + return std::unexpected("Wrong magic code"); + } + std::memcpy(&tmp, rawHeader.data() + sizeof(uint32_t), sizeof(uint32_t)); + pSize = ntohl(tmp); + return {}; +} + +uint32_t Header::PacketSize() { + return pSize; +} diff --git a/works/header/header.hpp b/works/header/header.hpp new file mode 100644 index 0000000..95a1f3a --- /dev/null +++ b/works/header/header.hpp @@ -0,0 +1,16 @@ + +#include + +const uint32_t MAGIC = 0xABBA; + +class Header { +private: + uint32_t pSize = 0; +public: + Header(const uint32_t pSize); + Header(void); + std::string Encode(void); + std::expected Decode(const std::string buffer); + uint32_t PacketSize(void); +}; + diff --git a/works/header/header_test.cpp b/works/header/header_test.cpp new file mode 100644 index 0000000..4701956 --- /dev/null +++ b/works/header/header_test.cpp @@ -0,0 +1,20 @@ + +#include +#include +#include +#include +#include + +#include + +int main(int argc, char** argv) { + uint32_t size = + Header primary(1021); + auto rawHeader = primary.Encode(); + + Header second; + second.Decode(rawHeader); + + std::cout << std::format("{}\n", second.PacketSize()); + assert +} diff --git a/works/protopart/hello.pb.cc b/works/protopart/hello.pb.cc new file mode 100644 index 0000000..6942fd6 --- /dev/null +++ b/works/protopart/hello.pb.cc @@ -0,0 +1,761 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: hello.proto + +#include "hello.pb.h" + +#include + +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include + +PROTOBUF_PRAGMA_INIT_SEG + +namespace _pb = ::PROTOBUF_NAMESPACE_ID; +namespace _pbi = _pb::internal; + +namespace control { +PROTOBUF_CONSTEXPR Header::Header( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_.meta_)*/nullptr + , /*decltype(_impl_._cached_size_)*/{}} {} +struct HeaderDefaultTypeInternal { + PROTOBUF_CONSTEXPR HeaderDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} + ~HeaderDefaultTypeInternal() {} + union { + Header _instance; + }; +}; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 HeaderDefaultTypeInternal _Header_default_instance_; +PROTOBUF_CONSTEXPR Meta::Meta( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_.rpcname_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} + , /*decltype(_impl_._cached_size_)*/{}} {} +struct MetaDefaultTypeInternal { + PROTOBUF_CONSTEXPR MetaDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} + ~MetaDefaultTypeInternal() {} + union { + Meta _instance; + }; +}; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MetaDefaultTypeInternal _Meta_default_instance_; +PROTOBUF_CONSTEXPR Hello::Hello( + ::_pbi::ConstantInitialized): _impl_{ + /*decltype(_impl_.name_)*/{&::_pbi::fixed_address_empty_string, ::_pbi::ConstantInitialized{}} + , /*decltype(_impl_.meta_)*/nullptr + , /*decltype(_impl_.id_)*/0 + , /*decltype(_impl_._cached_size_)*/{}} {} +struct HelloDefaultTypeInternal { + PROTOBUF_CONSTEXPR HelloDefaultTypeInternal() + : _instance(::_pbi::ConstantInitialized{}) {} + ~HelloDefaultTypeInternal() {} + union { + Hello _instance; + }; +}; +PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 HelloDefaultTypeInternal _Hello_default_instance_; +} // namespace control +namespace control { + +// =================================================================== + +class Header::_Internal { + public: + static const ::control::Meta& meta(const Header* msg); +}; + +const ::control::Meta& +Header::_Internal::meta(const Header* msg) { + return *msg->_impl_.meta_; +} +Header::Header(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned) + : ::PROTOBUF_NAMESPACE_ID::MessageLite(arena, is_message_owned) { + SharedCtor(arena, is_message_owned); + // @@protoc_insertion_point(arena_constructor:control.Header) +} +Header::Header(const Header& from) + : ::PROTOBUF_NAMESPACE_ID::MessageLite() { + Header* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.meta_){nullptr} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom(from._internal_metadata_); + if (from._internal_has_meta()) { + _this->_impl_.meta_ = new ::control::Meta(*from._impl_.meta_); + } + // @@protoc_insertion_point(copy_constructor:control.Header) +} + +inline void Header::SharedCtor( + ::_pb::Arena* arena, bool is_message_owned) { + (void)arena; + (void)is_message_owned; + new (&_impl_) Impl_{ + decltype(_impl_.meta_){nullptr} + , /*decltype(_impl_._cached_size_)*/{} + }; +} + +Header::~Header() { + // @@protoc_insertion_point(destructor:control.Header) + if (auto *arena = _internal_metadata_.DeleteReturnArena()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void Header::SharedDtor() { + GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); + if (this != internal_default_instance()) delete _impl_.meta_; +} + +void Header::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void Header::Clear() { +// @@protoc_insertion_point(message_clear_start:control.Header) + uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + if (GetArenaForAllocation() == nullptr && _impl_.meta_ != nullptr) { + delete _impl_.meta_; + } + _impl_.meta_ = nullptr; + _internal_metadata_.Clear(); +} + +const char* Header::_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) { + // .control.Meta meta = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + ptr = ctx->ParseMessage(_internal_mutable_meta(), 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(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +uint8_t* Header::_InternalSerialize( + uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:control.Header) + uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + // .control.Meta meta = 1; + if (this->_internal_has_meta()) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: + InternalWriteMessage(1, _Internal::meta(this), + _Internal::meta(this).GetCachedSize(), target, stream); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), + static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:control.Header) + return target; +} + +size_t Header::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:control.Header) + size_t total_size = 0; + + uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // .control.Meta meta = 1; + if (this->_internal_has_meta()) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize( + *_impl_.meta_); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + total_size += _internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size(); + } + int cached_size = ::_pbi::ToCachedSize(total_size); + SetCachedSize(cached_size); + return total_size; +} + +void Header::CheckTypeAndMergeFrom( + const ::PROTOBUF_NAMESPACE_ID::MessageLite& from) { + MergeFrom(*::_pbi::DownCast( + &from)); +} + +void Header::MergeFrom(const Header& from) { + Header* const _this = this; + // @@protoc_insertion_point(class_specific_merge_from_start:control.Header) + GOOGLE_DCHECK_NE(&from, _this); + uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + if (from._internal_has_meta()) { + _this->_internal_mutable_meta()->::control::Meta::MergeFrom( + from._internal_meta()); + } + _this->_internal_metadata_.MergeFrom(from._internal_metadata_); +} + +void Header::CopyFrom(const Header& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:control.Header) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool Header::IsInitialized() const { + return true; +} + +void Header::InternalSwap(Header* other) { + using std::swap; + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + swap(_impl_.meta_, other->_impl_.meta_); +} + +std::string Header::GetTypeName() const { + return "control.Header"; +} + + +// =================================================================== + +class Meta::_Internal { + public: +}; + +Meta::Meta(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned) + : ::PROTOBUF_NAMESPACE_ID::MessageLite(arena, is_message_owned) { + SharedCtor(arena, is_message_owned); + // @@protoc_insertion_point(arena_constructor:control.Meta) +} +Meta::Meta(const Meta& from) + : ::PROTOBUF_NAMESPACE_ID::MessageLite() { + Meta* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.rpcname_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom(from._internal_metadata_); + _impl_.rpcname_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.rpcname_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (!from._internal_rpcname().empty()) { + _this->_impl_.rpcname_.Set(from._internal_rpcname(), + _this->GetArenaForAllocation()); + } + // @@protoc_insertion_point(copy_constructor:control.Meta) +} + +inline void Meta::SharedCtor( + ::_pb::Arena* arena, bool is_message_owned) { + (void)arena; + (void)is_message_owned; + new (&_impl_) Impl_{ + decltype(_impl_.rpcname_){} + , /*decltype(_impl_._cached_size_)*/{} + }; + _impl_.rpcname_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.rpcname_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING +} + +Meta::~Meta() { + // @@protoc_insertion_point(destructor:control.Meta) + if (auto *arena = _internal_metadata_.DeleteReturnArena()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void Meta::SharedDtor() { + GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); + _impl_.rpcname_.Destroy(); +} + +void Meta::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void Meta::Clear() { +// @@protoc_insertion_point(message_clear_start:control.Meta) + uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.rpcname_.ClearToEmpty(); + _internal_metadata_.Clear(); +} + +const char* Meta::_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) { + // string rpcname = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + auto str = _internal_mutable_rpcname(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + CHK_(::_pbi::VerifyUTF8(str, nullptr)); + } 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(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +uint8_t* Meta::_InternalSerialize( + uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:control.Meta) + uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + // string rpcname = 1; + if (!this->_internal_rpcname().empty()) { + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + this->_internal_rpcname().data(), static_cast(this->_internal_rpcname().length()), + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, + "control.Meta.rpcname"); + target = stream->WriteStringMaybeAliased( + 1, this->_internal_rpcname(), target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), + static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:control.Meta) + return target; +} + +size_t Meta::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:control.Meta) + size_t total_size = 0; + + uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // string rpcname = 1; + if (!this->_internal_rpcname().empty()) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_rpcname()); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + total_size += _internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size(); + } + int cached_size = ::_pbi::ToCachedSize(total_size); + SetCachedSize(cached_size); + return total_size; +} + +void Meta::CheckTypeAndMergeFrom( + const ::PROTOBUF_NAMESPACE_ID::MessageLite& from) { + MergeFrom(*::_pbi::DownCast( + &from)); +} + +void Meta::MergeFrom(const Meta& from) { + Meta* const _this = this; + // @@protoc_insertion_point(class_specific_merge_from_start:control.Meta) + GOOGLE_DCHECK_NE(&from, _this); + uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + if (!from._internal_rpcname().empty()) { + _this->_internal_set_rpcname(from._internal_rpcname()); + } + _this->_internal_metadata_.MergeFrom(from._internal_metadata_); +} + +void Meta::CopyFrom(const Meta& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:control.Meta) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool Meta::IsInitialized() const { + return true; +} + +void Meta::InternalSwap(Meta* other) { + using std::swap; + auto* lhs_arena = GetArenaForAllocation(); + auto* rhs_arena = other->GetArenaForAllocation(); + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( + &_impl_.rpcname_, lhs_arena, + &other->_impl_.rpcname_, rhs_arena + ); +} + +std::string Meta::GetTypeName() const { + return "control.Meta"; +} + + +// =================================================================== + +class Hello::_Internal { + public: + static const ::control::Meta& meta(const Hello* msg); +}; + +const ::control::Meta& +Hello::_Internal::meta(const Hello* msg) { + return *msg->_impl_.meta_; +} +Hello::Hello(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned) + : ::PROTOBUF_NAMESPACE_ID::MessageLite(arena, is_message_owned) { + SharedCtor(arena, is_message_owned); + // @@protoc_insertion_point(arena_constructor:control.Hello) +} +Hello::Hello(const Hello& from) + : ::PROTOBUF_NAMESPACE_ID::MessageLite() { + Hello* const _this = this; (void)_this; + new (&_impl_) Impl_{ + decltype(_impl_.name_){} + , decltype(_impl_.meta_){nullptr} + , decltype(_impl_.id_){} + , /*decltype(_impl_._cached_size_)*/{}}; + + _internal_metadata_.MergeFrom(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_name().empty()) { + _this->_impl_.name_.Set(from._internal_name(), + _this->GetArenaForAllocation()); + } + if (from._internal_has_meta()) { + _this->_impl_.meta_ = new ::control::Meta(*from._impl_.meta_); + } + _this->_impl_.id_ = from._impl_.id_; + // @@protoc_insertion_point(copy_constructor:control.Hello) +} + +inline void Hello::SharedCtor( + ::_pb::Arena* arena, bool is_message_owned) { + (void)arena; + (void)is_message_owned; + new (&_impl_) Impl_{ + decltype(_impl_.name_){} + , decltype(_impl_.meta_){nullptr} + , decltype(_impl_.id_){0} + , /*decltype(_impl_._cached_size_)*/{} + }; + _impl_.name_.InitDefault(); + #ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + _impl_.name_.Set("", GetArenaForAllocation()); + #endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING +} + +Hello::~Hello() { + // @@protoc_insertion_point(destructor:control.Hello) + if (auto *arena = _internal_metadata_.DeleteReturnArena()) { + (void)arena; + return; + } + SharedDtor(); +} + +inline void Hello::SharedDtor() { + GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); + _impl_.name_.Destroy(); + if (this != internal_default_instance()) delete _impl_.meta_; +} + +void Hello::SetCachedSize(int size) const { + _impl_._cached_size_.Set(size); +} + +void Hello::Clear() { +// @@protoc_insertion_point(message_clear_start:control.Hello) + uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + _impl_.name_.ClearToEmpty(); + if (GetArenaForAllocation() == nullptr && _impl_.meta_ != nullptr) { + delete _impl_.meta_; + } + _impl_.meta_ = nullptr; + _impl_.id_ = 0; + _internal_metadata_.Clear(); +} + +const char* Hello::_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) { + // .control.Meta meta = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 10)) { + ptr = ctx->ParseMessage(_internal_mutable_meta(), ptr); + CHK_(ptr); + } else + goto handle_unusual; + continue; + // int32 id = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 16)) { + _impl_.id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint32(&ptr); + CHK_(ptr); + } else + goto handle_unusual; + continue; + // string name = 3; + case 3: + if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 26)) { + auto str = _internal_mutable_name(); + ptr = ::_pbi::InlineGreedyStringParser(str, ptr, ctx); + CHK_(ptr); + CHK_(::_pbi::VerifyUTF8(str, nullptr)); + } 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(), + ptr, ctx); + CHK_(ptr != nullptr); + } // while +message_done: + return ptr; +failure: + ptr = nullptr; + goto message_done; +#undef CHK_ +} + +uint8_t* Hello::_InternalSerialize( + uint8_t* target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream* stream) const { + // @@protoc_insertion_point(serialize_to_array_start:control.Hello) + uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + // .control.Meta meta = 1; + if (this->_internal_has_meta()) { + target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: + InternalWriteMessage(1, _Internal::meta(this), + _Internal::meta(this).GetCachedSize(), target, stream); + } + + // int32 id = 2; + if (this->_internal_id() != 0) { + target = stream->EnsureSpace(target); + target = ::_pbi::WireFormatLite::WriteInt32ToArray(2, this->_internal_id(), target); + } + + // string name = 3; + if (!this->_internal_name().empty()) { + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + this->_internal_name().data(), static_cast(this->_internal_name().length()), + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, + "control.Hello.name"); + target = stream->WriteStringMaybeAliased( + 3, this->_internal_name(), target); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + target = stream->WriteRaw(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).data(), + static_cast(_internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size()), target); + } + // @@protoc_insertion_point(serialize_to_array_end:control.Hello) + return target; +} + +size_t Hello::ByteSizeLong() const { +// @@protoc_insertion_point(message_byte_size_start:control.Hello) + size_t total_size = 0; + + uint32_t cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void) cached_has_bits; + + // string name = 3; + if (!this->_internal_name().empty()) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize( + this->_internal_name()); + } + + // .control.Meta meta = 1; + if (this->_internal_has_meta()) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize( + *_impl_.meta_); + } + + // int32 id = 2; + if (this->_internal_id() != 0) { + total_size += ::_pbi::WireFormatLite::Int32SizePlusOne(this->_internal_id()); + } + + if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { + total_size += _internal_metadata_.unknown_fields(::PROTOBUF_NAMESPACE_ID::internal::GetEmptyString).size(); + } + int cached_size = ::_pbi::ToCachedSize(total_size); + SetCachedSize(cached_size); + return total_size; +} + +void Hello::CheckTypeAndMergeFrom( + const ::PROTOBUF_NAMESPACE_ID::MessageLite& from) { + MergeFrom(*::_pbi::DownCast( + &from)); +} + +void Hello::MergeFrom(const Hello& from) { + Hello* const _this = this; + // @@protoc_insertion_point(class_specific_merge_from_start:control.Hello) + GOOGLE_DCHECK_NE(&from, _this); + uint32_t cached_has_bits = 0; + (void) cached_has_bits; + + if (!from._internal_name().empty()) { + _this->_internal_set_name(from._internal_name()); + } + if (from._internal_has_meta()) { + _this->_internal_mutable_meta()->::control::Meta::MergeFrom( + from._internal_meta()); + } + if (from._internal_id() != 0) { + _this->_internal_set_id(from._internal_id()); + } + _this->_internal_metadata_.MergeFrom(from._internal_metadata_); +} + +void Hello::CopyFrom(const Hello& from) { +// @@protoc_insertion_point(class_specific_copy_from_start:control.Hello) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool Hello::IsInitialized() const { + return true; +} + +void Hello::InternalSwap(Hello* other) { + using std::swap; + auto* lhs_arena = GetArenaForAllocation(); + auto* rhs_arena = other->GetArenaForAllocation(); + _internal_metadata_.InternalSwap(&other->_internal_metadata_); + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr::InternalSwap( + &_impl_.name_, lhs_arena, + &other->_impl_.name_, rhs_arena + ); + ::PROTOBUF_NAMESPACE_ID::internal::memswap< + PROTOBUF_FIELD_OFFSET(Hello, _impl_.id_) + + sizeof(Hello::_impl_.id_) + - PROTOBUF_FIELD_OFFSET(Hello, _impl_.meta_)>( + reinterpret_cast(&_impl_.meta_), + reinterpret_cast(&other->_impl_.meta_)); +} + +std::string Hello::GetTypeName() const { + return "control.Hello"; +} + + +// @@protoc_insertion_point(namespace_scope) +} // namespace control +PROTOBUF_NAMESPACE_OPEN +template<> PROTOBUF_NOINLINE ::control::Header* +Arena::CreateMaybeMessage< ::control::Header >(Arena* arena) { + return Arena::CreateMessageInternal< ::control::Header >(arena); +} +template<> PROTOBUF_NOINLINE ::control::Meta* +Arena::CreateMaybeMessage< ::control::Meta >(Arena* arena) { + return Arena::CreateMessageInternal< ::control::Meta >(arena); +} +template<> PROTOBUF_NOINLINE ::control::Hello* +Arena::CreateMaybeMessage< ::control::Hello >(Arena* arena) { + return Arena::CreateMessageInternal< ::control::Hello >(arena); +} +PROTOBUF_NAMESPACE_CLOSE + +// @@protoc_insertion_point(global_scope) +#include diff --git a/works/protopart/hello.pb.h b/works/protopart/hello.pb.h new file mode 100644 index 0000000..b000732 --- /dev/null +++ b/works/protopart/hello.pb.h @@ -0,0 +1,836 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: hello.proto + +#ifndef GOOGLE_PROTOBUF_INCLUDED_hello_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_hello_2eproto + +#include +#include + +#include +#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 +#if 3021012 < 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 // IWYU pragma: export +#include // IWYU pragma: export +// @@protoc_insertion_point(includes) +#include +#define PROTOBUF_INTERNAL_EXPORT_hello_2eproto +PROTOBUF_NAMESPACE_OPEN +namespace internal { +class AnyMetadata; +} // namespace internal +PROTOBUF_NAMESPACE_CLOSE + +// Internal implementation detail -- do not use these members. +struct TableStruct_hello_2eproto { + static const uint32_t offsets[]; +}; +namespace control { +class Header; +struct HeaderDefaultTypeInternal; +extern HeaderDefaultTypeInternal _Header_default_instance_; +class Hello; +struct HelloDefaultTypeInternal; +extern HelloDefaultTypeInternal _Hello_default_instance_; +class Meta; +struct MetaDefaultTypeInternal; +extern MetaDefaultTypeInternal _Meta_default_instance_; +} // namespace control +PROTOBUF_NAMESPACE_OPEN +template<> ::control::Header* Arena::CreateMaybeMessage<::control::Header>(Arena*); +template<> ::control::Hello* Arena::CreateMaybeMessage<::control::Hello>(Arena*); +template<> ::control::Meta* Arena::CreateMaybeMessage<::control::Meta>(Arena*); +PROTOBUF_NAMESPACE_CLOSE +namespace control { + +// =================================================================== + +class Header final : + public ::PROTOBUF_NAMESPACE_ID::MessageLite /* @@protoc_insertion_point(class_definition:control.Header) */ { + public: + inline Header() : Header(nullptr) {} + ~Header() override; + explicit PROTOBUF_CONSTEXPR Header(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + Header(const Header& from); + Header(Header&& from) noexcept + : Header() { + *this = ::std::move(from); + } + + inline Header& operator=(const Header& from) { + CopyFrom(from); + return *this; + } + inline Header& operator=(Header&& 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; + } + + static const Header& default_instance() { + return *internal_default_instance(); + } + static inline const Header* internal_default_instance() { + return reinterpret_cast( + &_Header_default_instance_); + } + static constexpr int kIndexInFileMessages = + 0; + + friend void swap(Header& a, Header& b) { + a.Swap(&b); + } + inline void Swap(Header* 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(Header* other) { + if (other == this) return; + GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + Header* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage
(arena); + } + void CheckTypeAndMergeFrom(const ::PROTOBUF_NAMESPACE_ID::MessageLite& from) final; + void CopyFrom(const Header& from); + void MergeFrom(const Header& 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; + 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; + void InternalSwap(Header* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { + return "control.Header"; + } + protected: + explicit Header(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned = false); + public: + + std::string GetTypeName() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kMetaFieldNumber = 1, + }; + // .control.Meta meta = 1; + bool has_meta() const; + private: + bool _internal_has_meta() const; + public: + void clear_meta(); + const ::control::Meta& meta() const; + PROTOBUF_NODISCARD ::control::Meta* release_meta(); + ::control::Meta* mutable_meta(); + void set_allocated_meta(::control::Meta* meta); + private: + const ::control::Meta& _internal_meta() const; + ::control::Meta* _internal_mutable_meta(); + public: + void unsafe_arena_set_allocated_meta( + ::control::Meta* meta); + ::control::Meta* unsafe_arena_release_meta(); + + // @@protoc_insertion_point(class_scope:control.Header) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::control::Meta* meta_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_hello_2eproto; +}; +// ------------------------------------------------------------------- + +class Meta final : + public ::PROTOBUF_NAMESPACE_ID::MessageLite /* @@protoc_insertion_point(class_definition:control.Meta) */ { + public: + inline Meta() : Meta(nullptr) {} + ~Meta() override; + explicit PROTOBUF_CONSTEXPR Meta(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + Meta(const Meta& from); + Meta(Meta&& from) noexcept + : Meta() { + *this = ::std::move(from); + } + + inline Meta& operator=(const Meta& from) { + CopyFrom(from); + return *this; + } + inline Meta& operator=(Meta&& 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; + } + + static const Meta& default_instance() { + return *internal_default_instance(); + } + static inline const Meta* internal_default_instance() { + return reinterpret_cast( + &_Meta_default_instance_); + } + static constexpr int kIndexInFileMessages = + 1; + + friend void swap(Meta& a, Meta& b) { + a.Swap(&b); + } + inline void Swap(Meta* 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(Meta* other) { + if (other == this) return; + GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + Meta* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage(arena); + } + void CheckTypeAndMergeFrom(const ::PROTOBUF_NAMESPACE_ID::MessageLite& from) final; + void CopyFrom(const Meta& from); + void MergeFrom(const Meta& 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; + 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; + void InternalSwap(Meta* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { + return "control.Meta"; + } + protected: + explicit Meta(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned = false); + public: + + std::string GetTypeName() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kRpcnameFieldNumber = 1, + }; + // string rpcname = 1; + void clear_rpcname(); + const std::string& rpcname() const; + template + void set_rpcname(ArgT0&& arg0, ArgT... args); + std::string* mutable_rpcname(); + PROTOBUF_NODISCARD std::string* release_rpcname(); + void set_allocated_rpcname(std::string* rpcname); + private: + const std::string& _internal_rpcname() const; + inline PROTOBUF_ALWAYS_INLINE void _internal_set_rpcname(const std::string& value); + std::string* _internal_mutable_rpcname(); + public: + + // @@protoc_insertion_point(class_scope:control.Meta) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr rpcname_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_hello_2eproto; +}; +// ------------------------------------------------------------------- + +class Hello final : + public ::PROTOBUF_NAMESPACE_ID::MessageLite /* @@protoc_insertion_point(class_definition:control.Hello) */ { + public: + inline Hello() : Hello(nullptr) {} + ~Hello() override; + explicit PROTOBUF_CONSTEXPR Hello(::PROTOBUF_NAMESPACE_ID::internal::ConstantInitialized); + + Hello(const Hello& from); + Hello(Hello&& from) noexcept + : Hello() { + *this = ::std::move(from); + } + + inline Hello& operator=(const Hello& from) { + CopyFrom(from); + return *this; + } + inline Hello& operator=(Hello&& 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; + } + + static const Hello& default_instance() { + return *internal_default_instance(); + } + static inline const Hello* internal_default_instance() { + return reinterpret_cast( + &_Hello_default_instance_); + } + static constexpr int kIndexInFileMessages = + 2; + + friend void swap(Hello& a, Hello& b) { + a.Swap(&b); + } + inline void Swap(Hello* 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(Hello* other) { + if (other == this) return; + GOOGLE_DCHECK(GetOwningArena() == other->GetOwningArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + Hello* New(::PROTOBUF_NAMESPACE_ID::Arena* arena = nullptr) const final { + return CreateMaybeMessage(arena); + } + void CheckTypeAndMergeFrom(const ::PROTOBUF_NAMESPACE_ID::MessageLite& from) final; + void CopyFrom(const Hello& from); + void MergeFrom(const Hello& 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; + 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; + void InternalSwap(Hello* other); + + private: + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { + return "control.Hello"; + } + protected: + explicit Hello(::PROTOBUF_NAMESPACE_ID::Arena* arena, + bool is_message_owned = false); + public: + + std::string GetTypeName() const final; + + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kNameFieldNumber = 3, + kMetaFieldNumber = 1, + kIdFieldNumber = 2, + }; + // string name = 3; + 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: + + // .control.Meta meta = 1; + bool has_meta() const; + private: + bool _internal_has_meta() const; + public: + void clear_meta(); + const ::control::Meta& meta() const; + PROTOBUF_NODISCARD ::control::Meta* release_meta(); + ::control::Meta* mutable_meta(); + void set_allocated_meta(::control::Meta* meta); + private: + const ::control::Meta& _internal_meta() const; + ::control::Meta* _internal_mutable_meta(); + public: + void unsafe_arena_set_allocated_meta( + ::control::Meta* meta); + ::control::Meta* unsafe_arena_release_meta(); + + // int32 id = 2; + void clear_id(); + int32_t id() const; + void set_id(int32_t value); + private: + int32_t _internal_id() const; + void _internal_set_id(int32_t value); + public: + + // @@protoc_insertion_point(class_scope:control.Hello) + private: + class _Internal; + + template friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + struct Impl_ { + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr name_; + ::control::Meta* meta_; + int32_t id_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + }; + union { Impl_ _impl_; }; + friend struct ::TableStruct_hello_2eproto; +}; +// =================================================================== + + +// =================================================================== + +#ifdef __GNUC__ + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// Header + +// .control.Meta meta = 1; +inline bool Header::_internal_has_meta() const { + return this != internal_default_instance() && _impl_.meta_ != nullptr; +} +inline bool Header::has_meta() const { + return _internal_has_meta(); +} +inline void Header::clear_meta() { + if (GetArenaForAllocation() == nullptr && _impl_.meta_ != nullptr) { + delete _impl_.meta_; + } + _impl_.meta_ = nullptr; +} +inline const ::control::Meta& Header::_internal_meta() const { + const ::control::Meta* p = _impl_.meta_; + return p != nullptr ? *p : reinterpret_cast( + ::control::_Meta_default_instance_); +} +inline const ::control::Meta& Header::meta() const { + // @@protoc_insertion_point(field_get:control.Header.meta) + return _internal_meta(); +} +inline void Header::unsafe_arena_set_allocated_meta( + ::control::Meta* meta) { + if (GetArenaForAllocation() == nullptr) { + delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.meta_); + } + _impl_.meta_ = meta; + if (meta) { + + } else { + + } + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:control.Header.meta) +} +inline ::control::Meta* Header::release_meta() { + + ::control::Meta* temp = _impl_.meta_; + _impl_.meta_ = nullptr; +#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE + auto* old = reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(temp); + temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp); + if (GetArenaForAllocation() == nullptr) { delete old; } +#else // PROTOBUF_FORCE_COPY_IN_RELEASE + if (GetArenaForAllocation() != nullptr) { + temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp); + } +#endif // !PROTOBUF_FORCE_COPY_IN_RELEASE + return temp; +} +inline ::control::Meta* Header::unsafe_arena_release_meta() { + // @@protoc_insertion_point(field_release:control.Header.meta) + + ::control::Meta* temp = _impl_.meta_; + _impl_.meta_ = nullptr; + return temp; +} +inline ::control::Meta* Header::_internal_mutable_meta() { + + if (_impl_.meta_ == nullptr) { + auto* p = CreateMaybeMessage<::control::Meta>(GetArenaForAllocation()); + _impl_.meta_ = p; + } + return _impl_.meta_; +} +inline ::control::Meta* Header::mutable_meta() { + ::control::Meta* _msg = _internal_mutable_meta(); + // @@protoc_insertion_point(field_mutable:control.Header.meta) + return _msg; +} +inline void Header::set_allocated_meta(::control::Meta* meta) { + ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaForAllocation(); + if (message_arena == nullptr) { + delete _impl_.meta_; + } + if (meta) { + ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = + ::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena(meta); + if (message_arena != submessage_arena) { + meta = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( + message_arena, meta, submessage_arena); + } + + } else { + + } + _impl_.meta_ = meta; + // @@protoc_insertion_point(field_set_allocated:control.Header.meta) +} + +// ------------------------------------------------------------------- + +// Meta + +// string rpcname = 1; +inline void Meta::clear_rpcname() { + _impl_.rpcname_.ClearToEmpty(); +} +inline const std::string& Meta::rpcname() const { + // @@protoc_insertion_point(field_get:control.Meta.rpcname) + return _internal_rpcname(); +} +template +inline PROTOBUF_ALWAYS_INLINE +void Meta::set_rpcname(ArgT0&& arg0, ArgT... args) { + + _impl_.rpcname_.Set(static_cast(arg0), args..., GetArenaForAllocation()); + // @@protoc_insertion_point(field_set:control.Meta.rpcname) +} +inline std::string* Meta::mutable_rpcname() { + std::string* _s = _internal_mutable_rpcname(); + // @@protoc_insertion_point(field_mutable:control.Meta.rpcname) + return _s; +} +inline const std::string& Meta::_internal_rpcname() const { + return _impl_.rpcname_.Get(); +} +inline void Meta::_internal_set_rpcname(const std::string& value) { + + _impl_.rpcname_.Set(value, GetArenaForAllocation()); +} +inline std::string* Meta::_internal_mutable_rpcname() { + + return _impl_.rpcname_.Mutable(GetArenaForAllocation()); +} +inline std::string* Meta::release_rpcname() { + // @@protoc_insertion_point(field_release:control.Meta.rpcname) + return _impl_.rpcname_.Release(); +} +inline void Meta::set_allocated_rpcname(std::string* rpcname) { + if (rpcname != nullptr) { + + } else { + + } + _impl_.rpcname_.SetAllocated(rpcname, GetArenaForAllocation()); +#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING + if (_impl_.rpcname_.IsDefault()) { + _impl_.rpcname_.Set("", GetArenaForAllocation()); + } +#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING + // @@protoc_insertion_point(field_set_allocated:control.Meta.rpcname) +} + +// ------------------------------------------------------------------- + +// Hello + +// .control.Meta meta = 1; +inline bool Hello::_internal_has_meta() const { + return this != internal_default_instance() && _impl_.meta_ != nullptr; +} +inline bool Hello::has_meta() const { + return _internal_has_meta(); +} +inline void Hello::clear_meta() { + if (GetArenaForAllocation() == nullptr && _impl_.meta_ != nullptr) { + delete _impl_.meta_; + } + _impl_.meta_ = nullptr; +} +inline const ::control::Meta& Hello::_internal_meta() const { + const ::control::Meta* p = _impl_.meta_; + return p != nullptr ? *p : reinterpret_cast( + ::control::_Meta_default_instance_); +} +inline const ::control::Meta& Hello::meta() const { + // @@protoc_insertion_point(field_get:control.Hello.meta) + return _internal_meta(); +} +inline void Hello::unsafe_arena_set_allocated_meta( + ::control::Meta* meta) { + if (GetArenaForAllocation() == nullptr) { + delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.meta_); + } + _impl_.meta_ = meta; + if (meta) { + + } else { + + } + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:control.Hello.meta) +} +inline ::control::Meta* Hello::release_meta() { + + ::control::Meta* temp = _impl_.meta_; + _impl_.meta_ = nullptr; +#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE + auto* old = reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(temp); + temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp); + if (GetArenaForAllocation() == nullptr) { delete old; } +#else // PROTOBUF_FORCE_COPY_IN_RELEASE + if (GetArenaForAllocation() != nullptr) { + temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp); + } +#endif // !PROTOBUF_FORCE_COPY_IN_RELEASE + return temp; +} +inline ::control::Meta* Hello::unsafe_arena_release_meta() { + // @@protoc_insertion_point(field_release:control.Hello.meta) + + ::control::Meta* temp = _impl_.meta_; + _impl_.meta_ = nullptr; + return temp; +} +inline ::control::Meta* Hello::_internal_mutable_meta() { + + if (_impl_.meta_ == nullptr) { + auto* p = CreateMaybeMessage<::control::Meta>(GetArenaForAllocation()); + _impl_.meta_ = p; + } + return _impl_.meta_; +} +inline ::control::Meta* Hello::mutable_meta() { + ::control::Meta* _msg = _internal_mutable_meta(); + // @@protoc_insertion_point(field_mutable:control.Hello.meta) + return _msg; +} +inline void Hello::set_allocated_meta(::control::Meta* meta) { + ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaForAllocation(); + if (message_arena == nullptr) { + delete _impl_.meta_; + } + if (meta) { + ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = + ::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena(meta); + if (message_arena != submessage_arena) { + meta = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( + message_arena, meta, submessage_arena); + } + + } else { + + } + _impl_.meta_ = meta; + // @@protoc_insertion_point(field_set_allocated:control.Hello.meta) +} + +// int32 id = 2; +inline void Hello::clear_id() { + _impl_.id_ = 0; +} +inline int32_t Hello::_internal_id() const { + return _impl_.id_; +} +inline int32_t Hello::id() const { + // @@protoc_insertion_point(field_get:control.Hello.id) + return _internal_id(); +} +inline void Hello::_internal_set_id(int32_t value) { + + _impl_.id_ = value; +} +inline void Hello::set_id(int32_t value) { + _internal_set_id(value); + // @@protoc_insertion_point(field_set:control.Hello.id) +} + +// string name = 3; +inline void Hello::clear_name() { + _impl_.name_.ClearToEmpty(); +} +inline const std::string& Hello::name() const { + // @@protoc_insertion_point(field_get:control.Hello.name) + return _internal_name(); +} +template +inline PROTOBUF_ALWAYS_INLINE +void Hello::set_name(ArgT0&& arg0, ArgT... args) { + + _impl_.name_.Set(static_cast(arg0), args..., GetArenaForAllocation()); + // @@protoc_insertion_point(field_set:control.Hello.name) +} +inline std::string* Hello::mutable_name() { + std::string* _s = _internal_mutable_name(); + // @@protoc_insertion_point(field_mutable:control.Hello.name) + return _s; +} +inline const std::string& Hello::_internal_name() const { + return _impl_.name_.Get(); +} +inline void Hello::_internal_set_name(const std::string& value) { + + _impl_.name_.Set(value, GetArenaForAllocation()); +} +inline std::string* Hello::_internal_mutable_name() { + + return _impl_.name_.Mutable(GetArenaForAllocation()); +} +inline std::string* Hello::release_name() { + // @@protoc_insertion_point(field_release:control.Hello.name) + return _impl_.name_.Release(); +} +inline void Hello::set_allocated_name(std::string* name) { + if (name != nullptr) { + + } else { + + } + _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:control.Hello.name) +} + +#ifdef __GNUC__ + #pragma GCC diagnostic pop +#endif // __GNUC__ +// ------------------------------------------------------------------- + +// ------------------------------------------------------------------- + + +// @@protoc_insertion_point(namespace_scope) + +} // namespace control + +// @@protoc_insertion_point(global_scope) + +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_hello_2eproto diff --git a/works/protopart/hello.proto b/works/protopart/hello.proto new file mode 100644 index 0000000..3a6b43d --- /dev/null +++ b/works/protopart/hello.proto @@ -0,0 +1,21 @@ +syntax = "proto3"; + +package control; +option optimize_for = LITE_RUNTIME; +option cc_generic_services = false; + +message Header { + Meta meta = 1; +} +message Meta { + string rpcname = 1; +} + +message Hello { + Meta meta = 1; + int32 id = 2; + string name = 3; +} + + + diff --git a/works/protopart/message_test.cpp b/works/protopart/message_test.cpp new file mode 100644 index 0000000..399dd1e --- /dev/null +++ b/works/protopart/message_test.cpp @@ -0,0 +1,26 @@ + +#include +#include +#include +#include +#include + +#include + +int main(int argc, char** argv) { + control::Hello msg; + msg.set_id(1); + msg.set_name("bare"); + + auto meta = msg.mutable_meta(); + meta->set_rpcname("getHello"); + + std::string buffer; + msg.SerializeToString(&buffer); + + control::Header newmsg; + newmsg.ParsePartialFromString(buffer); + + auto newmeta = newmsg.meta(); + std::cout << std::format("{}\n", meta->rpcname()); +}