diff --git a/src/io/protobuf_transport/protobuf_transport.hpp b/src/io/protobuf_transport/protobuf_transport.hpp new file mode 100644 index 000000000..7c7f9624d --- /dev/null +++ b/src/io/protobuf_transport/protobuf_transport.hpp @@ -0,0 +1,60 @@ +// Copyright 2022 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#include "io/address.hpp" +#include "io/message_conversion.hpp" +#include "io/protobuf_transport/protobuf_transport_handle.hpp" +#include "io/transport.hpp" + +namespace memgraph::io::protobuf_transport { + +class ProtobufTransport { + std::shared_ptr protobuf_transport_handle_; + + public: + explicit ProtobufTransport(std::shared_ptr protobuf_transport_handle) + : protobuf_transport_handle_(std::move(protobuf_transport_handle)) {} + + template + ResponseFuture Request(Address to_address, Address from_address, RequestId request_id, RequestT request, + Duration timeout) { + auto [future, promise] = memgraph::io::FuturePromisePair>(); + + protobuf_transport_handle_->SubmitRequest(to_address, from_address, request_id, std::move(request), timeout, + std::move(promise)); + + return std::move(future); + } + + template + requires(sizeof...(Ms) > 0) RequestResult Receive(Address receiver_address, Duration timeout) { + return protobuf_transport_handle_->template Receive(receiver_address, timeout); + } + + template + void Send(Address to_address, Address from_address, RequestId request_id, M &&message) { + return protobuf_transport_handle_->template Send(to_address, from_address, request_id, std::forward(message)); + } + + Time Now() const { return protobuf_transport_handle_->Now(); } + + bool ShouldShutDown() const { return protobuf_transport_handle_->ShouldShutDown(); } + + template , class Return = uint64_t> + Return Rand(D distrib) { + std::random_device rng; + return distrib(rng); + } +}; + +}; // namespace memgraph::io::protobuf_transport diff --git a/src/io/protobuf_transport/protobuf_transport_handle.hpp b/src/io/protobuf_transport/protobuf_transport_handle.hpp new file mode 100644 index 000000000..51bc2a47d --- /dev/null +++ b/src/io/protobuf_transport/protobuf_transport_handle.hpp @@ -0,0 +1,153 @@ +// Copyright 2022 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#pragma once + +#include +#include +#include +#include +#include + +#include "google/protobuf/message.h" + +#include "io/address.hpp" +#include "io/transport.hpp" + +namespace memgraph::io::protobuf_transport { + +class ProtobufTransportHandle { + mutable std::mutex mu_{}; + mutable std::condition_variable cv_; + bool should_shut_down_ = false; + + // the responses to requests that are being waited on + std::map promises_; + + // messages that are sent to servers that may later receive them + std::vector can_receive_; + + public: + ~ProtobufTransportHandle() { + for (auto &&[pk, promise] : promises_) { + std::move(promise.promise).TimeOut(); + } + promises_.clear(); + } + + void ShutDown() { + std::unique_lock lock(mu_); + should_shut_down_ = true; + cv_.notify_all(); + } + + bool ShouldShutDown() const { + std::unique_lock lock(mu_); + return should_shut_down_; + } + + static Time Now() { + auto nano_time = std::chrono::system_clock::now(); + return std::chrono::time_point_cast(nano_time); + } + + template + requires(sizeof...(Ms) > 0) RequestResult Receive(Address /* receiver_address */, Duration timeout) { + std::unique_lock lock(mu_); + + Time before = Now(); + + spdlog::info("can_receive_ size: {}", can_receive_.size()); + + while (can_receive_.empty()) { + Time now = Now(); + + // protection against non-monotonic timesources + auto maxed_now = std::max(now, before); + auto elapsed = maxed_now - before; + + if (timeout < elapsed) { + return TimedOut{}; + } + + Duration relative_timeout = timeout - elapsed; + + std::cv_status cv_status_value = cv_.wait_for(lock, relative_timeout); + + if (cv_status_value == std::cv_status::timeout) { + return TimedOut{}; + } + } + + auto current_message = std::move(can_receive_.back()); + can_receive_.pop_back(); + + auto m_opt = std::move(current_message).Take(); + + return std::move(m_opt).value(); + } + + template + void Send(Address to_address, Address from_address, RequestId request_id, M &&message) { + std::any message_any(std::forward(message)); + OpaqueMessage opaque_message{.to_address = to_address, + .from_address = from_address, + .request_id = request_id, + .message = std::move(message_any)}; + + PromiseKey promise_key{ + .requester_address = to_address, .request_id = opaque_message.request_id, .replier_address = from_address}; + + { + std::unique_lock lock(mu_); + + if (promises_.contains(promise_key)) { + spdlog::info("using message to fill promise"); + // complete waiting promise if it's there + DeadlineAndOpaquePromise dop = std::move(promises_.at(promise_key)); + promises_.erase(promise_key); + + dop.promise.Fill(std::move(opaque_message)); + } else { + spdlog::info("placing message in can_receive_"); + + // TODO(tyler) send over socket to destination + can_receive_.emplace_back(std::move(opaque_message)); + } + } // lock dropped + + cv_.notify_all(); + } + + template + void SubmitRequest(Address to_address, Address from_address, RequestId request_id, RequestT &&request, + Duration timeout, ResponsePromise promise) { + const bool port_matches = to_address.last_known_port == from_address.last_known_port; + const bool ip_matches = to_address.last_known_ip == from_address.last_known_ip; + + MG_ASSERT(port_matches && ip_matches); + const Time deadline = Now() + timeout; + + { + std::unique_lock lock(mu_); + + PromiseKey promise_key{ + .requester_address = from_address, .request_id = request_id, .replier_address = to_address}; + OpaquePromise opaque_promise(std::move(promise).ToUnique()); + DeadlineAndOpaquePromise dop{.deadline = deadline, .promise = std::move(opaque_promise)}; + promises_.emplace(std::move(promise_key), std::move(dop)); + } // lock dropped + + Send(to_address, from_address, request_id, std::forward(request)); + } +}; + +} // namespace memgraph::io::protobuf_transport diff --git a/src/protobuf/echo_test.pb.cc b/src/protobuf/echo_test.pb.cc new file mode 100644 index 000000000..a550cd66a --- /dev/null +++ b/src/protobuf/echo_test.pb.cc @@ -0,0 +1,595 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: src/protobuf/echo_test.proto + +#include "protobuf/echo_test.pb.h" + +#include + +#include +#include +#include +#include +#include +#include +#include +// @@protoc_insertion_point(includes) +#include +namespace memgraph { +namespace protobuf { +class TestRequestDefaultTypeInternal { + public: + ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; +} _TestRequest_default_instance_; +class TestResponseDefaultTypeInternal { + public: + ::PROTOBUF_NAMESPACE_ID::internal::ExplicitlyConstructed _instance; +} _TestResponse_default_instance_; +} // namespace protobuf +} // namespace memgraph +static void InitDefaultsscc_info_TestRequest_src_2fprotobuf_2fecho_5ftest_2eproto() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + { + void *ptr = &::memgraph::protobuf::_TestRequest_default_instance_; + new (ptr)::memgraph::protobuf::TestRequest(); + ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); + } + ::memgraph::protobuf::TestRequest::InitAsDefaultInstance(); +} + +::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_TestRequest_src_2fprotobuf_2fecho_5ftest_2eproto = { + {ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, + InitDefaultsscc_info_TestRequest_src_2fprotobuf_2fecho_5ftest_2eproto}, + {}}; + +static void InitDefaultsscc_info_TestResponse_src_2fprotobuf_2fecho_5ftest_2eproto() { + GOOGLE_PROTOBUF_VERIFY_VERSION; + + { + void *ptr = &::memgraph::protobuf::_TestResponse_default_instance_; + new (ptr)::memgraph::protobuf::TestResponse(); + ::PROTOBUF_NAMESPACE_ID::internal::OnShutdownDestroyMessage(ptr); + } + ::memgraph::protobuf::TestResponse::InitAsDefaultInstance(); +} + +::PROTOBUF_NAMESPACE_ID::internal::SCCInfo<0> scc_info_TestResponse_src_2fprotobuf_2fecho_5ftest_2eproto = { + {ATOMIC_VAR_INIT(::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase::kUninitialized), 0, 0, + InitDefaultsscc_info_TestResponse_src_2fprotobuf_2fecho_5ftest_2eproto}, + {}}; + +static ::PROTOBUF_NAMESPACE_ID::Metadata file_level_metadata_src_2fprotobuf_2fecho_5ftest_2eproto[2]; +static constexpr ::PROTOBUF_NAMESPACE_ID::EnumDescriptor const * + *file_level_enum_descriptors_src_2fprotobuf_2fecho_5ftest_2eproto = nullptr; +static constexpr ::PROTOBUF_NAMESPACE_ID::ServiceDescriptor const * + *file_level_service_descriptors_src_2fprotobuf_2fecho_5ftest_2eproto = nullptr; + +const ::PROTOBUF_NAMESPACE_ID::uint32 + TableStruct_src_2fprotobuf_2fecho_5ftest_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::memgraph::protobuf::TestRequest, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + PROTOBUF_FIELD_OFFSET(::memgraph::protobuf::TestRequest, request_id_), + PROTOBUF_FIELD_OFFSET(::memgraph::protobuf::TestRequest, content_), + ~0u, // no _has_bits_ + PROTOBUF_FIELD_OFFSET(::memgraph::protobuf::TestResponse, _internal_metadata_), + ~0u, // no _extensions_ + ~0u, // no _oneof_case_ + ~0u, // no _weak_field_map_ + PROTOBUF_FIELD_OFFSET(::memgraph::protobuf::TestResponse, request_id_), + PROTOBUF_FIELD_OFFSET(::memgraph::protobuf::TestResponse, content_), +}; +static const ::PROTOBUF_NAMESPACE_ID::internal::MigrationSchema schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = { + {0, -1, sizeof(::memgraph::protobuf::TestRequest)}, + {7, -1, sizeof(::memgraph::protobuf::TestResponse)}, +}; + +static ::PROTOBUF_NAMESPACE_ID::Message const *const file_default_instances[] = { + reinterpret_cast(&::memgraph::protobuf::_TestRequest_default_instance_), + reinterpret_cast(&::memgraph::protobuf::_TestResponse_default_instance_), +}; + +const char descriptor_table_protodef_src_2fprotobuf_2fecho_5ftest_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = + "\n\034src/protobuf/echo_test.proto\022\021memgraph" + ".protobuf\"2\n\013TestRequest\022\022\n\nrequest_id\030\001" + " \001(\004\022\017\n\007content\030\002 \001(\t\"3\n\014TestResponse\022\022\n" + "\nrequest_id\030\001 \001(\004\022\017\n\007content\030\002 \001(\tb\006prot" + "o3"; +static const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable + *const descriptor_table_src_2fprotobuf_2fecho_5ftest_2eproto_deps[1] = {}; +static ::PROTOBUF_NAMESPACE_ID::internal::SCCInfoBase + *const descriptor_table_src_2fprotobuf_2fecho_5ftest_2eproto_sccs[2] = { + &scc_info_TestRequest_src_2fprotobuf_2fecho_5ftest_2eproto.base, + &scc_info_TestResponse_src_2fprotobuf_2fecho_5ftest_2eproto.base, +}; +static ::PROTOBUF_NAMESPACE_ID::internal::once_flag descriptor_table_src_2fprotobuf_2fecho_5ftest_2eproto_once; +const ::PROTOBUF_NAMESPACE_ID::internal::DescriptorTable descriptor_table_src_2fprotobuf_2fecho_5ftest_2eproto = { + false, + false, + descriptor_table_protodef_src_2fprotobuf_2fecho_5ftest_2eproto, + "src/protobuf/echo_test.proto", + 162, + &descriptor_table_src_2fprotobuf_2fecho_5ftest_2eproto_once, + descriptor_table_src_2fprotobuf_2fecho_5ftest_2eproto_sccs, + descriptor_table_src_2fprotobuf_2fecho_5ftest_2eproto_deps, + 2, + 0, + schemas, + file_default_instances, + TableStruct_src_2fprotobuf_2fecho_5ftest_2eproto::offsets, + file_level_metadata_src_2fprotobuf_2fecho_5ftest_2eproto, + 2, + file_level_enum_descriptors_src_2fprotobuf_2fecho_5ftest_2eproto, + file_level_service_descriptors_src_2fprotobuf_2fecho_5ftest_2eproto, +}; + +// Force running AddDescriptors() at dynamic initialization time. +static bool dynamic_init_dummy_src_2fprotobuf_2fecho_5ftest_2eproto = + (static_cast( + ::PROTOBUF_NAMESPACE_ID::internal::AddDescriptors(&descriptor_table_src_2fprotobuf_2fecho_5ftest_2eproto)), + true); +namespace memgraph { +namespace protobuf { + +// =================================================================== + +void TestRequest::InitAsDefaultInstance() {} +class TestRequest::_Internal { + public: +}; + +TestRequest::TestRequest(::PROTOBUF_NAMESPACE_ID::Arena *arena) : ::PROTOBUF_NAMESPACE_ID::Message(arena) { + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:memgraph.protobuf.TestRequest) +} +TestRequest::TestRequest(const TestRequest &from) : ::PROTOBUF_NAMESPACE_ID::Message() { + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + content_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + if (!from._internal_content().empty()) { + content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_content(), + GetArena()); + } + request_id_ = from.request_id_; + // @@protoc_insertion_point(copy_constructor:memgraph.protobuf.TestRequest) +} + +void TestRequest::SharedCtor() { + ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_TestRequest_src_2fprotobuf_2fecho_5ftest_2eproto.base); + content_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + request_id_ = PROTOBUF_ULONGLONG(0); +} + +TestRequest::~TestRequest() { + // @@protoc_insertion_point(destructor:memgraph.protobuf.TestRequest) + SharedDtor(); + _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +void TestRequest::SharedDtor() { + GOOGLE_DCHECK(GetArena() == nullptr); + content_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); +} + +void TestRequest::ArenaDtor(void *object) { + TestRequest *_this = reinterpret_cast(object); + (void)_this; +} +void TestRequest::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena *) {} +void TestRequest::SetCachedSize(int size) const { _cached_size_.Set(size); } +const TestRequest &TestRequest::default_instance() { + ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_TestRequest_src_2fprotobuf_2fecho_5ftest_2eproto.base); + return *internal_default_instance(); +} + +void TestRequest::Clear() { + // @@protoc_insertion_point(message_clear_start:memgraph.protobuf.TestRequest) + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void)cached_has_bits; + + content_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); + request_id_ = PROTOBUF_ULONGLONG(0); + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char *TestRequest::_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) { + // uint64 request_id = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { + request_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); + CHK_(ptr); + } else + goto handle_unusual; + continue; + // string content = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { + auto str = _internal_mutable_content(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "memgraph.protobuf.TestRequest.content")); + 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 *TestRequest::_InternalSerialize( + ::PROTOBUF_NAMESPACE_ID::uint8 *target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream *stream) const { + // @@protoc_insertion_point(serialize_to_array_start:memgraph.protobuf.TestRequest) + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + (void)cached_has_bits; + + // uint64 request_id = 1; + if (this->request_id() != 0) { + target = stream->EnsureSpace(target); + target = + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt64ToArray(1, this->_internal_request_id(), target); + } + + // string content = 2; + if (this->content().size() > 0) { + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + this->_internal_content().data(), static_cast(this->_internal_content().length()), + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "memgraph.protobuf.TestRequest.content"); + target = stream->WriteStringMaybeAliased(2, this->_internal_content(), 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:memgraph.protobuf.TestRequest) + return target; +} + +size_t TestRequest::ByteSizeLong() const { + // @@protoc_insertion_point(message_byte_size_start:memgraph.protobuf.TestRequest) + 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 content = 2; + if (this->content().size() > 0) { + total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(this->_internal_content()); + } + + // uint64 request_id = 1; + if (this->request_id() != 0) { + total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt64Size(this->_internal_request_id()); + } + + 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 TestRequest::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message &from) { + // @@protoc_insertion_point(generalized_merge_from_start:memgraph.protobuf.TestRequest) + GOOGLE_DCHECK_NE(&from, this); + const TestRequest *source = ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated(&from); + if (source == nullptr) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:memgraph.protobuf.TestRequest) + ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:memgraph.protobuf.TestRequest) + MergeFrom(*source); + } +} + +void TestRequest::MergeFrom(const TestRequest &from) { + // @@protoc_insertion_point(class_specific_merge_from_start:memgraph.protobuf.TestRequest) + 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.content().size() > 0) { + _internal_set_content(from._internal_content()); + } + if (from.request_id() != 0) { + _internal_set_request_id(from._internal_request_id()); + } +} + +void TestRequest::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message &from) { + // @@protoc_insertion_point(generalized_copy_from_start:memgraph.protobuf.TestRequest) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void TestRequest::CopyFrom(const TestRequest &from) { + // @@protoc_insertion_point(class_specific_copy_from_start:memgraph.protobuf.TestRequest) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool TestRequest::IsInitialized() const { return true; } + +void TestRequest::InternalSwap(TestRequest *other) { + using std::swap; + _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); + content_.Swap(&other->content_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); + swap(request_id_, other->request_id_); +} + +::PROTOBUF_NAMESPACE_ID::Metadata TestRequest::GetMetadata() const { return GetMetadataStatic(); } + +// =================================================================== + +void TestResponse::InitAsDefaultInstance() {} +class TestResponse::_Internal { + public: +}; + +TestResponse::TestResponse(::PROTOBUF_NAMESPACE_ID::Arena *arena) : ::PROTOBUF_NAMESPACE_ID::Message(arena) { + SharedCtor(); + RegisterArenaDtor(arena); + // @@protoc_insertion_point(arena_constructor:memgraph.protobuf.TestResponse) +} +TestResponse::TestResponse(const TestResponse &from) : ::PROTOBUF_NAMESPACE_ID::Message() { + _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + content_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + if (!from._internal_content().empty()) { + content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), from._internal_content(), + GetArena()); + } + request_id_ = from.request_id_; + // @@protoc_insertion_point(copy_constructor:memgraph.protobuf.TestResponse) +} + +void TestResponse::SharedCtor() { + ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&scc_info_TestResponse_src_2fprotobuf_2fecho_5ftest_2eproto.base); + content_.UnsafeSetDefault(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); + request_id_ = PROTOBUF_ULONGLONG(0); +} + +TestResponse::~TestResponse() { + // @@protoc_insertion_point(destructor:memgraph.protobuf.TestResponse) + SharedDtor(); + _internal_metadata_.Delete<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +void TestResponse::SharedDtor() { + GOOGLE_DCHECK(GetArena() == nullptr); + content_.DestroyNoArena(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited()); +} + +void TestResponse::ArenaDtor(void *object) { + TestResponse *_this = reinterpret_cast(object); + (void)_this; +} +void TestResponse::RegisterArenaDtor(::PROTOBUF_NAMESPACE_ID::Arena *) {} +void TestResponse::SetCachedSize(int size) const { _cached_size_.Set(size); } +const TestResponse &TestResponse::default_instance() { + ::PROTOBUF_NAMESPACE_ID::internal::InitSCC(&::scc_info_TestResponse_src_2fprotobuf_2fecho_5ftest_2eproto.base); + return *internal_default_instance(); +} + +void TestResponse::Clear() { + // @@protoc_insertion_point(message_clear_start:memgraph.protobuf.TestResponse) + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + // Prevent compiler warnings about cached_has_bits being unused + (void)cached_has_bits; + + content_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); + request_id_ = PROTOBUF_ULONGLONG(0); + _internal_metadata_.Clear<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(); +} + +const char *TestResponse::_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) { + // uint64 request_id = 1; + case 1: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 8)) { + request_id_ = ::PROTOBUF_NAMESPACE_ID::internal::ReadVarint64(&ptr); + CHK_(ptr); + } else + goto handle_unusual; + continue; + // string content = 2; + case 2: + if (PROTOBUF_PREDICT_TRUE(static_cast<::PROTOBUF_NAMESPACE_ID::uint8>(tag) == 18)) { + auto str = _internal_mutable_content(); + ptr = ::PROTOBUF_NAMESPACE_ID::internal::InlineGreedyStringParser(str, ptr, ctx); + CHK_(::PROTOBUF_NAMESPACE_ID::internal::VerifyUTF8(str, "memgraph.protobuf.TestResponse.content")); + 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 *TestResponse::_InternalSerialize( + ::PROTOBUF_NAMESPACE_ID::uint8 *target, ::PROTOBUF_NAMESPACE_ID::io::EpsCopyOutputStream *stream) const { + // @@protoc_insertion_point(serialize_to_array_start:memgraph.protobuf.TestResponse) + ::PROTOBUF_NAMESPACE_ID::uint32 cached_has_bits = 0; + (void)cached_has_bits; + + // uint64 request_id = 1; + if (this->request_id() != 0) { + target = stream->EnsureSpace(target); + target = + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::WriteUInt64ToArray(1, this->_internal_request_id(), target); + } + + // string content = 2; + if (this->content().size() > 0) { + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::VerifyUtf8String( + this->_internal_content().data(), static_cast(this->_internal_content().length()), + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::SERIALIZE, "memgraph.protobuf.TestResponse.content"); + target = stream->WriteStringMaybeAliased(2, this->_internal_content(), 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:memgraph.protobuf.TestResponse) + return target; +} + +size_t TestResponse::ByteSizeLong() const { + // @@protoc_insertion_point(message_byte_size_start:memgraph.protobuf.TestResponse) + 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 content = 2; + if (this->content().size() > 0) { + total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::StringSize(this->_internal_content()); + } + + // uint64 request_id = 1; + if (this->request_id() != 0) { + total_size += 1 + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::UInt64Size(this->_internal_request_id()); + } + + 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 TestResponse::MergeFrom(const ::PROTOBUF_NAMESPACE_ID::Message &from) { + // @@protoc_insertion_point(generalized_merge_from_start:memgraph.protobuf.TestResponse) + GOOGLE_DCHECK_NE(&from, this); + const TestResponse *source = ::PROTOBUF_NAMESPACE_ID::DynamicCastToGenerated(&from); + if (source == nullptr) { + // @@protoc_insertion_point(generalized_merge_from_cast_fail:memgraph.protobuf.TestResponse) + ::PROTOBUF_NAMESPACE_ID::internal::ReflectionOps::Merge(from, this); + } else { + // @@protoc_insertion_point(generalized_merge_from_cast_success:memgraph.protobuf.TestResponse) + MergeFrom(*source); + } +} + +void TestResponse::MergeFrom(const TestResponse &from) { + // @@protoc_insertion_point(class_specific_merge_from_start:memgraph.protobuf.TestResponse) + 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.content().size() > 0) { + _internal_set_content(from._internal_content()); + } + if (from.request_id() != 0) { + _internal_set_request_id(from._internal_request_id()); + } +} + +void TestResponse::CopyFrom(const ::PROTOBUF_NAMESPACE_ID::Message &from) { + // @@protoc_insertion_point(generalized_copy_from_start:memgraph.protobuf.TestResponse) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +void TestResponse::CopyFrom(const TestResponse &from) { + // @@protoc_insertion_point(class_specific_copy_from_start:memgraph.protobuf.TestResponse) + if (&from == this) return; + Clear(); + MergeFrom(from); +} + +bool TestResponse::IsInitialized() const { return true; } + +void TestResponse::InternalSwap(TestResponse *other) { + using std::swap; + _internal_metadata_.Swap<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(&other->_internal_metadata_); + content_.Swap(&other->content_, &::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); + swap(request_id_, other->request_id_); +} + +::PROTOBUF_NAMESPACE_ID::Metadata TestResponse::GetMetadata() const { return GetMetadataStatic(); } + +// @@protoc_insertion_point(namespace_scope) +} // namespace protobuf +} // namespace memgraph +PROTOBUF_NAMESPACE_OPEN +template <> +PROTOBUF_NOINLINE ::memgraph::protobuf::TestRequest *Arena::CreateMaybeMessage<::memgraph::protobuf::TestRequest>( + Arena *arena) { + return Arena::CreateMessageInternal<::memgraph::protobuf::TestRequest>(arena); +} +template <> +PROTOBUF_NOINLINE ::memgraph::protobuf::TestResponse *Arena::CreateMaybeMessage<::memgraph::protobuf::TestResponse>( + Arena *arena) { + return Arena::CreateMessageInternal<::memgraph::protobuf::TestResponse>(arena); +} +PROTOBUF_NAMESPACE_CLOSE + +// @@protoc_insertion_point(global_scope) +#include diff --git a/src/protobuf/echo_test.pb.h b/src/protobuf/echo_test.pb.h new file mode 100644 index 000000000..53f7598e3 --- /dev/null +++ b/src/protobuf/echo_test.pb.h @@ -0,0 +1,563 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: src/protobuf/echo_test.proto + +#ifndef GOOGLE_PROTOBUF_INCLUDED_src_2fprotobuf_2fecho_5ftest_2eproto +#define GOOGLE_PROTOBUF_INCLUDED_src_2fprotobuf_2fecho_5ftest_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 3012004 < 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 // IWYU pragma: export +#include +#include +#include +#include +#include +#include +#include +#include // IWYU pragma: export +#include +#include +// @@protoc_insertion_point(includes) +#include +#define PROTOBUF_INTERNAL_EXPORT_src_2fprotobuf_2fecho_5ftest_2eproto +PROTOBUF_NAMESPACE_OPEN +namespace internal { +class AnyMetadata; +} // namespace internal +PROTOBUF_NAMESPACE_CLOSE + +// Internal implementation detail -- do not use these members. +struct TableStruct_src_2fprotobuf_2fecho_5ftest_2eproto { + static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTableField entries[] PROTOBUF_SECTION_VARIABLE(protodesc_cold); + static const ::PROTOBUF_NAMESPACE_ID::internal::AuxillaryParseTableField aux[] PROTOBUF_SECTION_VARIABLE( + protodesc_cold); + static const ::PROTOBUF_NAMESPACE_ID::internal::ParseTable schema[2] 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_src_2fprotobuf_2fecho_5ftest_2eproto; +namespace memgraph { +namespace protobuf { +class TestRequest; +class TestRequestDefaultTypeInternal; +extern TestRequestDefaultTypeInternal _TestRequest_default_instance_; +class TestResponse; +class TestResponseDefaultTypeInternal; +extern TestResponseDefaultTypeInternal _TestResponse_default_instance_; +} // namespace protobuf +} // namespace memgraph +PROTOBUF_NAMESPACE_OPEN +template <> +::memgraph::protobuf::TestRequest *Arena::CreateMaybeMessage<::memgraph::protobuf::TestRequest>(Arena *); +template <> +::memgraph::protobuf::TestResponse *Arena::CreateMaybeMessage<::memgraph::protobuf::TestResponse>(Arena *); +PROTOBUF_NAMESPACE_CLOSE +namespace memgraph { +namespace protobuf { + +// =================================================================== + +class TestRequest PROTOBUF_FINAL + : public ::PROTOBUF_NAMESPACE_ID:: + Message /* @@protoc_insertion_point(class_definition:memgraph.protobuf.TestRequest) */ { + public: + inline TestRequest() : TestRequest(nullptr){}; + virtual ~TestRequest(); + + TestRequest(const TestRequest &from); + TestRequest(TestRequest &&from) noexcept : TestRequest() { *this = ::std::move(from); } + + inline TestRequest &operator=(const TestRequest &from) { + CopyFrom(from); + return *this; + } + inline TestRequest &operator=(TestRequest &&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 TestRequest &default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const TestRequest *internal_default_instance() { + return reinterpret_cast(&_TestRequest_default_instance_); + } + static constexpr int kIndexInFileMessages = 0; + + friend void swap(TestRequest &a, TestRequest &b) { a.Swap(&b); } + inline void Swap(TestRequest *other) { + if (other == this) return; + if (GetArena() == other->GetArena()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(TestRequest *other) { + if (other == this) return; + GOOGLE_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + inline TestRequest *New() const final { return CreateMaybeMessage(nullptr); } + + TestRequest *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 TestRequest &from); + void MergeFrom(const TestRequest &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(TestRequest *other); + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "memgraph.protobuf.TestRequest"; } + + protected: + explicit TestRequest(::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_src_2fprotobuf_2fecho_5ftest_2eproto); + return ::descriptor_table_src_2fprotobuf_2fecho_5ftest_2eproto.file_level_metadata[kIndexInFileMessages]; + } + + public: + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kContentFieldNumber = 2, + kRequestIdFieldNumber = 1, + }; + // string content = 2; + void clear_content(); + const std::string &content() const; + void set_content(const std::string &value); + void set_content(std::string &&value); + void set_content(const char *value); + void set_content(const char *value, size_t size); + std::string *mutable_content(); + std::string *release_content(); + void set_allocated_content(std::string *content); + GOOGLE_PROTOBUF_RUNTIME_DEPRECATED( + "The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") + std::string *unsafe_arena_release_content(); + GOOGLE_PROTOBUF_RUNTIME_DEPRECATED( + "The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") + void unsafe_arena_set_allocated_content(std::string *content); + + private: + const std::string &_internal_content() const; + void _internal_set_content(const std::string &value); + std::string *_internal_mutable_content(); + + public: + // uint64 request_id = 1; + void clear_request_id(); + ::PROTOBUF_NAMESPACE_ID::uint64 request_id() const; + void set_request_id(::PROTOBUF_NAMESPACE_ID::uint64 value); + + private: + ::PROTOBUF_NAMESPACE_ID::uint64 _internal_request_id() const; + void _internal_set_request_id(::PROTOBUF_NAMESPACE_ID::uint64 value); + + public: + // @@protoc_insertion_point(class_scope:memgraph.protobuf.TestRequest) + private: + class _Internal; + + template + friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr content_; + ::PROTOBUF_NAMESPACE_ID::uint64 request_id_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + friend struct ::TableStruct_src_2fprotobuf_2fecho_5ftest_2eproto; +}; +// ------------------------------------------------------------------- + +class TestResponse PROTOBUF_FINAL + : public ::PROTOBUF_NAMESPACE_ID:: + Message /* @@protoc_insertion_point(class_definition:memgraph.protobuf.TestResponse) */ { + public: + inline TestResponse() : TestResponse(nullptr){}; + virtual ~TestResponse(); + + TestResponse(const TestResponse &from); + TestResponse(TestResponse &&from) noexcept : TestResponse() { *this = ::std::move(from); } + + inline TestResponse &operator=(const TestResponse &from) { + CopyFrom(from); + return *this; + } + inline TestResponse &operator=(TestResponse &&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 TestResponse &default_instance(); + + static void InitAsDefaultInstance(); // FOR INTERNAL USE ONLY + static inline const TestResponse *internal_default_instance() { + return reinterpret_cast(&_TestResponse_default_instance_); + } + static constexpr int kIndexInFileMessages = 1; + + friend void swap(TestResponse &a, TestResponse &b) { a.Swap(&b); } + inline void Swap(TestResponse *other) { + if (other == this) return; + if (GetArena() == other->GetArena()) { + InternalSwap(other); + } else { + ::PROTOBUF_NAMESPACE_ID::internal::GenericSwap(this, other); + } + } + void UnsafeArenaSwap(TestResponse *other) { + if (other == this) return; + GOOGLE_DCHECK(GetArena() == other->GetArena()); + InternalSwap(other); + } + + // implements Message ---------------------------------------------- + + inline TestResponse *New() const final { return CreateMaybeMessage(nullptr); } + + TestResponse *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 TestResponse &from); + void MergeFrom(const TestResponse &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(TestResponse *other); + friend class ::PROTOBUF_NAMESPACE_ID::internal::AnyMetadata; + static ::PROTOBUF_NAMESPACE_ID::StringPiece FullMessageName() { return "memgraph.protobuf.TestResponse"; } + + protected: + explicit TestResponse(::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_src_2fprotobuf_2fecho_5ftest_2eproto); + return ::descriptor_table_src_2fprotobuf_2fecho_5ftest_2eproto.file_level_metadata[kIndexInFileMessages]; + } + + public: + // nested types ---------------------------------------------------- + + // accessors ------------------------------------------------------- + + enum : int { + kContentFieldNumber = 2, + kRequestIdFieldNumber = 1, + }; + // string content = 2; + void clear_content(); + const std::string &content() const; + void set_content(const std::string &value); + void set_content(std::string &&value); + void set_content(const char *value); + void set_content(const char *value, size_t size); + std::string *mutable_content(); + std::string *release_content(); + void set_allocated_content(std::string *content); + GOOGLE_PROTOBUF_RUNTIME_DEPRECATED( + "The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") + std::string *unsafe_arena_release_content(); + GOOGLE_PROTOBUF_RUNTIME_DEPRECATED( + "The unsafe_arena_ accessors for" + " string fields are deprecated and will be removed in a" + " future release.") + void unsafe_arena_set_allocated_content(std::string *content); + + private: + const std::string &_internal_content() const; + void _internal_set_content(const std::string &value); + std::string *_internal_mutable_content(); + + public: + // uint64 request_id = 1; + void clear_request_id(); + ::PROTOBUF_NAMESPACE_ID::uint64 request_id() const; + void set_request_id(::PROTOBUF_NAMESPACE_ID::uint64 value); + + private: + ::PROTOBUF_NAMESPACE_ID::uint64 _internal_request_id() const; + void _internal_set_request_id(::PROTOBUF_NAMESPACE_ID::uint64 value); + + public: + // @@protoc_insertion_point(class_scope:memgraph.protobuf.TestResponse) + private: + class _Internal; + + template + friend class ::PROTOBUF_NAMESPACE_ID::Arena::InternalHelper; + typedef void InternalArenaConstructable_; + typedef void DestructorSkippable_; + ::PROTOBUF_NAMESPACE_ID::internal::ArenaStringPtr content_; + ::PROTOBUF_NAMESPACE_ID::uint64 request_id_; + mutable ::PROTOBUF_NAMESPACE_ID::internal::CachedSize _cached_size_; + friend struct ::TableStruct_src_2fprotobuf_2fecho_5ftest_2eproto; +}; +// =================================================================== + +// =================================================================== + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wstrict-aliasing" +#endif // __GNUC__ +// TestRequest + +// uint64 request_id = 1; +inline void TestRequest::clear_request_id() { request_id_ = PROTOBUF_ULONGLONG(0); } +inline ::PROTOBUF_NAMESPACE_ID::uint64 TestRequest::_internal_request_id() const { return request_id_; } +inline ::PROTOBUF_NAMESPACE_ID::uint64 TestRequest::request_id() const { + // @@protoc_insertion_point(field_get:memgraph.protobuf.TestRequest.request_id) + return _internal_request_id(); +} +inline void TestRequest::_internal_set_request_id(::PROTOBUF_NAMESPACE_ID::uint64 value) { request_id_ = value; } +inline void TestRequest::set_request_id(::PROTOBUF_NAMESPACE_ID::uint64 value) { + _internal_set_request_id(value); + // @@protoc_insertion_point(field_set:memgraph.protobuf.TestRequest.request_id) +} + +// string content = 2; +inline void TestRequest::clear_content() { + content_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline const std::string &TestRequest::content() const { + // @@protoc_insertion_point(field_get:memgraph.protobuf.TestRequest.content) + return _internal_content(); +} +inline void TestRequest::set_content(const std::string &value) { + _internal_set_content(value); + // @@protoc_insertion_point(field_set:memgraph.protobuf.TestRequest.content) +} +inline std::string *TestRequest::mutable_content() { + // @@protoc_insertion_point(field_mutable:memgraph.protobuf.TestRequest.content) + return _internal_mutable_content(); +} +inline const std::string &TestRequest::_internal_content() const { return content_.Get(); } +inline void TestRequest::_internal_set_content(const std::string &value) { + content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); +} +inline void TestRequest::set_content(std::string &&value) { + content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); + // @@protoc_insertion_point(field_set_rvalue:memgraph.protobuf.TestRequest.content) +} +inline void TestRequest::set_content(const char *value) { + GOOGLE_DCHECK(value != nullptr); + + content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArena()); + // @@protoc_insertion_point(field_set_char:memgraph.protobuf.TestRequest.content) +} +inline void TestRequest::set_content(const char *value, size_t size) { + content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size), GetArena()); + // @@protoc_insertion_point(field_set_pointer:memgraph.protobuf.TestRequest.content) +} +inline std::string *TestRequest::_internal_mutable_content() { + return content_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline std::string *TestRequest::release_content() { + // @@protoc_insertion_point(field_release:memgraph.protobuf.TestRequest.content) + return content_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline void TestRequest::set_allocated_content(std::string *content) { + if (content != nullptr) { + } else { + } + content_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), content, GetArena()); + // @@protoc_insertion_point(field_set_allocated:memgraph.protobuf.TestRequest.content) +} +inline std::string *TestRequest::unsafe_arena_release_content() { + // @@protoc_insertion_point(field_unsafe_arena_release:memgraph.protobuf.TestRequest.content) + GOOGLE_DCHECK(GetArena() != nullptr); + + return content_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline void TestRequest::unsafe_arena_set_allocated_content(std::string *content) { + GOOGLE_DCHECK(GetArena() != nullptr); + if (content != nullptr) { + } else { + } + content_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), content, + GetArena()); + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:memgraph.protobuf.TestRequest.content) +} + +// ------------------------------------------------------------------- + +// TestResponse + +// uint64 request_id = 1; +inline void TestResponse::clear_request_id() { request_id_ = PROTOBUF_ULONGLONG(0); } +inline ::PROTOBUF_NAMESPACE_ID::uint64 TestResponse::_internal_request_id() const { return request_id_; } +inline ::PROTOBUF_NAMESPACE_ID::uint64 TestResponse::request_id() const { + // @@protoc_insertion_point(field_get:memgraph.protobuf.TestResponse.request_id) + return _internal_request_id(); +} +inline void TestResponse::_internal_set_request_id(::PROTOBUF_NAMESPACE_ID::uint64 value) { request_id_ = value; } +inline void TestResponse::set_request_id(::PROTOBUF_NAMESPACE_ID::uint64 value) { + _internal_set_request_id(value); + // @@protoc_insertion_point(field_set:memgraph.protobuf.TestResponse.request_id) +} + +// string content = 2; +inline void TestResponse::clear_content() { + content_.ClearToEmpty(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline const std::string &TestResponse::content() const { + // @@protoc_insertion_point(field_get:memgraph.protobuf.TestResponse.content) + return _internal_content(); +} +inline void TestResponse::set_content(const std::string &value) { + _internal_set_content(value); + // @@protoc_insertion_point(field_set:memgraph.protobuf.TestResponse.content) +} +inline std::string *TestResponse::mutable_content() { + // @@protoc_insertion_point(field_mutable:memgraph.protobuf.TestResponse.content) + return _internal_mutable_content(); +} +inline const std::string &TestResponse::_internal_content() const { return content_.Get(); } +inline void TestResponse::_internal_set_content(const std::string &value) { + content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), value, GetArena()); +} +inline void TestResponse::set_content(std::string &&value) { + content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::move(value), GetArena()); + // @@protoc_insertion_point(field_set_rvalue:memgraph.protobuf.TestResponse.content) +} +inline void TestResponse::set_content(const char *value) { + GOOGLE_DCHECK(value != nullptr); + + content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), ::std::string(value), GetArena()); + // @@protoc_insertion_point(field_set_char:memgraph.protobuf.TestResponse.content) +} +inline void TestResponse::set_content(const char *value, size_t size) { + content_.Set(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), + ::std::string(reinterpret_cast(value), size), GetArena()); + // @@protoc_insertion_point(field_set_pointer:memgraph.protobuf.TestResponse.content) +} +inline std::string *TestResponse::_internal_mutable_content() { + return content_.Mutable(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline std::string *TestResponse::release_content() { + // @@protoc_insertion_point(field_release:memgraph.protobuf.TestResponse.content) + return content_.Release(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline void TestResponse::set_allocated_content(std::string *content) { + if (content != nullptr) { + } else { + } + content_.SetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), content, GetArena()); + // @@protoc_insertion_point(field_set_allocated:memgraph.protobuf.TestResponse.content) +} +inline std::string *TestResponse::unsafe_arena_release_content() { + // @@protoc_insertion_point(field_unsafe_arena_release:memgraph.protobuf.TestResponse.content) + GOOGLE_DCHECK(GetArena() != nullptr); + + return content_.UnsafeArenaRelease(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), GetArena()); +} +inline void TestResponse::unsafe_arena_set_allocated_content(std::string *content) { + GOOGLE_DCHECK(GetArena() != nullptr); + if (content != nullptr) { + } else { + } + content_.UnsafeArenaSetAllocated(&::PROTOBUF_NAMESPACE_ID::internal::GetEmptyStringAlreadyInited(), content, + GetArena()); + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:memgraph.protobuf.TestResponse.content) +} + +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif // __GNUC__ +// ------------------------------------------------------------------- + +// @@protoc_insertion_point(namespace_scope) + +} // namespace protobuf +} // namespace memgraph + +// @@protoc_insertion_point(global_scope) + +#include +#endif // GOOGLE_PROTOBUF_INCLUDED_GOOGLE_PROTOBUF_INCLUDED_src_2fprotobuf_2fecho_5ftest_2eproto diff --git a/src/protobuf/echo_test.proto b/src/protobuf/echo_test.proto new file mode 100644 index 000000000..61ff33d5e --- /dev/null +++ b/src/protobuf/echo_test.proto @@ -0,0 +1,19 @@ +syntax = "proto3"; + +package memgraph.protobuf; + +message TestRequest { + // option optimize_for = LITE_RUNTIME; + // option cc_enable_arenas = true; + + uint64 request_id = 1; + string content = 2; +} + +message TestResponse { + // option optimize_for = LITE_RUNTIME; + // option cc_enable_arenas = true; + + uint64 request_id = 1; + string content = 2; +} diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 028eed26a..2bf838a45 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -433,3 +433,7 @@ target_link_libraries(${test_prefix}local_transport mg-io) # Test MachineManager with LocalTransport add_unit_test(machine_manager.cpp) target_link_libraries(${test_prefix}machine_manager mg-io mg-coordinator mg-storage-v3) + +# Test ProtobufTransport +add_unit_test(protobuf_transport.cpp) +target_link_libraries(${test_prefix}protobuf_transport mg-io protobuf) diff --git a/tests/unit/machine_manager.cpp b/tests/unit/machine_manager.cpp index 93f2cef23..f9b77a025 100644 --- a/tests/unit/machine_manager.cpp +++ b/tests/unit/machine_manager.cpp @@ -15,18 +15,17 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "coordinator/coordinator.hpp" +#include "coordinator/coordinator_client.hpp" +#include "coordinator/hybrid_logical_clock.hpp" +#include "coordinator/shard_map.hpp" +#include "io/local_transport/local_system.hpp" +#include "io/local_transport/local_transport.hpp" #include "io/rsm/rsm_client.hpp" +#include "io/transport.hpp" +#include "machine_manager/machine_config.hpp" +#include "machine_manager/machine_manager.hpp" +#include "query/v2/requests.hpp" #include "storage/v3/id_types.hpp" #include "storage/v3/schemas.hpp" diff --git a/tests/unit/protobuf_transport.cpp b/tests/unit/protobuf_transport.cpp new file mode 100644 index 000000000..249e0a75d --- /dev/null +++ b/tests/unit/protobuf_transport.cpp @@ -0,0 +1,47 @@ +// Copyright 2022 Memgraph Ltd. +// +// Use of this software is governed by the Business Source License +// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source +// License, and you may not use this file except in compliance with the Business Source License. +// +// As of the Change Date specified in that file, in accordance with +// the Business Source License, use of this software will be governed +// by the Apache License, Version 2.0, included in the file +// licenses/APL.txt. + +#include +#include +#include +#include + +#include + +#include "io/protobuf_transport/protobuf_transport.hpp" +#include "protobuf/echo_test.pb.cc" +#include "protobuf/echo_test.pb.h" + +namespace memgraph::io::tests { + +using memgraph::protobuf::TestRequest; +using memgraph::protobuf::TestResponse; + +TEST(ProtobufTransport, Echo) { + spdlog::error("ayo"); + + std::string out; + + TestRequest req; + req.set_request_id(1); + req.set_content("ping"); + + bool success = req.SerializeToString(&out); + + MG_ASSERT(success); + + TestRequest rt; + rt.ParseFromString(out); + + MG_ASSERT(rt.content() == req.content()); +} + +} // namespace memgraph::io::tests