ADD: some initial compiling infrastructure
This commit is contained in:
parent
1f9eb2f6f8
commit
df04dcee00
102
CMakeLists.txt
Normal file
102
CMakeLists.txt
Normal file
@ -0,0 +1,102 @@
|
||||
cmake_minimum_required (VERSION 3.25 FATAL_ERROR)
|
||||
project (whisperCom VERSION 0.0.1 LANGUAGES CXX C)
|
||||
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)
|
||||
|
||||
#
|
||||
# Options for compiling whisperCom
|
||||
#
|
||||
option(TEST_WHISPERCOM "Turn running of whisperCom specific tests on/off. Default: on" ON)
|
||||
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS 1)
|
||||
|
||||
#
|
||||
# some stuff required inclusion
|
||||
#
|
||||
include(doxygen)
|
||||
include(compdb)
|
||||
include(protobuf)
|
||||
|
||||
IF(${TEST_WHISPERCOM})
|
||||
include(CTest)
|
||||
ENDIF()
|
||||
|
||||
#
|
||||
# enable building documentation
|
||||
#
|
||||
build_docs(PROCESS_DOXYFILE DOXYFILE_PATH "docs/Doxyfile.in" )
|
||||
|
||||
#
|
||||
# External required projects
|
||||
#
|
||||
IF(NOT TARGET Catch2 AND ${TEST_WHISPERCOM})
|
||||
add_subdirectory(libs/Catch2 EXCLUDE_FROM_ALL)
|
||||
include(libs/Catch2/extras/Catch.cmake)
|
||||
ENDIF()
|
||||
|
||||
IF(NOT TARGET loguru)
|
||||
add_library(loguru STATIC libs/loguru/loguru.cpp libs/loguru/loguru.hpp)
|
||||
target_include_directories(loguru PUBLIC libs/loguru)
|
||||
target_compile_options(loguru PUBLIC -DLOGURU_WITH_STREAMS=1)
|
||||
set_property(TARGET loguru PROPERTY POSITION_INDEPENDENT_CODE 1)
|
||||
target_link_libraries(loguru PUBLIC dl)
|
||||
ENDIF()
|
||||
|
||||
IF(NOT TARGET libzmq)
|
||||
set(BUILD_STATIC ON CACHE BOOL "enable building zmq as static library")
|
||||
set(ENABLE_DRAFTS ON CACHE BOOL "enable zmq drafts")
|
||||
set(ENABLE_RADIX_TREE ON CACHE BOOL "enable ENABLE_RADIX_TREE drafts")
|
||||
set(ENABLE_WS ON CACHE BOOL "enable websocket support")
|
||||
set(WITH_OPENPGM ON CACHE BOOL "enable pgm protocol")
|
||||
set(WITH_LIBSODIUM ON CACHE BOOL "enable static libsodium support")
|
||||
set(WITH_LIBSODIUM_STATIC ON CACHE BOOL "enable static libsodium support")
|
||||
set(ENABLE_CURVE ON CACHE BOOL "enable curve cryptography in libsodium support")
|
||||
set(ZMQ_BUILD_TESTS OFF CACHE BOOL "disable zmq tests")
|
||||
set(OPENPGM_PKGCONFIG_NAME openpgm-5.3)
|
||||
add_subdirectory(libs/libzmq EXCLUDE_FROM_ALL)
|
||||
ENDIF()
|
||||
|
||||
IF(NOT TARGET cppzmq-static)
|
||||
set(CPPZMQ_BUILD_TESTS OFF CACHE BOOL "disbale cppzmq tests")
|
||||
add_subdirectory(libs/cppzmq EXCLUDE_FROM_ALL)
|
||||
ENDIF()
|
||||
|
||||
IF(NOT TARGET protobuf)
|
||||
SET(protobuf_BUILD_TESTS OFF CACHE BOOL "disable protobuf tests")
|
||||
SET(protobuf_BUILD_SHARED_LIBS OFF CACHE BOOL "disable shared libraries")
|
||||
#SET(WITH_PROTOC ON CACHE BOOL "enable building of protoc")
|
||||
add_subdirectory(libs/protobuf EXCLUDE_FROM_ALL)
|
||||
ENDIF()
|
||||
|
||||
# we are building with c++20
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
set(CMAKE_CXX_EXTENSIONS ON)
|
||||
|
||||
protobuf_generate_cpp(PROTO_PATH proto CPP_PATH proto HPP_PATH proto)
|
||||
|
||||
SET(WHISPERCOM_SOURCES
|
||||
proto/RouterMessage.pb.cc
|
||||
proto/Message.pb.cc
|
||||
proto/TestMessage.pb.cc
|
||||
include/WhisperCom/Router.hpp
|
||||
src/WhisperCom/Router.cpp
|
||||
include/WhisperCom/Service.hpp
|
||||
src/WhisperCom/Service.cpp
|
||||
)
|
||||
|
||||
add_library(whisperCom STATIC ${WHISPERCOM_SOURCES})
|
||||
target_link_libraries(whisperCom loguru cppzmq-static protobuf::libprotobuf ${CMAKE_THREAD_LIBS_INIT} )
|
||||
target_include_directories(whisperCom
|
||||
PUBLIC
|
||||
include
|
||||
proto
|
||||
PRIVATE
|
||||
src
|
||||
)
|
||||
add_dependencies(whisperCom protoc)
|
||||
|
||||
add_executable(wctest src/main.cpp)
|
||||
target_link_libraries(wctest whisperCom)
|
||||
|
||||
add_executable(wcListener src/Listener.cpp)
|
||||
target_link_libraries(wcListener whisperCom)
|
8443
compile_commands.json
Normal file
8443
compile_commands.json
Normal file
File diff suppressed because it is too large
Load Diff
23
docs/Doxyfile.in
Normal file
23
docs/Doxyfile.in
Normal file
@ -0,0 +1,23 @@
|
||||
DOXYFILE_ENCODING = UTF-8
|
||||
PROJECT_NAME = @PROJECT_NAME@
|
||||
PROJECT_NUMBER = "@GIT_BRANCH@ @GIT_COMMIT_HASH@"
|
||||
PROJECT_BRIEF = "library implementing a local and remote publish subscribe system without broker"
|
||||
OUTPUT_DIRECTORY = @CMAKE_CURRENT_BINARY_DIR@/doxygen/
|
||||
OUTPUT_LANGUAGE = English
|
||||
BRIEF_MEMBER_DESC = YES
|
||||
REPEAT_BRIEF = YES
|
||||
ALWAYS_DETAILED_SEC = NO
|
||||
INLINE_INHERITED_MEMB = NO
|
||||
FULL_PATH_NAMES = NO
|
||||
MULTILINE_CPP_IS_BRIEF = NO
|
||||
TAB_SIZE = 4
|
||||
MARKDOWN_SUPPORT = YES
|
||||
GENERATE_TODOLIST = YES
|
||||
GENERATE_TESTLIST = YES
|
||||
GENERATE_BUGLIST = YES
|
||||
GENERATE_DEPRECATEDLIST= YES
|
||||
INPUT = @CMAKE_CURRENT_SOURCE_DIR@/README.md @CMAKE_CURRENT_SOURCE_DIR@/src/ @CMAKE_CURRENT_SOURCE_DIR@/tests/ @CMAKE_CURRENT_SOURCE_DIR@/docs @CMAKE_CURRENT_SOURCE_DIR@/include
|
||||
INPUT_ENCODING = UTF-8
|
||||
FILE_PATTERNS = *.hpp *.cpp *.md
|
||||
USE_MDFILE_AS_MAINPAGE = README.md
|
||||
RECURSIVE = YES
|
90
include/WhisperCom/Router.hpp
Normal file
90
include/WhisperCom/Router.hpp
Normal file
@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
|
||||
#include "zmq.hpp"
|
||||
#include <condition_variable>
|
||||
#include <cstdint>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <thread>
|
||||
#include <map>
|
||||
#include <vector>
|
||||
|
||||
/**
|
||||
* @brief main namespace of WhisperCom
|
||||
*
|
||||
*/
|
||||
namespace WhisperCom
|
||||
{
|
||||
|
||||
class Router
|
||||
{
|
||||
private:
|
||||
|
||||
/// is the router ready
|
||||
bool isReady_;
|
||||
|
||||
/// local zmq url
|
||||
std::string localUrl_;
|
||||
|
||||
/// url for the radio socket
|
||||
std::string radiolUrl_;
|
||||
|
||||
/// url for the dish socket
|
||||
std::string dishUrl_;
|
||||
|
||||
/// zeromq context
|
||||
zmq::context_t zmqContext_;
|
||||
|
||||
/// local, system internal socket for connecting services
|
||||
zmq::socket_t localSocket_;
|
||||
|
||||
/// external socket for listening
|
||||
zmq::socket_t listening_;
|
||||
|
||||
/// external socket for transmitting
|
||||
zmq::socket_t transmitting_;
|
||||
|
||||
zmq::socket_t dummySocket_;
|
||||
|
||||
/// thread for running local processing in
|
||||
std::unique_ptr<std::thread> localProcesing_;
|
||||
|
||||
/// is the local processing thread running?
|
||||
std::atomic<bool> isLocalProcessingRunning_;
|
||||
|
||||
/// stop the local processing thread
|
||||
std::atomic<bool> stopLocalProcessing_;
|
||||
|
||||
/// map of connected clients and the last seen time
|
||||
std::map<std::uint32_t, std::uint32_t> localClients_;
|
||||
///mutex to protect localClients_
|
||||
std::mutex mutexLocalClients_;
|
||||
|
||||
/// map of clients subscribed to a specific topic
|
||||
std::map<std::string,std::vector<std::uint32_t>> subscription_;
|
||||
/// mutex to protect subscription_
|
||||
std::mutex mutexSubscription_;
|
||||
|
||||
void processLocalMessages_();
|
||||
void processLocalMessage_(zmq::message_t &msg);
|
||||
void processExternalMessage_(const zmq::message_t &msg);
|
||||
|
||||
public:
|
||||
Router(const std::string localUrl, const std::string radioUrl, const std::string dishUrl);
|
||||
Router() : Router("ipc:///tmp/whispercom", "udp://239.0.0.1:40000", "udp://*:40000"){}
|
||||
~Router();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
bool isReady() const {return isReady_;}
|
||||
}; // class Router
|
||||
|
||||
|
||||
}; //namespace WhisperCom
|
90
include/WhisperCom/Service.hpp
Normal file
90
include/WhisperCom/Service.hpp
Normal file
@ -0,0 +1,90 @@
|
||||
#pragma once
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include "RouterMessage.pb.h"
|
||||
#include "WhisperCom/Router.hpp"
|
||||
#include "zmq.hpp"
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <queue>
|
||||
|
||||
/**
|
||||
* @brief main namespace of WhisperCom
|
||||
*
|
||||
*/
|
||||
namespace WhisperCom
|
||||
{
|
||||
|
||||
class Service
|
||||
{
|
||||
private:
|
||||
|
||||
/// the local url to connect to
|
||||
std::string localUrl_;
|
||||
|
||||
/// the radio url to use within the router
|
||||
std::string radioUrl_;
|
||||
|
||||
/// the dish url to use within the router
|
||||
std::string dishUrl_;
|
||||
|
||||
/// a WhisperComm router for relaying messages off the computer
|
||||
std::unique_ptr<WhisperCom::Router> router_;
|
||||
|
||||
/// context for zeromq
|
||||
zmq::context_t zmqContext_;
|
||||
|
||||
/// socket for communication with the router
|
||||
zmq::socket_t socket_;
|
||||
|
||||
/// time of last keepalive
|
||||
std::atomic<std::chrono::steady_clock::time_point> lastKeepAlive_;
|
||||
|
||||
/// number of seconds without message to assume router dead
|
||||
std::uint32_t routerDeadTimeOut_;
|
||||
|
||||
/// number of seconds to transmit and request q keepalive
|
||||
std::uint32_t keepaliveTime_;
|
||||
|
||||
void keepalive_();
|
||||
std::unique_ptr<std::thread> keepaliveThread_;
|
||||
std::atomic<bool> stopKeepAlive_;
|
||||
std::atomic<bool> isKeepAliveRunning_;
|
||||
|
||||
void receive_();
|
||||
std::unique_ptr<std::thread> receiveThread_;
|
||||
std::atomic<bool> stopReceive_;
|
||||
std::atomic<bool> isReceiveRunning_;
|
||||
|
||||
std::queue<std::shared_ptr<WhisperCom::Protobuf::Message>> messageQueue_;
|
||||
|
||||
std::mutex mutexMessageQueue_;
|
||||
std::condition_variable condWaitMessageQueue_;
|
||||
|
||||
void processMessage_(const zmq::message_t &msg);
|
||||
void verifyRouter_();
|
||||
public:
|
||||
Service(const std::string localUrl, const std::string radioUrl,const std::string dishUrl, std::uint32_t routerDeadTimeout=10,std::uint32_t keepaliveTime=2);
|
||||
Service()
|
||||
: Service("ipc:///tmp/whispercom", "udp://239.0.0.1:40000", "udp://239.0.0.1:40000") {}
|
||||
~Service();
|
||||
|
||||
void subscribe(const std::string &topic);
|
||||
void unsubscribe(const std::string &topic);
|
||||
void unsubscribeAll();
|
||||
|
||||
bool hasMessages() {std::lock_guard<std::mutex> guard{mutexMessageQueue_}; return messageQueue_.size();}
|
||||
bool waitForMessage(std::chrono::milliseconds timeout);
|
||||
bool waitForMessage(std::chrono::milliseconds timeout, std::shared_ptr<WhisperCom::Protobuf::Message> message);
|
||||
std::shared_ptr<WhisperCom::Protobuf::Message> getMessage();
|
||||
bool sendMessage(const std::string &topic, WhisperCom::Protobuf::Message &data);
|
||||
void stop();
|
||||
}; // class Service
|
||||
|
||||
}; // namespace WhisperCom
|
367
proto/Message.pb.cc
Normal file
367
proto/Message.pb.cc
Normal file
@ -0,0 +1,367 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: Message.proto
|
||||
|
||||
#include "Message.pb.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "google/protobuf/io/coded_stream.h"
|
||||
#include "google/protobuf/extension_set.h"
|
||||
#include "google/protobuf/wire_format_lite.h"
|
||||
#include "google/protobuf/descriptor.h"
|
||||
#include "google/protobuf/generated_message_reflection.h"
|
||||
#include "google/protobuf/reflection_ops.h"
|
||||
#include "google/protobuf/wire_format.h"
|
||||
#include "google/protobuf/generated_message_tctable_impl.h"
|
||||
// @@protoc_insertion_point(includes)
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
PROTOBUF_PRAGMA_INIT_SEG
|
||||
namespace _pb = ::google::protobuf;
|
||||
namespace _pbi = ::google::protobuf::internal;
|
||||
namespace _fl = ::google::protobuf::internal::field_layout;
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
template <typename>
|
||||
PROTOBUF_CONSTEXPR Message::Message(::_pbi::ConstantInitialized)
|
||||
: _impl_{
|
||||
/*decltype(_impl_._has_bits_)*/ {},
|
||||
/*decltype(_impl_._cached_size_)*/ {},
|
||||
/*decltype(_impl_.payload_)*/ nullptr,
|
||||
/*decltype(_impl_.type_)*/ 0u,
|
||||
} {}
|
||||
struct MessageDefaultTypeInternal {
|
||||
PROTOBUF_CONSTEXPR MessageDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
|
||||
~MessageDefaultTypeInternal() {}
|
||||
union {
|
||||
Message _instance;
|
||||
};
|
||||
};
|
||||
|
||||
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
|
||||
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 MessageDefaultTypeInternal _Message_default_instance_;
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
static ::_pb::Metadata file_level_metadata_Message_2eproto[1];
|
||||
static constexpr const ::_pb::EnumDescriptor**
|
||||
file_level_enum_descriptors_Message_2eproto = nullptr;
|
||||
static constexpr const ::_pb::ServiceDescriptor**
|
||||
file_level_service_descriptors_Message_2eproto = nullptr;
|
||||
const ::uint32_t TableStruct_Message_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(
|
||||
protodesc_cold) = {
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::Message, _impl_._has_bits_),
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::Message, _internal_metadata_),
|
||||
~0u, // no _extensions_
|
||||
~0u, // no _oneof_case_
|
||||
~0u, // no _weak_field_map_
|
||||
~0u, // no _inlined_string_donated_
|
||||
~0u, // no _split_
|
||||
~0u, // no sizeof(Split)
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::Message, _impl_.type_),
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::Message, _impl_.payload_),
|
||||
~0u,
|
||||
0,
|
||||
};
|
||||
|
||||
static const ::_pbi::MigrationSchema
|
||||
schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
|
||||
{0, 10, -1, sizeof(::WhisperCom::Protobuf::Message)},
|
||||
};
|
||||
|
||||
static const ::_pb::Message* const file_default_instances[] = {
|
||||
&::WhisperCom::Protobuf::_Message_default_instance_._instance,
|
||||
};
|
||||
const char descriptor_table_protodef_Message_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
|
||||
"\n\rMessage.proto\022\023WhisperCom.Protobuf\032\031go"
|
||||
"ogle/protobuf/any.proto\">\n\007Message\022\014\n\004ty"
|
||||
"pe\030\001 \001(\r\022%\n\007payload\030\002 \001(\0132\024.google.proto"
|
||||
"buf.Anyb\006proto3"
|
||||
};
|
||||
static const ::_pbi::DescriptorTable* const descriptor_table_Message_2eproto_deps[1] =
|
||||
{
|
||||
&::descriptor_table_google_2fprotobuf_2fany_2eproto,
|
||||
};
|
||||
static ::absl::once_flag descriptor_table_Message_2eproto_once;
|
||||
const ::_pbi::DescriptorTable descriptor_table_Message_2eproto = {
|
||||
false,
|
||||
false,
|
||||
135,
|
||||
descriptor_table_protodef_Message_2eproto,
|
||||
"Message.proto",
|
||||
&descriptor_table_Message_2eproto_once,
|
||||
descriptor_table_Message_2eproto_deps,
|
||||
1,
|
||||
1,
|
||||
schemas,
|
||||
file_default_instances,
|
||||
TableStruct_Message_2eproto::offsets,
|
||||
file_level_metadata_Message_2eproto,
|
||||
file_level_enum_descriptors_Message_2eproto,
|
||||
file_level_service_descriptors_Message_2eproto,
|
||||
};
|
||||
|
||||
// This function exists to be marked as weak.
|
||||
// It can significantly speed up compilation by breaking up LLVM's SCC
|
||||
// in the .pb.cc translation units. Large translation units see a
|
||||
// reduction of more than 35% of walltime for optimized builds. Without
|
||||
// the weak attribute all the messages in the file, including all the
|
||||
// vtables and everything they use become part of the same SCC through
|
||||
// a cycle like:
|
||||
// GetMetadata -> descriptor table -> default instances ->
|
||||
// vtables -> GetMetadata
|
||||
// By adding a weak function here we break the connection from the
|
||||
// individual vtables back into the descriptor table.
|
||||
PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_Message_2eproto_getter() {
|
||||
return &descriptor_table_Message_2eproto;
|
||||
}
|
||||
// Force running AddDescriptors() at dynamic initialization time.
|
||||
PROTOBUF_ATTRIBUTE_INIT_PRIORITY2
|
||||
static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_Message_2eproto(&descriptor_table_Message_2eproto);
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
// ===================================================================
|
||||
|
||||
class Message::_Internal {
|
||||
public:
|
||||
using HasBits = decltype(std::declval<Message>()._impl_._has_bits_);
|
||||
static constexpr ::int32_t kHasBitsOffset =
|
||||
8 * PROTOBUF_FIELD_OFFSET(Message, _impl_._has_bits_);
|
||||
static const ::google::protobuf::Any& payload(const Message* msg);
|
||||
static void set_has_payload(HasBits* has_bits) {
|
||||
(*has_bits)[0] |= 1u;
|
||||
}
|
||||
};
|
||||
|
||||
const ::google::protobuf::Any& Message::_Internal::payload(const Message* msg) {
|
||||
return *msg->_impl_.payload_;
|
||||
}
|
||||
void Message::clear_payload() {
|
||||
if (_impl_.payload_ != nullptr) _impl_.payload_->Clear();
|
||||
_impl_._has_bits_[0] &= ~0x00000001u;
|
||||
}
|
||||
Message::Message(::google::protobuf::Arena* arena)
|
||||
: ::google::protobuf::Message(arena) {
|
||||
SharedCtor(arena);
|
||||
// @@protoc_insertion_point(arena_constructor:WhisperCom.Protobuf.Message)
|
||||
}
|
||||
Message::Message(const Message& from) : ::google::protobuf::Message() {
|
||||
Message* const _this = this;
|
||||
(void)_this;
|
||||
new (&_impl_) Impl_{
|
||||
decltype(_impl_._has_bits_){from._impl_._has_bits_},
|
||||
/*decltype(_impl_._cached_size_)*/ {},
|
||||
decltype(_impl_.payload_){nullptr},
|
||||
decltype(_impl_.type_){},
|
||||
};
|
||||
_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(
|
||||
from._internal_metadata_);
|
||||
if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) {
|
||||
_this->_impl_.payload_ = new ::google::protobuf::Any(*from._impl_.payload_);
|
||||
}
|
||||
_this->_impl_.type_ = from._impl_.type_;
|
||||
|
||||
// @@protoc_insertion_point(copy_constructor:WhisperCom.Protobuf.Message)
|
||||
}
|
||||
inline void Message::SharedCtor(::_pb::Arena* arena) {
|
||||
(void)arena;
|
||||
new (&_impl_) Impl_{
|
||||
decltype(_impl_._has_bits_){},
|
||||
/*decltype(_impl_._cached_size_)*/ {},
|
||||
decltype(_impl_.payload_){nullptr},
|
||||
decltype(_impl_.type_){0u},
|
||||
};
|
||||
}
|
||||
Message::~Message() {
|
||||
// @@protoc_insertion_point(destructor:WhisperCom.Protobuf.Message)
|
||||
_internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>();
|
||||
SharedDtor();
|
||||
}
|
||||
inline void Message::SharedDtor() {
|
||||
ABSL_DCHECK(GetArenaForAllocation() == nullptr);
|
||||
if (this != internal_default_instance()) delete _impl_.payload_;
|
||||
}
|
||||
void Message::SetCachedSize(int size) const {
|
||||
_impl_._cached_size_.Set(size);
|
||||
}
|
||||
|
||||
PROTOBUF_NOINLINE void Message::Clear() {
|
||||
// @@protoc_insertion_point(message_clear_start:WhisperCom.Protobuf.Message)
|
||||
::uint32_t cached_has_bits = 0;
|
||||
// Prevent compiler warnings about cached_has_bits being unused
|
||||
(void) cached_has_bits;
|
||||
|
||||
cached_has_bits = _impl_._has_bits_[0];
|
||||
if (cached_has_bits & 0x00000001u) {
|
||||
ABSL_DCHECK(_impl_.payload_ != nullptr);
|
||||
_impl_.payload_->Clear();
|
||||
}
|
||||
_impl_.type_ = 0u;
|
||||
_impl_._has_bits_.Clear();
|
||||
_internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
const char* Message::_InternalParse(
|
||||
const char* ptr, ::_pbi::ParseContext* ctx) {
|
||||
ptr = ::_pbi::TcParser::ParseLoop(this, ptr, ctx, &_table_.header);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1
|
||||
const ::_pbi::TcParseTable<1, 2, 1, 0, 2> Message::_table_ = {
|
||||
{
|
||||
PROTOBUF_FIELD_OFFSET(Message, _impl_._has_bits_),
|
||||
0, // no _extensions_
|
||||
2, 8, // max_field_number, fast_idx_mask
|
||||
offsetof(decltype(_table_), field_lookup_table),
|
||||
4294967292, // skipmap
|
||||
offsetof(decltype(_table_), field_entries),
|
||||
2, // num_field_entries
|
||||
1, // num_aux_entries
|
||||
offsetof(decltype(_table_), aux_entries),
|
||||
&_Message_default_instance_._instance,
|
||||
::_pbi::TcParser::GenericFallback, // fallback
|
||||
}, {{
|
||||
// .google.protobuf.Any payload = 2;
|
||||
{::_pbi::TcParser::FastMtS1,
|
||||
{18, 0, 0, PROTOBUF_FIELD_OFFSET(Message, _impl_.payload_)}},
|
||||
// uint32 type = 1;
|
||||
{::_pbi::TcParser::SingularVarintNoZag1<::uint32_t, offsetof(Message, _impl_.type_), 63>(),
|
||||
{8, 63, 0, PROTOBUF_FIELD_OFFSET(Message, _impl_.type_)}},
|
||||
}}, {{
|
||||
65535, 65535
|
||||
}}, {{
|
||||
// uint32 type = 1;
|
||||
{PROTOBUF_FIELD_OFFSET(Message, _impl_.type_), -1, 0,
|
||||
(0 | ::_fl::kFcSingular | ::_fl::kUInt32)},
|
||||
// .google.protobuf.Any payload = 2;
|
||||
{PROTOBUF_FIELD_OFFSET(Message, _impl_.payload_), _Internal::kHasBitsOffset + 0, 0,
|
||||
(0 | ::_fl::kFcOptional | ::_fl::kMessage | ::_fl::kTvTable)},
|
||||
}}, {{
|
||||
{::_pbi::TcParser::GetTable<::google::protobuf::Any>()},
|
||||
}}, {{
|
||||
}},
|
||||
};
|
||||
|
||||
::uint8_t* Message::_InternalSerialize(
|
||||
::uint8_t* target,
|
||||
::google::protobuf::io::EpsCopyOutputStream* stream) const {
|
||||
// @@protoc_insertion_point(serialize_to_array_start:WhisperCom.Protobuf.Message)
|
||||
::uint32_t cached_has_bits = 0;
|
||||
(void)cached_has_bits;
|
||||
|
||||
// uint32 type = 1;
|
||||
if (this->_internal_type() != 0) {
|
||||
target = stream->EnsureSpace(target);
|
||||
target = ::_pbi::WireFormatLite::WriteUInt32ToArray(
|
||||
1, this->_internal_type(), target);
|
||||
}
|
||||
|
||||
cached_has_bits = _impl_._has_bits_[0];
|
||||
// .google.protobuf.Any payload = 2;
|
||||
if (cached_has_bits & 0x00000001u) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::
|
||||
InternalWriteMessage(2, _Internal::payload(this),
|
||||
_Internal::payload(this).GetCachedSize(), target, stream);
|
||||
}
|
||||
|
||||
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
|
||||
target =
|
||||
::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray(
|
||||
_internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream);
|
||||
}
|
||||
// @@protoc_insertion_point(serialize_to_array_end:WhisperCom.Protobuf.Message)
|
||||
return target;
|
||||
}
|
||||
|
||||
::size_t Message::ByteSizeLong() const {
|
||||
// @@protoc_insertion_point(message_byte_size_start:WhisperCom.Protobuf.Message)
|
||||
::size_t total_size = 0;
|
||||
|
||||
::uint32_t cached_has_bits = 0;
|
||||
// Prevent compiler warnings about cached_has_bits being unused
|
||||
(void) cached_has_bits;
|
||||
|
||||
// .google.protobuf.Any payload = 2;
|
||||
cached_has_bits = _impl_._has_bits_[0];
|
||||
if (cached_has_bits & 0x00000001u) {
|
||||
total_size += 1 +
|
||||
::google::protobuf::internal::WireFormatLite::MessageSize(
|
||||
*_impl_.payload_);
|
||||
}
|
||||
|
||||
// uint32 type = 1;
|
||||
if (this->_internal_type() != 0) {
|
||||
total_size += ::_pbi::WireFormatLite::UInt32SizePlusOne(
|
||||
this->_internal_type());
|
||||
}
|
||||
|
||||
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
|
||||
}
|
||||
|
||||
const ::google::protobuf::Message::ClassData Message::_class_data_ = {
|
||||
::google::protobuf::Message::CopyWithSourceCheck,
|
||||
Message::MergeImpl
|
||||
};
|
||||
const ::google::protobuf::Message::ClassData*Message::GetClassData() const { return &_class_data_; }
|
||||
|
||||
|
||||
void Message::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
|
||||
auto* const _this = static_cast<Message*>(&to_msg);
|
||||
auto& from = static_cast<const Message&>(from_msg);
|
||||
// @@protoc_insertion_point(class_specific_merge_from_start:WhisperCom.Protobuf.Message)
|
||||
ABSL_DCHECK_NE(&from, _this);
|
||||
::uint32_t cached_has_bits = 0;
|
||||
(void) cached_has_bits;
|
||||
|
||||
if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) {
|
||||
_this->_internal_mutable_payload()->::google::protobuf::Any::MergeFrom(
|
||||
from._internal_payload());
|
||||
}
|
||||
if (from._internal_type() != 0) {
|
||||
_this->_internal_set_type(from._internal_type());
|
||||
}
|
||||
_this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_);
|
||||
}
|
||||
|
||||
void Message::CopyFrom(const Message& from) {
|
||||
// @@protoc_insertion_point(class_specific_copy_from_start:WhisperCom.Protobuf.Message)
|
||||
if (&from == this) return;
|
||||
Clear();
|
||||
MergeFrom(from);
|
||||
}
|
||||
|
||||
PROTOBUF_NOINLINE bool Message::IsInitialized() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void Message::InternalSwap(Message* other) {
|
||||
using std::swap;
|
||||
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
|
||||
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
|
||||
::google::protobuf::internal::memswap<
|
||||
PROTOBUF_FIELD_OFFSET(Message, _impl_.type_)
|
||||
+ sizeof(Message::_impl_.type_)
|
||||
- PROTOBUF_FIELD_OFFSET(Message, _impl_.payload_)>(
|
||||
reinterpret_cast<char*>(&_impl_.payload_),
|
||||
reinterpret_cast<char*>(&other->_impl_.payload_));
|
||||
}
|
||||
|
||||
::google::protobuf::Metadata Message::GetMetadata() const {
|
||||
return ::_pbi::AssignDescriptors(
|
||||
&descriptor_table_Message_2eproto_getter, &descriptor_table_Message_2eproto_once,
|
||||
file_level_metadata_Message_2eproto[0]);
|
||||
}
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
template<> PROTOBUF_NOINLINE ::WhisperCom::Protobuf::Message*
|
||||
Arena::CreateMaybeMessage< ::WhisperCom::Protobuf::Message >(Arena* arena) {
|
||||
return Arena::CreateMessageInternal< ::WhisperCom::Protobuf::Message >(arena);
|
||||
}
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
#include "google/protobuf/port_undef.inc"
|
389
proto/Message.pb.h
Normal file
389
proto/Message.pb.h
Normal file
@ -0,0 +1,389 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: Message.proto
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_INCLUDED_Message_2eproto_2epb_2eh
|
||||
#define GOOGLE_PROTOBUF_INCLUDED_Message_2eproto_2epb_2eh
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "google/protobuf/port_def.inc"
|
||||
#if PROTOBUF_VERSION < 4023000
|
||||
#error "This file was generated by a newer version of protoc which is"
|
||||
#error "incompatible with your Protocol Buffer headers. Please update"
|
||||
#error "your headers."
|
||||
#endif // PROTOBUF_VERSION
|
||||
|
||||
#if 4023000 < PROTOBUF_MIN_PROTOC_VERSION
|
||||
#error "This file was generated by an older version of protoc which is"
|
||||
#error "incompatible with your Protocol Buffer headers. Please"
|
||||
#error "regenerate this file with a newer version of protoc."
|
||||
#endif // PROTOBUF_MIN_PROTOC_VERSION
|
||||
#include "google/protobuf/port_undef.inc"
|
||||
#include "google/protobuf/io/coded_stream.h"
|
||||
#include "google/protobuf/arena.h"
|
||||
#include "google/protobuf/arenastring.h"
|
||||
#include "google/protobuf/generated_message_tctable_decl.h"
|
||||
#include "google/protobuf/generated_message_util.h"
|
||||
#include "google/protobuf/metadata_lite.h"
|
||||
#include "google/protobuf/generated_message_reflection.h"
|
||||
#include "google/protobuf/message.h"
|
||||
#include "google/protobuf/repeated_field.h" // IWYU pragma: export
|
||||
#include "google/protobuf/extension_set.h" // IWYU pragma: export
|
||||
#include "google/protobuf/unknown_field_set.h"
|
||||
#include "google/protobuf/any.pb.h"
|
||||
// @@protoc_insertion_point(includes)
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
|
||||
#define PROTOBUF_INTERNAL_EXPORT_Message_2eproto
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
class AnyMetadata;
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
// Internal implementation detail -- do not use these members.
|
||||
struct TableStruct_Message_2eproto {
|
||||
static const ::uint32_t offsets[];
|
||||
};
|
||||
extern const ::google::protobuf::internal::DescriptorTable
|
||||
descriptor_table_Message_2eproto;
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
class Message;
|
||||
struct MessageDefaultTypeInternal;
|
||||
extern MessageDefaultTypeInternal _Message_default_instance_;
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
template <>
|
||||
::WhisperCom::Protobuf::Message* Arena::CreateMaybeMessage<::WhisperCom::Protobuf::Message>(Arena*);
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
class Message final :
|
||||
public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:WhisperCom.Protobuf.Message) */ {
|
||||
public:
|
||||
inline Message() : Message(nullptr) {}
|
||||
~Message() override;
|
||||
template<typename = void>
|
||||
explicit PROTOBUF_CONSTEXPR Message(::google::protobuf::internal::ConstantInitialized);
|
||||
|
||||
Message(const Message& from);
|
||||
Message(Message&& from) noexcept
|
||||
: Message() {
|
||||
*this = ::std::move(from);
|
||||
}
|
||||
|
||||
inline Message& operator=(const Message& from) {
|
||||
CopyFrom(from);
|
||||
return *this;
|
||||
}
|
||||
inline Message& operator=(Message&& from) noexcept {
|
||||
if (this == &from) return *this;
|
||||
if (GetOwningArena() == from.GetOwningArena()
|
||||
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
|
||||
&& GetOwningArena() != nullptr
|
||||
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
|
||||
) {
|
||||
InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
|
||||
return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance);
|
||||
}
|
||||
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
|
||||
return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
static const ::google::protobuf::Descriptor* descriptor() {
|
||||
return GetDescriptor();
|
||||
}
|
||||
static const ::google::protobuf::Descriptor* GetDescriptor() {
|
||||
return default_instance().GetMetadata().descriptor;
|
||||
}
|
||||
static const ::google::protobuf::Reflection* GetReflection() {
|
||||
return default_instance().GetMetadata().reflection;
|
||||
}
|
||||
static const Message& default_instance() {
|
||||
return *internal_default_instance();
|
||||
}
|
||||
static inline const Message* internal_default_instance() {
|
||||
return reinterpret_cast<const Message*>(
|
||||
&_Message_default_instance_);
|
||||
}
|
||||
static constexpr int kIndexInFileMessages =
|
||||
0;
|
||||
|
||||
friend void swap(Message& a, Message& b) {
|
||||
a.Swap(&b);
|
||||
}
|
||||
inline void Swap(Message* 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 {
|
||||
::google::protobuf::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(Message* other) {
|
||||
if (other == this) return;
|
||||
ABSL_DCHECK(GetOwningArena() == other->GetOwningArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
// implements Message ----------------------------------------------
|
||||
|
||||
Message* New(::google::protobuf::Arena* arena = nullptr) const final {
|
||||
return CreateMaybeMessage<Message>(arena);
|
||||
}
|
||||
using ::google::protobuf::Message::CopyFrom;
|
||||
void CopyFrom(const Message& from);
|
||||
using ::google::protobuf::Message::MergeFrom;
|
||||
void MergeFrom( const Message& from) {
|
||||
Message::MergeImpl(*this, from);
|
||||
}
|
||||
private:
|
||||
static void MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg);
|
||||
public:
|
||||
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final;
|
||||
bool IsInitialized() const final;
|
||||
|
||||
::size_t ByteSizeLong() const final;
|
||||
const char* _InternalParse(const char* ptr, ::google::protobuf::internal::ParseContext* ctx) final;
|
||||
::uint8_t* _InternalSerialize(
|
||||
::uint8_t* target, ::google::protobuf::io::EpsCopyOutputStream* stream) const final;
|
||||
int GetCachedSize() const final { return _impl_._cached_size_.Get(); }
|
||||
|
||||
private:
|
||||
void SharedCtor(::google::protobuf::Arena* arena);
|
||||
void SharedDtor();
|
||||
void SetCachedSize(int size) const final;
|
||||
void InternalSwap(Message* other);
|
||||
|
||||
private:
|
||||
friend class ::google::protobuf::internal::AnyMetadata;
|
||||
static ::absl::string_view FullMessageName() {
|
||||
return "WhisperCom.Protobuf.Message";
|
||||
}
|
||||
protected:
|
||||
explicit Message(::google::protobuf::Arena* arena);
|
||||
public:
|
||||
|
||||
static const ClassData _class_data_;
|
||||
const ::google::protobuf::Message::ClassData*GetClassData() const final;
|
||||
|
||||
::google::protobuf::Metadata GetMetadata() const final;
|
||||
|
||||
// nested types ----------------------------------------------------
|
||||
|
||||
// accessors -------------------------------------------------------
|
||||
|
||||
enum : int {
|
||||
kPayloadFieldNumber = 2,
|
||||
kTypeFieldNumber = 1,
|
||||
};
|
||||
// .google.protobuf.Any payload = 2;
|
||||
bool has_payload() const;
|
||||
void clear_payload() ;
|
||||
const ::google::protobuf::Any& payload() const;
|
||||
PROTOBUF_NODISCARD ::google::protobuf::Any* release_payload();
|
||||
::google::protobuf::Any* mutable_payload();
|
||||
void set_allocated_payload(::google::protobuf::Any* value);
|
||||
void unsafe_arena_set_allocated_payload(::google::protobuf::Any* value);
|
||||
::google::protobuf::Any* unsafe_arena_release_payload();
|
||||
|
||||
private:
|
||||
const ::google::protobuf::Any& _internal_payload() const;
|
||||
::google::protobuf::Any* _internal_mutable_payload();
|
||||
|
||||
public:
|
||||
// uint32 type = 1;
|
||||
void clear_type() ;
|
||||
::uint32_t type() const;
|
||||
void set_type(::uint32_t value);
|
||||
|
||||
private:
|
||||
::uint32_t _internal_type() const;
|
||||
void _internal_set_type(::uint32_t value);
|
||||
|
||||
public:
|
||||
// @@protoc_insertion_point(class_scope:WhisperCom.Protobuf.Message)
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
friend class ::google::protobuf::internal::TcParser;
|
||||
static const ::google::protobuf::internal::TcParseTable<1, 2, 1, 0, 2> _table_;
|
||||
template <typename T> friend class ::google::protobuf::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
struct Impl_ {
|
||||
::google::protobuf::internal::HasBits<1> _has_bits_;
|
||||
mutable ::google::protobuf::internal::CachedSize _cached_size_;
|
||||
::google::protobuf::Any* payload_;
|
||||
::uint32_t type_;
|
||||
};
|
||||
union { Impl_ _impl_; };
|
||||
friend struct ::TableStruct_Message_2eproto;
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif // __GNUC__
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// Message
|
||||
|
||||
// uint32 type = 1;
|
||||
inline void Message::clear_type() {
|
||||
_impl_.type_ = 0u;
|
||||
}
|
||||
inline ::uint32_t Message::type() const {
|
||||
// @@protoc_insertion_point(field_get:WhisperCom.Protobuf.Message.type)
|
||||
return _internal_type();
|
||||
}
|
||||
inline void Message::set_type(::uint32_t value) {
|
||||
_internal_set_type(value);
|
||||
// @@protoc_insertion_point(field_set:WhisperCom.Protobuf.Message.type)
|
||||
}
|
||||
inline ::uint32_t Message::_internal_type() const {
|
||||
return _impl_.type_;
|
||||
}
|
||||
inline void Message::_internal_set_type(::uint32_t value) {
|
||||
;
|
||||
_impl_.type_ = value;
|
||||
}
|
||||
|
||||
// .google.protobuf.Any payload = 2;
|
||||
inline bool Message::has_payload() const {
|
||||
bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0;
|
||||
PROTOBUF_ASSUME(!value || _impl_.payload_ != nullptr);
|
||||
return value;
|
||||
}
|
||||
inline const ::google::protobuf::Any& Message::_internal_payload() const {
|
||||
const ::google::protobuf::Any* p = _impl_.payload_;
|
||||
return p != nullptr ? *p : reinterpret_cast<const ::google::protobuf::Any&>(::google::protobuf::_Any_default_instance_);
|
||||
}
|
||||
inline const ::google::protobuf::Any& Message::payload() const {
|
||||
// @@protoc_insertion_point(field_get:WhisperCom.Protobuf.Message.payload)
|
||||
return _internal_payload();
|
||||
}
|
||||
inline void Message::unsafe_arena_set_allocated_payload(::google::protobuf::Any* value) {
|
||||
if (GetArenaForAllocation() == nullptr) {
|
||||
delete reinterpret_cast<::google::protobuf::MessageLite*>(_impl_.payload_);
|
||||
}
|
||||
_impl_.payload_ = reinterpret_cast<::google::protobuf::Any*>(value);
|
||||
if (value != nullptr) {
|
||||
_impl_._has_bits_[0] |= 0x00000001u;
|
||||
} else {
|
||||
_impl_._has_bits_[0] &= ~0x00000001u;
|
||||
}
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:WhisperCom.Protobuf.Message.payload)
|
||||
}
|
||||
inline ::google::protobuf::Any* Message::release_payload() {
|
||||
|
||||
_impl_._has_bits_[0] &= ~0x00000001u;
|
||||
::google::protobuf::Any* released = _impl_.payload_;
|
||||
_impl_.payload_ = nullptr;
|
||||
#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE
|
||||
auto* old = reinterpret_cast<::google::protobuf::MessageLite*>(released);
|
||||
released = ::google::protobuf::internal::DuplicateIfNonNull(released);
|
||||
if (GetArenaForAllocation() == nullptr) {
|
||||
delete old;
|
||||
}
|
||||
#else // PROTOBUF_FORCE_COPY_IN_RELEASE
|
||||
if (GetArenaForAllocation() != nullptr) {
|
||||
released = ::google::protobuf::internal::DuplicateIfNonNull(released);
|
||||
}
|
||||
#endif // !PROTOBUF_FORCE_COPY_IN_RELEASE
|
||||
return released;
|
||||
}
|
||||
inline ::google::protobuf::Any* Message::unsafe_arena_release_payload() {
|
||||
// @@protoc_insertion_point(field_release:WhisperCom.Protobuf.Message.payload)
|
||||
|
||||
_impl_._has_bits_[0] &= ~0x00000001u;
|
||||
::google::protobuf::Any* temp = _impl_.payload_;
|
||||
_impl_.payload_ = nullptr;
|
||||
return temp;
|
||||
}
|
||||
inline ::google::protobuf::Any* Message::_internal_mutable_payload() {
|
||||
_impl_._has_bits_[0] |= 0x00000001u;
|
||||
if (_impl_.payload_ == nullptr) {
|
||||
auto* p = CreateMaybeMessage<::google::protobuf::Any>(GetArenaForAllocation());
|
||||
_impl_.payload_ = reinterpret_cast<::google::protobuf::Any*>(p);
|
||||
}
|
||||
return _impl_.payload_;
|
||||
}
|
||||
inline ::google::protobuf::Any* Message::mutable_payload() {
|
||||
::google::protobuf::Any* _msg = _internal_mutable_payload();
|
||||
// @@protoc_insertion_point(field_mutable:WhisperCom.Protobuf.Message.payload)
|
||||
return _msg;
|
||||
}
|
||||
inline void Message::set_allocated_payload(::google::protobuf::Any* value) {
|
||||
::google::protobuf::Arena* message_arena = GetArenaForAllocation();
|
||||
if (message_arena == nullptr) {
|
||||
delete reinterpret_cast<::google::protobuf::MessageLite*>(_impl_.payload_);
|
||||
}
|
||||
|
||||
if (value != nullptr) {
|
||||
::google::protobuf::Arena* submessage_arena =
|
||||
::google::protobuf::Arena::InternalGetOwningArena(reinterpret_cast<::google::protobuf::MessageLite*>(value));
|
||||
if (message_arena != submessage_arena) {
|
||||
value = ::google::protobuf::internal::GetOwnedMessage(message_arena, value, submessage_arena);
|
||||
}
|
||||
_impl_._has_bits_[0] |= 0x00000001u;
|
||||
} else {
|
||||
_impl_._has_bits_[0] &= ~0x00000001u;
|
||||
}
|
||||
|
||||
_impl_.payload_ = reinterpret_cast<::google::protobuf::Any*>(value);
|
||||
// @@protoc_insertion_point(field_set_allocated:WhisperCom.Protobuf.Message.payload)
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // __GNUC__
|
||||
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
|
||||
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
|
||||
#include "google/protobuf/port_undef.inc"
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_INCLUDED_Message_2eproto_2epb_2eh
|
8
proto/Message.proto
Normal file
8
proto/Message.proto
Normal file
@ -0,0 +1,8 @@
|
||||
syntax = "proto3";
|
||||
import "google/protobuf/any.proto";
|
||||
package WhisperCom.Protobuf;
|
||||
|
||||
message Message {
|
||||
uint32 type = 1;
|
||||
google.protobuf.Any payload = 2;
|
||||
}
|
443
proto/RouterMessage.pb.cc
Normal file
443
proto/RouterMessage.pb.cc
Normal file
@ -0,0 +1,443 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: RouterMessage.proto
|
||||
|
||||
#include "RouterMessage.pb.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "google/protobuf/io/coded_stream.h"
|
||||
#include "google/protobuf/extension_set.h"
|
||||
#include "google/protobuf/wire_format_lite.h"
|
||||
#include "google/protobuf/descriptor.h"
|
||||
#include "google/protobuf/generated_message_reflection.h"
|
||||
#include "google/protobuf/reflection_ops.h"
|
||||
#include "google/protobuf/wire_format.h"
|
||||
#include "google/protobuf/generated_message_tctable_impl.h"
|
||||
// @@protoc_insertion_point(includes)
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
PROTOBUF_PRAGMA_INIT_SEG
|
||||
namespace _pb = ::google::protobuf;
|
||||
namespace _pbi = ::google::protobuf::internal;
|
||||
namespace _fl = ::google::protobuf::internal::field_layout;
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
template <typename>
|
||||
PROTOBUF_CONSTEXPR RouterMessage::RouterMessage(::_pbi::ConstantInitialized)
|
||||
: _impl_{
|
||||
/*decltype(_impl_._has_bits_)*/ {},
|
||||
/*decltype(_impl_._cached_size_)*/ {},
|
||||
/*decltype(_impl_.topic_)*/ {
|
||||
&::_pbi::fixed_address_empty_string,
|
||||
::_pbi::ConstantInitialized{},
|
||||
},
|
||||
/*decltype(_impl_.msg_)*/ nullptr,
|
||||
/*decltype(_impl_.type_)*/ 0,
|
||||
} {}
|
||||
struct RouterMessageDefaultTypeInternal {
|
||||
PROTOBUF_CONSTEXPR RouterMessageDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
|
||||
~RouterMessageDefaultTypeInternal() {}
|
||||
union {
|
||||
RouterMessage _instance;
|
||||
};
|
||||
};
|
||||
|
||||
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
|
||||
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 RouterMessageDefaultTypeInternal _RouterMessage_default_instance_;
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
static ::_pb::Metadata file_level_metadata_RouterMessage_2eproto[1];
|
||||
static const ::_pb::EnumDescriptor* file_level_enum_descriptors_RouterMessage_2eproto[1];
|
||||
static constexpr const ::_pb::ServiceDescriptor**
|
||||
file_level_service_descriptors_RouterMessage_2eproto = nullptr;
|
||||
const ::uint32_t TableStruct_RouterMessage_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(
|
||||
protodesc_cold) = {
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::RouterMessage, _impl_._has_bits_),
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::RouterMessage, _internal_metadata_),
|
||||
~0u, // no _extensions_
|
||||
~0u, // no _oneof_case_
|
||||
~0u, // no _weak_field_map_
|
||||
~0u, // no _inlined_string_donated_
|
||||
~0u, // no _split_
|
||||
~0u, // no sizeof(Split)
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::RouterMessage, _impl_.type_),
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::RouterMessage, _impl_.msg_),
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::RouterMessage, _impl_.topic_),
|
||||
~0u,
|
||||
0,
|
||||
~0u,
|
||||
};
|
||||
|
||||
static const ::_pbi::MigrationSchema
|
||||
schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
|
||||
{0, 11, -1, sizeof(::WhisperCom::Protobuf::RouterMessage)},
|
||||
};
|
||||
|
||||
static const ::_pb::Message* const file_default_instances[] = {
|
||||
&::WhisperCom::Protobuf::_RouterMessage_default_instance_._instance,
|
||||
};
|
||||
const char descriptor_table_protodef_RouterMessage_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
|
||||
"\n\023RouterMessage.proto\022\023WhisperCom.Protob"
|
||||
"uf\032\031google/protobuf/any.proto\032\rMessage.p"
|
||||
"roto\"\177\n\rRouterMessage\0224\n\004type\030\001 \001(\0162&.Wh"
|
||||
"isperCom.Protobuf.RouterMessageType\022)\n\003m"
|
||||
"sg\030\002 \001(\0132\034.WhisperCom.Protobuf.Message\022\r"
|
||||
"\n\005topic\030\003 \001(\t*\203\001\n\021RouterMessageType\022\013\n\007U"
|
||||
"NKNOWN\020\000\022\010\n\004JOIN\020\001\022\t\n\005LEAVE\020\002\022\010\n\004DATA\020\003\022"
|
||||
"\r\n\tKEEPALIVE\020\004\022\r\n\tSUBSCRIBE\020\005\022\017\n\013UNSUBSC"
|
||||
"RIBE\020\006\022\023\n\017UNSUBSCRIBE_ALL\020\007b\006proto3"
|
||||
};
|
||||
static const ::_pbi::DescriptorTable* const descriptor_table_RouterMessage_2eproto_deps[2] =
|
||||
{
|
||||
&::descriptor_table_Message_2eproto,
|
||||
&::descriptor_table_google_2fprotobuf_2fany_2eproto,
|
||||
};
|
||||
static ::absl::once_flag descriptor_table_RouterMessage_2eproto_once;
|
||||
const ::_pbi::DescriptorTable descriptor_table_RouterMessage_2eproto = {
|
||||
false,
|
||||
false,
|
||||
355,
|
||||
descriptor_table_protodef_RouterMessage_2eproto,
|
||||
"RouterMessage.proto",
|
||||
&descriptor_table_RouterMessage_2eproto_once,
|
||||
descriptor_table_RouterMessage_2eproto_deps,
|
||||
2,
|
||||
1,
|
||||
schemas,
|
||||
file_default_instances,
|
||||
TableStruct_RouterMessage_2eproto::offsets,
|
||||
file_level_metadata_RouterMessage_2eproto,
|
||||
file_level_enum_descriptors_RouterMessage_2eproto,
|
||||
file_level_service_descriptors_RouterMessage_2eproto,
|
||||
};
|
||||
|
||||
// This function exists to be marked as weak.
|
||||
// It can significantly speed up compilation by breaking up LLVM's SCC
|
||||
// in the .pb.cc translation units. Large translation units see a
|
||||
// reduction of more than 35% of walltime for optimized builds. Without
|
||||
// the weak attribute all the messages in the file, including all the
|
||||
// vtables and everything they use become part of the same SCC through
|
||||
// a cycle like:
|
||||
// GetMetadata -> descriptor table -> default instances ->
|
||||
// vtables -> GetMetadata
|
||||
// By adding a weak function here we break the connection from the
|
||||
// individual vtables back into the descriptor table.
|
||||
PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_RouterMessage_2eproto_getter() {
|
||||
return &descriptor_table_RouterMessage_2eproto;
|
||||
}
|
||||
// Force running AddDescriptors() at dynamic initialization time.
|
||||
PROTOBUF_ATTRIBUTE_INIT_PRIORITY2
|
||||
static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_RouterMessage_2eproto(&descriptor_table_RouterMessage_2eproto);
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
const ::google::protobuf::EnumDescriptor* RouterMessageType_descriptor() {
|
||||
::google::protobuf::internal::AssignDescriptors(&descriptor_table_RouterMessage_2eproto);
|
||||
return file_level_enum_descriptors_RouterMessage_2eproto[0];
|
||||
}
|
||||
bool RouterMessageType_IsValid(int value) {
|
||||
switch (value) {
|
||||
case 0:
|
||||
case 1:
|
||||
case 2:
|
||||
case 3:
|
||||
case 4:
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// ===================================================================
|
||||
|
||||
class RouterMessage::_Internal {
|
||||
public:
|
||||
using HasBits = decltype(std::declval<RouterMessage>()._impl_._has_bits_);
|
||||
static constexpr ::int32_t kHasBitsOffset =
|
||||
8 * PROTOBUF_FIELD_OFFSET(RouterMessage, _impl_._has_bits_);
|
||||
static const ::WhisperCom::Protobuf::Message& msg(const RouterMessage* msg);
|
||||
static void set_has_msg(HasBits* has_bits) {
|
||||
(*has_bits)[0] |= 1u;
|
||||
}
|
||||
};
|
||||
|
||||
const ::WhisperCom::Protobuf::Message& RouterMessage::_Internal::msg(const RouterMessage* msg) {
|
||||
return *msg->_impl_.msg_;
|
||||
}
|
||||
void RouterMessage::clear_msg() {
|
||||
if (_impl_.msg_ != nullptr) _impl_.msg_->Clear();
|
||||
_impl_._has_bits_[0] &= ~0x00000001u;
|
||||
}
|
||||
RouterMessage::RouterMessage(::google::protobuf::Arena* arena)
|
||||
: ::google::protobuf::Message(arena) {
|
||||
SharedCtor(arena);
|
||||
// @@protoc_insertion_point(arena_constructor:WhisperCom.Protobuf.RouterMessage)
|
||||
}
|
||||
RouterMessage::RouterMessage(const RouterMessage& from) : ::google::protobuf::Message() {
|
||||
RouterMessage* const _this = this;
|
||||
(void)_this;
|
||||
new (&_impl_) Impl_{
|
||||
decltype(_impl_._has_bits_){from._impl_._has_bits_},
|
||||
/*decltype(_impl_._cached_size_)*/ {},
|
||||
decltype(_impl_.topic_){},
|
||||
decltype(_impl_.msg_){nullptr},
|
||||
decltype(_impl_.type_){},
|
||||
};
|
||||
_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(
|
||||
from._internal_metadata_);
|
||||
_impl_.topic_.InitDefault();
|
||||
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
_impl_.topic_.Set("", GetArenaForAllocation());
|
||||
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
if (!from._internal_topic().empty()) {
|
||||
_this->_impl_.topic_.Set(from._internal_topic(), _this->GetArenaForAllocation());
|
||||
}
|
||||
if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) {
|
||||
_this->_impl_.msg_ = new ::WhisperCom::Protobuf::Message(*from._impl_.msg_);
|
||||
}
|
||||
_this->_impl_.type_ = from._impl_.type_;
|
||||
|
||||
// @@protoc_insertion_point(copy_constructor:WhisperCom.Protobuf.RouterMessage)
|
||||
}
|
||||
inline void RouterMessage::SharedCtor(::_pb::Arena* arena) {
|
||||
(void)arena;
|
||||
new (&_impl_) Impl_{
|
||||
decltype(_impl_._has_bits_){},
|
||||
/*decltype(_impl_._cached_size_)*/ {},
|
||||
decltype(_impl_.topic_){},
|
||||
decltype(_impl_.msg_){nullptr},
|
||||
decltype(_impl_.type_){0},
|
||||
};
|
||||
_impl_.topic_.InitDefault();
|
||||
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
_impl_.topic_.Set("", GetArenaForAllocation());
|
||||
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
}
|
||||
RouterMessage::~RouterMessage() {
|
||||
// @@protoc_insertion_point(destructor:WhisperCom.Protobuf.RouterMessage)
|
||||
_internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>();
|
||||
SharedDtor();
|
||||
}
|
||||
inline void RouterMessage::SharedDtor() {
|
||||
ABSL_DCHECK(GetArenaForAllocation() == nullptr);
|
||||
_impl_.topic_.Destroy();
|
||||
if (this != internal_default_instance()) delete _impl_.msg_;
|
||||
}
|
||||
void RouterMessage::SetCachedSize(int size) const {
|
||||
_impl_._cached_size_.Set(size);
|
||||
}
|
||||
|
||||
PROTOBUF_NOINLINE void RouterMessage::Clear() {
|
||||
// @@protoc_insertion_point(message_clear_start:WhisperCom.Protobuf.RouterMessage)
|
||||
::uint32_t cached_has_bits = 0;
|
||||
// Prevent compiler warnings about cached_has_bits being unused
|
||||
(void) cached_has_bits;
|
||||
|
||||
_impl_.topic_.ClearToEmpty();
|
||||
cached_has_bits = _impl_._has_bits_[0];
|
||||
if (cached_has_bits & 0x00000001u) {
|
||||
ABSL_DCHECK(_impl_.msg_ != nullptr);
|
||||
_impl_.msg_->Clear();
|
||||
}
|
||||
_impl_.type_ = 0;
|
||||
_impl_._has_bits_.Clear();
|
||||
_internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
const char* RouterMessage::_InternalParse(
|
||||
const char* ptr, ::_pbi::ParseContext* ctx) {
|
||||
ptr = ::_pbi::TcParser::ParseLoop(this, ptr, ctx, &_table_.header);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1
|
||||
const ::_pbi::TcParseTable<2, 3, 1, 47, 2> RouterMessage::_table_ = {
|
||||
{
|
||||
PROTOBUF_FIELD_OFFSET(RouterMessage, _impl_._has_bits_),
|
||||
0, // no _extensions_
|
||||
3, 24, // max_field_number, fast_idx_mask
|
||||
offsetof(decltype(_table_), field_lookup_table),
|
||||
4294967288, // skipmap
|
||||
offsetof(decltype(_table_), field_entries),
|
||||
3, // num_field_entries
|
||||
1, // num_aux_entries
|
||||
offsetof(decltype(_table_), aux_entries),
|
||||
&_RouterMessage_default_instance_._instance,
|
||||
::_pbi::TcParser::GenericFallback, // fallback
|
||||
}, {{
|
||||
{::_pbi::TcParser::MiniParse, {}},
|
||||
// .WhisperCom.Protobuf.RouterMessageType type = 1;
|
||||
{::_pbi::TcParser::SingularVarintNoZag1<::uint32_t, offsetof(RouterMessage, _impl_.type_), 63>(),
|
||||
{8, 63, 0, PROTOBUF_FIELD_OFFSET(RouterMessage, _impl_.type_)}},
|
||||
// .WhisperCom.Protobuf.Message msg = 2;
|
||||
{::_pbi::TcParser::FastMtS1,
|
||||
{18, 0, 0, PROTOBUF_FIELD_OFFSET(RouterMessage, _impl_.msg_)}},
|
||||
// string topic = 3;
|
||||
{::_pbi::TcParser::FastUS1,
|
||||
{26, 63, 0, PROTOBUF_FIELD_OFFSET(RouterMessage, _impl_.topic_)}},
|
||||
}}, {{
|
||||
65535, 65535
|
||||
}}, {{
|
||||
// .WhisperCom.Protobuf.RouterMessageType type = 1;
|
||||
{PROTOBUF_FIELD_OFFSET(RouterMessage, _impl_.type_), -1, 0,
|
||||
(0 | ::_fl::kFcSingular | ::_fl::kOpenEnum)},
|
||||
// .WhisperCom.Protobuf.Message msg = 2;
|
||||
{PROTOBUF_FIELD_OFFSET(RouterMessage, _impl_.msg_), _Internal::kHasBitsOffset + 0, 0,
|
||||
(0 | ::_fl::kFcOptional | ::_fl::kMessage | ::_fl::kTvTable)},
|
||||
// string topic = 3;
|
||||
{PROTOBUF_FIELD_OFFSET(RouterMessage, _impl_.topic_), -1, 0,
|
||||
(0 | ::_fl::kFcSingular | ::_fl::kUtf8String | ::_fl::kRepAString)},
|
||||
}}, {{
|
||||
{::_pbi::TcParser::GetTable<::WhisperCom::Protobuf::Message>()},
|
||||
}}, {{
|
||||
"\41\0\0\5\0\0\0\0"
|
||||
"WhisperCom.Protobuf.RouterMessage"
|
||||
"topic"
|
||||
}},
|
||||
};
|
||||
|
||||
::uint8_t* RouterMessage::_InternalSerialize(
|
||||
::uint8_t* target,
|
||||
::google::protobuf::io::EpsCopyOutputStream* stream) const {
|
||||
// @@protoc_insertion_point(serialize_to_array_start:WhisperCom.Protobuf.RouterMessage)
|
||||
::uint32_t cached_has_bits = 0;
|
||||
(void)cached_has_bits;
|
||||
|
||||
// .WhisperCom.Protobuf.RouterMessageType type = 1;
|
||||
if (this->_internal_type() != 0) {
|
||||
target = stream->EnsureSpace(target);
|
||||
target = ::_pbi::WireFormatLite::WriteEnumToArray(
|
||||
1, this->_internal_type(), target);
|
||||
}
|
||||
|
||||
cached_has_bits = _impl_._has_bits_[0];
|
||||
// .WhisperCom.Protobuf.Message msg = 2;
|
||||
if (cached_has_bits & 0x00000001u) {
|
||||
target = ::google::protobuf::internal::WireFormatLite::
|
||||
InternalWriteMessage(2, _Internal::msg(this),
|
||||
_Internal::msg(this).GetCachedSize(), target, stream);
|
||||
}
|
||||
|
||||
// string topic = 3;
|
||||
if (!this->_internal_topic().empty()) {
|
||||
const std::string& _s = this->_internal_topic();
|
||||
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
|
||||
_s.data(), static_cast<int>(_s.length()), ::google::protobuf::internal::WireFormatLite::SERIALIZE, "WhisperCom.Protobuf.RouterMessage.topic");
|
||||
target = stream->WriteStringMaybeAliased(3, _s, target);
|
||||
}
|
||||
|
||||
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
|
||||
target =
|
||||
::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray(
|
||||
_internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream);
|
||||
}
|
||||
// @@protoc_insertion_point(serialize_to_array_end:WhisperCom.Protobuf.RouterMessage)
|
||||
return target;
|
||||
}
|
||||
|
||||
::size_t RouterMessage::ByteSizeLong() const {
|
||||
// @@protoc_insertion_point(message_byte_size_start:WhisperCom.Protobuf.RouterMessage)
|
||||
::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 topic = 3;
|
||||
if (!this->_internal_topic().empty()) {
|
||||
total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize(
|
||||
this->_internal_topic());
|
||||
}
|
||||
|
||||
// .WhisperCom.Protobuf.Message msg = 2;
|
||||
cached_has_bits = _impl_._has_bits_[0];
|
||||
if (cached_has_bits & 0x00000001u) {
|
||||
total_size += 1 +
|
||||
::google::protobuf::internal::WireFormatLite::MessageSize(
|
||||
*_impl_.msg_);
|
||||
}
|
||||
|
||||
// .WhisperCom.Protobuf.RouterMessageType type = 1;
|
||||
if (this->_internal_type() != 0) {
|
||||
total_size += 1 +
|
||||
::_pbi::WireFormatLite::EnumSize(this->_internal_type());
|
||||
}
|
||||
|
||||
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
|
||||
}
|
||||
|
||||
const ::google::protobuf::Message::ClassData RouterMessage::_class_data_ = {
|
||||
::google::protobuf::Message::CopyWithSourceCheck,
|
||||
RouterMessage::MergeImpl
|
||||
};
|
||||
const ::google::protobuf::Message::ClassData*RouterMessage::GetClassData() const { return &_class_data_; }
|
||||
|
||||
|
||||
void RouterMessage::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
|
||||
auto* const _this = static_cast<RouterMessage*>(&to_msg);
|
||||
auto& from = static_cast<const RouterMessage&>(from_msg);
|
||||
// @@protoc_insertion_point(class_specific_merge_from_start:WhisperCom.Protobuf.RouterMessage)
|
||||
ABSL_DCHECK_NE(&from, _this);
|
||||
::uint32_t cached_has_bits = 0;
|
||||
(void) cached_has_bits;
|
||||
|
||||
if (!from._internal_topic().empty()) {
|
||||
_this->_internal_set_topic(from._internal_topic());
|
||||
}
|
||||
if ((from._impl_._has_bits_[0] & 0x00000001u) != 0) {
|
||||
_this->_internal_mutable_msg()->::WhisperCom::Protobuf::Message::MergeFrom(
|
||||
from._internal_msg());
|
||||
}
|
||||
if (from._internal_type() != 0) {
|
||||
_this->_internal_set_type(from._internal_type());
|
||||
}
|
||||
_this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_);
|
||||
}
|
||||
|
||||
void RouterMessage::CopyFrom(const RouterMessage& from) {
|
||||
// @@protoc_insertion_point(class_specific_copy_from_start:WhisperCom.Protobuf.RouterMessage)
|
||||
if (&from == this) return;
|
||||
Clear();
|
||||
MergeFrom(from);
|
||||
}
|
||||
|
||||
PROTOBUF_NOINLINE bool RouterMessage::IsInitialized() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void RouterMessage::InternalSwap(RouterMessage* other) {
|
||||
using std::swap;
|
||||
auto* lhs_arena = GetArenaForAllocation();
|
||||
auto* rhs_arena = other->GetArenaForAllocation();
|
||||
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
|
||||
swap(_impl_._has_bits_[0], other->_impl_._has_bits_[0]);
|
||||
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.topic_, lhs_arena,
|
||||
&other->_impl_.topic_, rhs_arena);
|
||||
::google::protobuf::internal::memswap<
|
||||
PROTOBUF_FIELD_OFFSET(RouterMessage, _impl_.type_)
|
||||
+ sizeof(RouterMessage::_impl_.type_)
|
||||
- PROTOBUF_FIELD_OFFSET(RouterMessage, _impl_.msg_)>(
|
||||
reinterpret_cast<char*>(&_impl_.msg_),
|
||||
reinterpret_cast<char*>(&other->_impl_.msg_));
|
||||
}
|
||||
|
||||
::google::protobuf::Metadata RouterMessage::GetMetadata() const {
|
||||
return ::_pbi::AssignDescriptors(
|
||||
&descriptor_table_RouterMessage_2eproto_getter, &descriptor_table_RouterMessage_2eproto_once,
|
||||
file_level_metadata_RouterMessage_2eproto[0]);
|
||||
}
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
template<> PROTOBUF_NOINLINE ::WhisperCom::Protobuf::RouterMessage*
|
||||
Arena::CreateMaybeMessage< ::WhisperCom::Protobuf::RouterMessage >(Arena* arena) {
|
||||
return Arena::CreateMessageInternal< ::WhisperCom::Protobuf::RouterMessage >(arena);
|
||||
}
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
#include "google/protobuf/port_undef.inc"
|
505
proto/RouterMessage.pb.h
Normal file
505
proto/RouterMessage.pb.h
Normal file
@ -0,0 +1,505 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: RouterMessage.proto
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_INCLUDED_RouterMessage_2eproto_2epb_2eh
|
||||
#define GOOGLE_PROTOBUF_INCLUDED_RouterMessage_2eproto_2epb_2eh
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "google/protobuf/port_def.inc"
|
||||
#if PROTOBUF_VERSION < 4023000
|
||||
#error "This file was generated by a newer version of protoc which is"
|
||||
#error "incompatible with your Protocol Buffer headers. Please update"
|
||||
#error "your headers."
|
||||
#endif // PROTOBUF_VERSION
|
||||
|
||||
#if 4023000 < PROTOBUF_MIN_PROTOC_VERSION
|
||||
#error "This file was generated by an older version of protoc which is"
|
||||
#error "incompatible with your Protocol Buffer headers. Please"
|
||||
#error "regenerate this file with a newer version of protoc."
|
||||
#endif // PROTOBUF_MIN_PROTOC_VERSION
|
||||
#include "google/protobuf/port_undef.inc"
|
||||
#include "google/protobuf/io/coded_stream.h"
|
||||
#include "google/protobuf/arena.h"
|
||||
#include "google/protobuf/arenastring.h"
|
||||
#include "google/protobuf/generated_message_tctable_decl.h"
|
||||
#include "google/protobuf/generated_message_util.h"
|
||||
#include "google/protobuf/metadata_lite.h"
|
||||
#include "google/protobuf/generated_message_reflection.h"
|
||||
#include "google/protobuf/message.h"
|
||||
#include "google/protobuf/repeated_field.h" // IWYU pragma: export
|
||||
#include "google/protobuf/extension_set.h" // IWYU pragma: export
|
||||
#include "google/protobuf/generated_enum_reflection.h"
|
||||
#include "google/protobuf/unknown_field_set.h"
|
||||
#include "google/protobuf/any.pb.h"
|
||||
#include "Message.pb.h"
|
||||
// @@protoc_insertion_point(includes)
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
|
||||
#define PROTOBUF_INTERNAL_EXPORT_RouterMessage_2eproto
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
class AnyMetadata;
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
// Internal implementation detail -- do not use these members.
|
||||
struct TableStruct_RouterMessage_2eproto {
|
||||
static const ::uint32_t offsets[];
|
||||
};
|
||||
extern const ::google::protobuf::internal::DescriptorTable
|
||||
descriptor_table_RouterMessage_2eproto;
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
class RouterMessage;
|
||||
struct RouterMessageDefaultTypeInternal;
|
||||
extern RouterMessageDefaultTypeInternal _RouterMessage_default_instance_;
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
template <>
|
||||
::WhisperCom::Protobuf::RouterMessage* Arena::CreateMaybeMessage<::WhisperCom::Protobuf::RouterMessage>(Arena*);
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
enum RouterMessageType : int {
|
||||
UNKNOWN = 0,
|
||||
JOIN = 1,
|
||||
LEAVE = 2,
|
||||
DATA = 3,
|
||||
KEEPALIVE = 4,
|
||||
SUBSCRIBE = 5,
|
||||
UNSUBSCRIBE = 6,
|
||||
UNSUBSCRIBE_ALL = 7,
|
||||
RouterMessageType_INT_MIN_SENTINEL_DO_NOT_USE_ =
|
||||
std::numeric_limits<::int32_t>::min(),
|
||||
RouterMessageType_INT_MAX_SENTINEL_DO_NOT_USE_ =
|
||||
std::numeric_limits<::int32_t>::max(),
|
||||
};
|
||||
|
||||
bool RouterMessageType_IsValid(int value);
|
||||
constexpr RouterMessageType RouterMessageType_MIN = static_cast<RouterMessageType>(0);
|
||||
constexpr RouterMessageType RouterMessageType_MAX = static_cast<RouterMessageType>(7);
|
||||
constexpr int RouterMessageType_ARRAYSIZE = 7 + 1;
|
||||
const ::google::protobuf::EnumDescriptor*
|
||||
RouterMessageType_descriptor();
|
||||
template <typename T>
|
||||
const std::string& RouterMessageType_Name(T value) {
|
||||
static_assert(std::is_same<T, RouterMessageType>::value ||
|
||||
std::is_integral<T>::value,
|
||||
"Incorrect type passed to RouterMessageType_Name().");
|
||||
return RouterMessageType_Name(static_cast<RouterMessageType>(value));
|
||||
}
|
||||
template <>
|
||||
inline const std::string& RouterMessageType_Name(RouterMessageType value) {
|
||||
return ::google::protobuf::internal::NameOfDenseEnum<RouterMessageType_descriptor,
|
||||
0, 7>(
|
||||
static_cast<int>(value));
|
||||
}
|
||||
inline bool RouterMessageType_Parse(absl::string_view name, RouterMessageType* value) {
|
||||
return ::google::protobuf::internal::ParseNamedEnum<RouterMessageType>(
|
||||
RouterMessageType_descriptor(), name, value);
|
||||
}
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
class RouterMessage final :
|
||||
public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:WhisperCom.Protobuf.RouterMessage) */ {
|
||||
public:
|
||||
inline RouterMessage() : RouterMessage(nullptr) {}
|
||||
~RouterMessage() override;
|
||||
template<typename = void>
|
||||
explicit PROTOBUF_CONSTEXPR RouterMessage(::google::protobuf::internal::ConstantInitialized);
|
||||
|
||||
RouterMessage(const RouterMessage& from);
|
||||
RouterMessage(RouterMessage&& from) noexcept
|
||||
: RouterMessage() {
|
||||
*this = ::std::move(from);
|
||||
}
|
||||
|
||||
inline RouterMessage& operator=(const RouterMessage& from) {
|
||||
CopyFrom(from);
|
||||
return *this;
|
||||
}
|
||||
inline RouterMessage& operator=(RouterMessage&& from) noexcept {
|
||||
if (this == &from) return *this;
|
||||
if (GetOwningArena() == from.GetOwningArena()
|
||||
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
|
||||
&& GetOwningArena() != nullptr
|
||||
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
|
||||
) {
|
||||
InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
|
||||
return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance);
|
||||
}
|
||||
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
|
||||
return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
static const ::google::protobuf::Descriptor* descriptor() {
|
||||
return GetDescriptor();
|
||||
}
|
||||
static const ::google::protobuf::Descriptor* GetDescriptor() {
|
||||
return default_instance().GetMetadata().descriptor;
|
||||
}
|
||||
static const ::google::protobuf::Reflection* GetReflection() {
|
||||
return default_instance().GetMetadata().reflection;
|
||||
}
|
||||
static const RouterMessage& default_instance() {
|
||||
return *internal_default_instance();
|
||||
}
|
||||
static inline const RouterMessage* internal_default_instance() {
|
||||
return reinterpret_cast<const RouterMessage*>(
|
||||
&_RouterMessage_default_instance_);
|
||||
}
|
||||
static constexpr int kIndexInFileMessages =
|
||||
0;
|
||||
|
||||
friend void swap(RouterMessage& a, RouterMessage& b) {
|
||||
a.Swap(&b);
|
||||
}
|
||||
inline void Swap(RouterMessage* 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 {
|
||||
::google::protobuf::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(RouterMessage* other) {
|
||||
if (other == this) return;
|
||||
ABSL_DCHECK(GetOwningArena() == other->GetOwningArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
// implements Message ----------------------------------------------
|
||||
|
||||
RouterMessage* New(::google::protobuf::Arena* arena = nullptr) const final {
|
||||
return CreateMaybeMessage<RouterMessage>(arena);
|
||||
}
|
||||
using ::google::protobuf::Message::CopyFrom;
|
||||
void CopyFrom(const RouterMessage& from);
|
||||
using ::google::protobuf::Message::MergeFrom;
|
||||
void MergeFrom( const RouterMessage& from) {
|
||||
RouterMessage::MergeImpl(*this, from);
|
||||
}
|
||||
private:
|
||||
static void MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg);
|
||||
public:
|
||||
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final;
|
||||
bool IsInitialized() const final;
|
||||
|
||||
::size_t ByteSizeLong() const final;
|
||||
const char* _InternalParse(const char* ptr, ::google::protobuf::internal::ParseContext* ctx) final;
|
||||
::uint8_t* _InternalSerialize(
|
||||
::uint8_t* target, ::google::protobuf::io::EpsCopyOutputStream* stream) const final;
|
||||
int GetCachedSize() const final { return _impl_._cached_size_.Get(); }
|
||||
|
||||
private:
|
||||
void SharedCtor(::google::protobuf::Arena* arena);
|
||||
void SharedDtor();
|
||||
void SetCachedSize(int size) const final;
|
||||
void InternalSwap(RouterMessage* other);
|
||||
|
||||
private:
|
||||
friend class ::google::protobuf::internal::AnyMetadata;
|
||||
static ::absl::string_view FullMessageName() {
|
||||
return "WhisperCom.Protobuf.RouterMessage";
|
||||
}
|
||||
protected:
|
||||
explicit RouterMessage(::google::protobuf::Arena* arena);
|
||||
public:
|
||||
|
||||
static const ClassData _class_data_;
|
||||
const ::google::protobuf::Message::ClassData*GetClassData() const final;
|
||||
|
||||
::google::protobuf::Metadata GetMetadata() const final;
|
||||
|
||||
// nested types ----------------------------------------------------
|
||||
|
||||
// accessors -------------------------------------------------------
|
||||
|
||||
enum : int {
|
||||
kTopicFieldNumber = 3,
|
||||
kMsgFieldNumber = 2,
|
||||
kTypeFieldNumber = 1,
|
||||
};
|
||||
// string topic = 3;
|
||||
void clear_topic() ;
|
||||
const std::string& topic() const;
|
||||
template <typename Arg_ = const std::string&, typename... Args_>
|
||||
void set_topic(Arg_&& arg, Args_... args);
|
||||
std::string* mutable_topic();
|
||||
PROTOBUF_NODISCARD std::string* release_topic();
|
||||
void set_allocated_topic(std::string* ptr);
|
||||
|
||||
private:
|
||||
const std::string& _internal_topic() const;
|
||||
inline PROTOBUF_ALWAYS_INLINE void _internal_set_topic(
|
||||
const std::string& value);
|
||||
std::string* _internal_mutable_topic();
|
||||
|
||||
public:
|
||||
// .WhisperCom.Protobuf.Message msg = 2;
|
||||
bool has_msg() const;
|
||||
void clear_msg() ;
|
||||
const ::WhisperCom::Protobuf::Message& msg() const;
|
||||
PROTOBUF_NODISCARD ::WhisperCom::Protobuf::Message* release_msg();
|
||||
::WhisperCom::Protobuf::Message* mutable_msg();
|
||||
void set_allocated_msg(::WhisperCom::Protobuf::Message* value);
|
||||
void unsafe_arena_set_allocated_msg(::WhisperCom::Protobuf::Message* value);
|
||||
::WhisperCom::Protobuf::Message* unsafe_arena_release_msg();
|
||||
|
||||
private:
|
||||
const ::WhisperCom::Protobuf::Message& _internal_msg() const;
|
||||
::WhisperCom::Protobuf::Message* _internal_mutable_msg();
|
||||
|
||||
public:
|
||||
// .WhisperCom.Protobuf.RouterMessageType type = 1;
|
||||
void clear_type() ;
|
||||
::WhisperCom::Protobuf::RouterMessageType type() const;
|
||||
void set_type(::WhisperCom::Protobuf::RouterMessageType value);
|
||||
|
||||
private:
|
||||
::WhisperCom::Protobuf::RouterMessageType _internal_type() const;
|
||||
void _internal_set_type(::WhisperCom::Protobuf::RouterMessageType value);
|
||||
|
||||
public:
|
||||
// @@protoc_insertion_point(class_scope:WhisperCom.Protobuf.RouterMessage)
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
friend class ::google::protobuf::internal::TcParser;
|
||||
static const ::google::protobuf::internal::TcParseTable<2, 3, 1, 47, 2> _table_;
|
||||
template <typename T> friend class ::google::protobuf::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
struct Impl_ {
|
||||
::google::protobuf::internal::HasBits<1> _has_bits_;
|
||||
mutable ::google::protobuf::internal::CachedSize _cached_size_;
|
||||
::google::protobuf::internal::ArenaStringPtr topic_;
|
||||
::WhisperCom::Protobuf::Message* msg_;
|
||||
int type_;
|
||||
};
|
||||
union { Impl_ _impl_; };
|
||||
friend struct ::TableStruct_RouterMessage_2eproto;
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif // __GNUC__
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// RouterMessage
|
||||
|
||||
// .WhisperCom.Protobuf.RouterMessageType type = 1;
|
||||
inline void RouterMessage::clear_type() {
|
||||
_impl_.type_ = 0;
|
||||
}
|
||||
inline ::WhisperCom::Protobuf::RouterMessageType RouterMessage::type() const {
|
||||
// @@protoc_insertion_point(field_get:WhisperCom.Protobuf.RouterMessage.type)
|
||||
return _internal_type();
|
||||
}
|
||||
inline void RouterMessage::set_type(::WhisperCom::Protobuf::RouterMessageType value) {
|
||||
_internal_set_type(value);
|
||||
// @@protoc_insertion_point(field_set:WhisperCom.Protobuf.RouterMessage.type)
|
||||
}
|
||||
inline ::WhisperCom::Protobuf::RouterMessageType RouterMessage::_internal_type() const {
|
||||
return static_cast<::WhisperCom::Protobuf::RouterMessageType>(_impl_.type_);
|
||||
}
|
||||
inline void RouterMessage::_internal_set_type(::WhisperCom::Protobuf::RouterMessageType value) {
|
||||
;
|
||||
_impl_.type_ = value;
|
||||
}
|
||||
|
||||
// .WhisperCom.Protobuf.Message msg = 2;
|
||||
inline bool RouterMessage::has_msg() const {
|
||||
bool value = (_impl_._has_bits_[0] & 0x00000001u) != 0;
|
||||
PROTOBUF_ASSUME(!value || _impl_.msg_ != nullptr);
|
||||
return value;
|
||||
}
|
||||
inline const ::WhisperCom::Protobuf::Message& RouterMessage::_internal_msg() const {
|
||||
const ::WhisperCom::Protobuf::Message* p = _impl_.msg_;
|
||||
return p != nullptr ? *p : reinterpret_cast<const ::WhisperCom::Protobuf::Message&>(::WhisperCom::Protobuf::_Message_default_instance_);
|
||||
}
|
||||
inline const ::WhisperCom::Protobuf::Message& RouterMessage::msg() const {
|
||||
// @@protoc_insertion_point(field_get:WhisperCom.Protobuf.RouterMessage.msg)
|
||||
return _internal_msg();
|
||||
}
|
||||
inline void RouterMessage::unsafe_arena_set_allocated_msg(::WhisperCom::Protobuf::Message* value) {
|
||||
if (GetArenaForAllocation() == nullptr) {
|
||||
delete reinterpret_cast<::google::protobuf::MessageLite*>(_impl_.msg_);
|
||||
}
|
||||
_impl_.msg_ = reinterpret_cast<::WhisperCom::Protobuf::Message*>(value);
|
||||
if (value != nullptr) {
|
||||
_impl_._has_bits_[0] |= 0x00000001u;
|
||||
} else {
|
||||
_impl_._has_bits_[0] &= ~0x00000001u;
|
||||
}
|
||||
// @@protoc_insertion_point(field_unsafe_arena_set_allocated:WhisperCom.Protobuf.RouterMessage.msg)
|
||||
}
|
||||
inline ::WhisperCom::Protobuf::Message* RouterMessage::release_msg() {
|
||||
|
||||
_impl_._has_bits_[0] &= ~0x00000001u;
|
||||
::WhisperCom::Protobuf::Message* released = _impl_.msg_;
|
||||
_impl_.msg_ = nullptr;
|
||||
#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE
|
||||
auto* old = reinterpret_cast<::google::protobuf::MessageLite*>(released);
|
||||
released = ::google::protobuf::internal::DuplicateIfNonNull(released);
|
||||
if (GetArenaForAllocation() == nullptr) {
|
||||
delete old;
|
||||
}
|
||||
#else // PROTOBUF_FORCE_COPY_IN_RELEASE
|
||||
if (GetArenaForAllocation() != nullptr) {
|
||||
released = ::google::protobuf::internal::DuplicateIfNonNull(released);
|
||||
}
|
||||
#endif // !PROTOBUF_FORCE_COPY_IN_RELEASE
|
||||
return released;
|
||||
}
|
||||
inline ::WhisperCom::Protobuf::Message* RouterMessage::unsafe_arena_release_msg() {
|
||||
// @@protoc_insertion_point(field_release:WhisperCom.Protobuf.RouterMessage.msg)
|
||||
|
||||
_impl_._has_bits_[0] &= ~0x00000001u;
|
||||
::WhisperCom::Protobuf::Message* temp = _impl_.msg_;
|
||||
_impl_.msg_ = nullptr;
|
||||
return temp;
|
||||
}
|
||||
inline ::WhisperCom::Protobuf::Message* RouterMessage::_internal_mutable_msg() {
|
||||
_impl_._has_bits_[0] |= 0x00000001u;
|
||||
if (_impl_.msg_ == nullptr) {
|
||||
auto* p = CreateMaybeMessage<::WhisperCom::Protobuf::Message>(GetArenaForAllocation());
|
||||
_impl_.msg_ = reinterpret_cast<::WhisperCom::Protobuf::Message*>(p);
|
||||
}
|
||||
return _impl_.msg_;
|
||||
}
|
||||
inline ::WhisperCom::Protobuf::Message* RouterMessage::mutable_msg() {
|
||||
::WhisperCom::Protobuf::Message* _msg = _internal_mutable_msg();
|
||||
// @@protoc_insertion_point(field_mutable:WhisperCom.Protobuf.RouterMessage.msg)
|
||||
return _msg;
|
||||
}
|
||||
inline void RouterMessage::set_allocated_msg(::WhisperCom::Protobuf::Message* value) {
|
||||
::google::protobuf::Arena* message_arena = GetArenaForAllocation();
|
||||
if (message_arena == nullptr) {
|
||||
delete reinterpret_cast<::google::protobuf::MessageLite*>(_impl_.msg_);
|
||||
}
|
||||
|
||||
if (value != nullptr) {
|
||||
::google::protobuf::Arena* submessage_arena =
|
||||
::google::protobuf::Arena::InternalGetOwningArena(reinterpret_cast<::google::protobuf::MessageLite*>(value));
|
||||
if (message_arena != submessage_arena) {
|
||||
value = ::google::protobuf::internal::GetOwnedMessage(message_arena, value, submessage_arena);
|
||||
}
|
||||
_impl_._has_bits_[0] |= 0x00000001u;
|
||||
} else {
|
||||
_impl_._has_bits_[0] &= ~0x00000001u;
|
||||
}
|
||||
|
||||
_impl_.msg_ = reinterpret_cast<::WhisperCom::Protobuf::Message*>(value);
|
||||
// @@protoc_insertion_point(field_set_allocated:WhisperCom.Protobuf.RouterMessage.msg)
|
||||
}
|
||||
|
||||
// string topic = 3;
|
||||
inline void RouterMessage::clear_topic() {
|
||||
_impl_.topic_.ClearToEmpty();
|
||||
}
|
||||
inline const std::string& RouterMessage::topic() const {
|
||||
// @@protoc_insertion_point(field_get:WhisperCom.Protobuf.RouterMessage.topic)
|
||||
return _internal_topic();
|
||||
}
|
||||
template <typename Arg_, typename... Args_>
|
||||
inline PROTOBUF_ALWAYS_INLINE void RouterMessage::set_topic(Arg_&& arg,
|
||||
Args_... args) {
|
||||
;
|
||||
_impl_.topic_.Set(static_cast<Arg_&&>(arg), args..., GetArenaForAllocation());
|
||||
// @@protoc_insertion_point(field_set:WhisperCom.Protobuf.RouterMessage.topic)
|
||||
}
|
||||
inline std::string* RouterMessage::mutable_topic() {
|
||||
std::string* _s = _internal_mutable_topic();
|
||||
// @@protoc_insertion_point(field_mutable:WhisperCom.Protobuf.RouterMessage.topic)
|
||||
return _s;
|
||||
}
|
||||
inline const std::string& RouterMessage::_internal_topic() const {
|
||||
return _impl_.topic_.Get();
|
||||
}
|
||||
inline void RouterMessage::_internal_set_topic(const std::string& value) {
|
||||
;
|
||||
_impl_.topic_.Set(value, GetArenaForAllocation());
|
||||
}
|
||||
inline std::string* RouterMessage::_internal_mutable_topic() {
|
||||
;
|
||||
return _impl_.topic_.Mutable( GetArenaForAllocation());
|
||||
}
|
||||
inline std::string* RouterMessage::release_topic() {
|
||||
// @@protoc_insertion_point(field_release:WhisperCom.Protobuf.RouterMessage.topic)
|
||||
return _impl_.topic_.Release();
|
||||
}
|
||||
inline void RouterMessage::set_allocated_topic(std::string* value) {
|
||||
_impl_.topic_.SetAllocated(value, GetArenaForAllocation());
|
||||
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
if (_impl_.topic_.IsDefault()) {
|
||||
_impl_.topic_.Set("", GetArenaForAllocation());
|
||||
}
|
||||
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
// @@protoc_insertion_point(field_set_allocated:WhisperCom.Protobuf.RouterMessage.topic)
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // __GNUC__
|
||||
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
|
||||
template <>
|
||||
struct is_proto_enum<::WhisperCom::Protobuf::RouterMessageType> : std::true_type {};
|
||||
template <>
|
||||
inline const EnumDescriptor* GetEnumDescriptor<::WhisperCom::Protobuf::RouterMessageType>() {
|
||||
return ::WhisperCom::Protobuf::RouterMessageType_descriptor();
|
||||
}
|
||||
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
|
||||
#include "google/protobuf/port_undef.inc"
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_INCLUDED_RouterMessage_2eproto_2epb_2eh
|
23
proto/RouterMessage.proto
Normal file
23
proto/RouterMessage.proto
Normal file
@ -0,0 +1,23 @@
|
||||
syntax = "proto3";
|
||||
import "google/protobuf/any.proto";
|
||||
import "Message.proto";
|
||||
|
||||
package WhisperCom.Protobuf;
|
||||
|
||||
enum RouterMessageType
|
||||
{
|
||||
UNKNOWN = 0;
|
||||
JOIN = 1;
|
||||
LEAVE = 2;
|
||||
DATA = 3;
|
||||
KEEPALIVE = 4;
|
||||
SUBSCRIBE = 5;
|
||||
UNSUBSCRIBE = 6;
|
||||
UNSUBSCRIBE_ALL = 7;
|
||||
}
|
||||
|
||||
message RouterMessage {
|
||||
RouterMessageType type = 1;
|
||||
Message msg = 2;
|
||||
string topic = 3;
|
||||
}
|
317
proto/TestMessage.pb.cc
Normal file
317
proto/TestMessage.pb.cc
Normal file
@ -0,0 +1,317 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: TestMessage.proto
|
||||
|
||||
#include "TestMessage.pb.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include "google/protobuf/io/coded_stream.h"
|
||||
#include "google/protobuf/extension_set.h"
|
||||
#include "google/protobuf/wire_format_lite.h"
|
||||
#include "google/protobuf/descriptor.h"
|
||||
#include "google/protobuf/generated_message_reflection.h"
|
||||
#include "google/protobuf/reflection_ops.h"
|
||||
#include "google/protobuf/wire_format.h"
|
||||
#include "google/protobuf/generated_message_tctable_impl.h"
|
||||
// @@protoc_insertion_point(includes)
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
PROTOBUF_PRAGMA_INIT_SEG
|
||||
namespace _pb = ::google::protobuf;
|
||||
namespace _pbi = ::google::protobuf::internal;
|
||||
namespace _fl = ::google::protobuf::internal::field_layout;
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
template <typename>
|
||||
PROTOBUF_CONSTEXPR TestMessage::TestMessage(::_pbi::ConstantInitialized)
|
||||
: _impl_{
|
||||
/*decltype(_impl_.str_)*/ {
|
||||
&::_pbi::fixed_address_empty_string,
|
||||
::_pbi::ConstantInitialized{},
|
||||
},
|
||||
/*decltype(_impl_._cached_size_)*/ {},
|
||||
} {}
|
||||
struct TestMessageDefaultTypeInternal {
|
||||
PROTOBUF_CONSTEXPR TestMessageDefaultTypeInternal() : _instance(::_pbi::ConstantInitialized{}) {}
|
||||
~TestMessageDefaultTypeInternal() {}
|
||||
union {
|
||||
TestMessage _instance;
|
||||
};
|
||||
};
|
||||
|
||||
PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
|
||||
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 TestMessageDefaultTypeInternal _TestMessage_default_instance_;
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
static ::_pb::Metadata file_level_metadata_TestMessage_2eproto[1];
|
||||
static constexpr const ::_pb::EnumDescriptor**
|
||||
file_level_enum_descriptors_TestMessage_2eproto = nullptr;
|
||||
static constexpr const ::_pb::ServiceDescriptor**
|
||||
file_level_service_descriptors_TestMessage_2eproto = nullptr;
|
||||
const ::uint32_t TableStruct_TestMessage_2eproto::offsets[] PROTOBUF_SECTION_VARIABLE(
|
||||
protodesc_cold) = {
|
||||
~0u, // no _has_bits_
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::TestMessage, _internal_metadata_),
|
||||
~0u, // no _extensions_
|
||||
~0u, // no _oneof_case_
|
||||
~0u, // no _weak_field_map_
|
||||
~0u, // no _inlined_string_donated_
|
||||
~0u, // no _split_
|
||||
~0u, // no sizeof(Split)
|
||||
PROTOBUF_FIELD_OFFSET(::WhisperCom::Protobuf::TestMessage, _impl_.str_),
|
||||
};
|
||||
|
||||
static const ::_pbi::MigrationSchema
|
||||
schemas[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
|
||||
{0, -1, -1, sizeof(::WhisperCom::Protobuf::TestMessage)},
|
||||
};
|
||||
|
||||
static const ::_pb::Message* const file_default_instances[] = {
|
||||
&::WhisperCom::Protobuf::_TestMessage_default_instance_._instance,
|
||||
};
|
||||
const char descriptor_table_protodef_TestMessage_2eproto[] PROTOBUF_SECTION_VARIABLE(protodesc_cold) = {
|
||||
"\n\021TestMessage.proto\022\023WhisperCom.Protobuf"
|
||||
"\"\032\n\013TestMessage\022\013\n\003str\030\001 \001(\tb\006proto3"
|
||||
};
|
||||
static ::absl::once_flag descriptor_table_TestMessage_2eproto_once;
|
||||
const ::_pbi::DescriptorTable descriptor_table_TestMessage_2eproto = {
|
||||
false,
|
||||
false,
|
||||
76,
|
||||
descriptor_table_protodef_TestMessage_2eproto,
|
||||
"TestMessage.proto",
|
||||
&descriptor_table_TestMessage_2eproto_once,
|
||||
nullptr,
|
||||
0,
|
||||
1,
|
||||
schemas,
|
||||
file_default_instances,
|
||||
TableStruct_TestMessage_2eproto::offsets,
|
||||
file_level_metadata_TestMessage_2eproto,
|
||||
file_level_enum_descriptors_TestMessage_2eproto,
|
||||
file_level_service_descriptors_TestMessage_2eproto,
|
||||
};
|
||||
|
||||
// This function exists to be marked as weak.
|
||||
// It can significantly speed up compilation by breaking up LLVM's SCC
|
||||
// in the .pb.cc translation units. Large translation units see a
|
||||
// reduction of more than 35% of walltime for optimized builds. Without
|
||||
// the weak attribute all the messages in the file, including all the
|
||||
// vtables and everything they use become part of the same SCC through
|
||||
// a cycle like:
|
||||
// GetMetadata -> descriptor table -> default instances ->
|
||||
// vtables -> GetMetadata
|
||||
// By adding a weak function here we break the connection from the
|
||||
// individual vtables back into the descriptor table.
|
||||
PROTOBUF_ATTRIBUTE_WEAK const ::_pbi::DescriptorTable* descriptor_table_TestMessage_2eproto_getter() {
|
||||
return &descriptor_table_TestMessage_2eproto;
|
||||
}
|
||||
// Force running AddDescriptors() at dynamic initialization time.
|
||||
PROTOBUF_ATTRIBUTE_INIT_PRIORITY2
|
||||
static ::_pbi::AddDescriptorsRunner dynamic_init_dummy_TestMessage_2eproto(&descriptor_table_TestMessage_2eproto);
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
// ===================================================================
|
||||
|
||||
class TestMessage::_Internal {
|
||||
public:
|
||||
};
|
||||
|
||||
TestMessage::TestMessage(::google::protobuf::Arena* arena)
|
||||
: ::google::protobuf::Message(arena) {
|
||||
SharedCtor(arena);
|
||||
// @@protoc_insertion_point(arena_constructor:WhisperCom.Protobuf.TestMessage)
|
||||
}
|
||||
TestMessage::TestMessage(const TestMessage& from) : ::google::protobuf::Message() {
|
||||
TestMessage* const _this = this;
|
||||
(void)_this;
|
||||
new (&_impl_) Impl_{
|
||||
decltype(_impl_.str_){},
|
||||
/*decltype(_impl_._cached_size_)*/ {},
|
||||
};
|
||||
_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(
|
||||
from._internal_metadata_);
|
||||
_impl_.str_.InitDefault();
|
||||
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
_impl_.str_.Set("", GetArenaForAllocation());
|
||||
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
if (!from._internal_str().empty()) {
|
||||
_this->_impl_.str_.Set(from._internal_str(), _this->GetArenaForAllocation());
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(copy_constructor:WhisperCom.Protobuf.TestMessage)
|
||||
}
|
||||
inline void TestMessage::SharedCtor(::_pb::Arena* arena) {
|
||||
(void)arena;
|
||||
new (&_impl_) Impl_{
|
||||
decltype(_impl_.str_){},
|
||||
/*decltype(_impl_._cached_size_)*/ {},
|
||||
};
|
||||
_impl_.str_.InitDefault();
|
||||
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
_impl_.str_.Set("", GetArenaForAllocation());
|
||||
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
}
|
||||
TestMessage::~TestMessage() {
|
||||
// @@protoc_insertion_point(destructor:WhisperCom.Protobuf.TestMessage)
|
||||
_internal_metadata_.Delete<::google::protobuf::UnknownFieldSet>();
|
||||
SharedDtor();
|
||||
}
|
||||
inline void TestMessage::SharedDtor() {
|
||||
ABSL_DCHECK(GetArenaForAllocation() == nullptr);
|
||||
_impl_.str_.Destroy();
|
||||
}
|
||||
void TestMessage::SetCachedSize(int size) const {
|
||||
_impl_._cached_size_.Set(size);
|
||||
}
|
||||
|
||||
PROTOBUF_NOINLINE void TestMessage::Clear() {
|
||||
// @@protoc_insertion_point(message_clear_start:WhisperCom.Protobuf.TestMessage)
|
||||
::uint32_t cached_has_bits = 0;
|
||||
// Prevent compiler warnings about cached_has_bits being unused
|
||||
(void) cached_has_bits;
|
||||
|
||||
_impl_.str_.ClearToEmpty();
|
||||
_internal_metadata_.Clear<::google::protobuf::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
const char* TestMessage::_InternalParse(
|
||||
const char* ptr, ::_pbi::ParseContext* ctx) {
|
||||
ptr = ::_pbi::TcParser::ParseLoop(this, ptr, ctx, &_table_.header);
|
||||
return ptr;
|
||||
}
|
||||
|
||||
|
||||
PROTOBUF_CONSTINIT PROTOBUF_ATTRIBUTE_INIT_PRIORITY1
|
||||
const ::_pbi::TcParseTable<0, 1, 0, 43, 2> TestMessage::_table_ = {
|
||||
{
|
||||
0, // no _has_bits_
|
||||
0, // no _extensions_
|
||||
1, 0, // max_field_number, fast_idx_mask
|
||||
offsetof(decltype(_table_), field_lookup_table),
|
||||
4294967294, // skipmap
|
||||
offsetof(decltype(_table_), field_entries),
|
||||
1, // num_field_entries
|
||||
0, // num_aux_entries
|
||||
offsetof(decltype(_table_), field_names), // no aux_entries
|
||||
&_TestMessage_default_instance_._instance,
|
||||
::_pbi::TcParser::GenericFallback, // fallback
|
||||
}, {{
|
||||
// string str = 1;
|
||||
{::_pbi::TcParser::FastUS1,
|
||||
{10, 63, 0, PROTOBUF_FIELD_OFFSET(TestMessage, _impl_.str_)}},
|
||||
}}, {{
|
||||
65535, 65535
|
||||
}}, {{
|
||||
// string str = 1;
|
||||
{PROTOBUF_FIELD_OFFSET(TestMessage, _impl_.str_), 0, 0,
|
||||
(0 | ::_fl::kFcSingular | ::_fl::kUtf8String | ::_fl::kRepAString)},
|
||||
}},
|
||||
// no aux_entries
|
||||
{{
|
||||
"\37\3\0\0\0\0\0\0"
|
||||
"WhisperCom.Protobuf.TestMessage"
|
||||
"str"
|
||||
}},
|
||||
};
|
||||
|
||||
::uint8_t* TestMessage::_InternalSerialize(
|
||||
::uint8_t* target,
|
||||
::google::protobuf::io::EpsCopyOutputStream* stream) const {
|
||||
// @@protoc_insertion_point(serialize_to_array_start:WhisperCom.Protobuf.TestMessage)
|
||||
::uint32_t cached_has_bits = 0;
|
||||
(void)cached_has_bits;
|
||||
|
||||
// string str = 1;
|
||||
if (!this->_internal_str().empty()) {
|
||||
const std::string& _s = this->_internal_str();
|
||||
::google::protobuf::internal::WireFormatLite::VerifyUtf8String(
|
||||
_s.data(), static_cast<int>(_s.length()), ::google::protobuf::internal::WireFormatLite::SERIALIZE, "WhisperCom.Protobuf.TestMessage.str");
|
||||
target = stream->WriteStringMaybeAliased(1, _s, target);
|
||||
}
|
||||
|
||||
if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) {
|
||||
target =
|
||||
::_pbi::WireFormat::InternalSerializeUnknownFieldsToArray(
|
||||
_internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance), target, stream);
|
||||
}
|
||||
// @@protoc_insertion_point(serialize_to_array_end:WhisperCom.Protobuf.TestMessage)
|
||||
return target;
|
||||
}
|
||||
|
||||
::size_t TestMessage::ByteSizeLong() const {
|
||||
// @@protoc_insertion_point(message_byte_size_start:WhisperCom.Protobuf.TestMessage)
|
||||
::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 str = 1;
|
||||
if (!this->_internal_str().empty()) {
|
||||
total_size += 1 + ::google::protobuf::internal::WireFormatLite::StringSize(
|
||||
this->_internal_str());
|
||||
}
|
||||
|
||||
return MaybeComputeUnknownFieldsSize(total_size, &_impl_._cached_size_);
|
||||
}
|
||||
|
||||
const ::google::protobuf::Message::ClassData TestMessage::_class_data_ = {
|
||||
::google::protobuf::Message::CopyWithSourceCheck,
|
||||
TestMessage::MergeImpl
|
||||
};
|
||||
const ::google::protobuf::Message::ClassData*TestMessage::GetClassData() const { return &_class_data_; }
|
||||
|
||||
|
||||
void TestMessage::MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg) {
|
||||
auto* const _this = static_cast<TestMessage*>(&to_msg);
|
||||
auto& from = static_cast<const TestMessage&>(from_msg);
|
||||
// @@protoc_insertion_point(class_specific_merge_from_start:WhisperCom.Protobuf.TestMessage)
|
||||
ABSL_DCHECK_NE(&from, _this);
|
||||
::uint32_t cached_has_bits = 0;
|
||||
(void) cached_has_bits;
|
||||
|
||||
if (!from._internal_str().empty()) {
|
||||
_this->_internal_set_str(from._internal_str());
|
||||
}
|
||||
_this->_internal_metadata_.MergeFrom<::google::protobuf::UnknownFieldSet>(from._internal_metadata_);
|
||||
}
|
||||
|
||||
void TestMessage::CopyFrom(const TestMessage& from) {
|
||||
// @@protoc_insertion_point(class_specific_copy_from_start:WhisperCom.Protobuf.TestMessage)
|
||||
if (&from == this) return;
|
||||
Clear();
|
||||
MergeFrom(from);
|
||||
}
|
||||
|
||||
PROTOBUF_NOINLINE bool TestMessage::IsInitialized() const {
|
||||
return true;
|
||||
}
|
||||
|
||||
void TestMessage::InternalSwap(TestMessage* other) {
|
||||
using std::swap;
|
||||
auto* lhs_arena = GetArenaForAllocation();
|
||||
auto* rhs_arena = other->GetArenaForAllocation();
|
||||
_internal_metadata_.InternalSwap(&other->_internal_metadata_);
|
||||
::_pbi::ArenaStringPtr::InternalSwap(&_impl_.str_, lhs_arena,
|
||||
&other->_impl_.str_, rhs_arena);
|
||||
}
|
||||
|
||||
::google::protobuf::Metadata TestMessage::GetMetadata() const {
|
||||
return ::_pbi::AssignDescriptors(
|
||||
&descriptor_table_TestMessage_2eproto_getter, &descriptor_table_TestMessage_2eproto_once,
|
||||
file_level_metadata_TestMessage_2eproto[0]);
|
||||
}
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
template<> PROTOBUF_NOINLINE ::WhisperCom::Protobuf::TestMessage*
|
||||
Arena::CreateMaybeMessage< ::WhisperCom::Protobuf::TestMessage >(Arena* arena) {
|
||||
return Arena::CreateMessageInternal< ::WhisperCom::Protobuf::TestMessage >(arena);
|
||||
}
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
#include "google/protobuf/port_undef.inc"
|
315
proto/TestMessage.pb.h
Normal file
315
proto/TestMessage.pb.h
Normal file
@ -0,0 +1,315 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: TestMessage.proto
|
||||
|
||||
#ifndef GOOGLE_PROTOBUF_INCLUDED_TestMessage_2eproto_2epb_2eh
|
||||
#define GOOGLE_PROTOBUF_INCLUDED_TestMessage_2eproto_2epb_2eh
|
||||
|
||||
#include <limits>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
#include "google/protobuf/port_def.inc"
|
||||
#if PROTOBUF_VERSION < 4023000
|
||||
#error "This file was generated by a newer version of protoc which is"
|
||||
#error "incompatible with your Protocol Buffer headers. Please update"
|
||||
#error "your headers."
|
||||
#endif // PROTOBUF_VERSION
|
||||
|
||||
#if 4023000 < PROTOBUF_MIN_PROTOC_VERSION
|
||||
#error "This file was generated by an older version of protoc which is"
|
||||
#error "incompatible with your Protocol Buffer headers. Please"
|
||||
#error "regenerate this file with a newer version of protoc."
|
||||
#endif // PROTOBUF_MIN_PROTOC_VERSION
|
||||
#include "google/protobuf/port_undef.inc"
|
||||
#include "google/protobuf/io/coded_stream.h"
|
||||
#include "google/protobuf/arena.h"
|
||||
#include "google/protobuf/arenastring.h"
|
||||
#include "google/protobuf/generated_message_tctable_decl.h"
|
||||
#include "google/protobuf/generated_message_util.h"
|
||||
#include "google/protobuf/metadata_lite.h"
|
||||
#include "google/protobuf/generated_message_reflection.h"
|
||||
#include "google/protobuf/message.h"
|
||||
#include "google/protobuf/repeated_field.h" // IWYU pragma: export
|
||||
#include "google/protobuf/extension_set.h" // IWYU pragma: export
|
||||
#include "google/protobuf/unknown_field_set.h"
|
||||
// @@protoc_insertion_point(includes)
|
||||
|
||||
// Must be included last.
|
||||
#include "google/protobuf/port_def.inc"
|
||||
|
||||
#define PROTOBUF_INTERNAL_EXPORT_TestMessage_2eproto
|
||||
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
namespace internal {
|
||||
class AnyMetadata;
|
||||
} // namespace internal
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
// Internal implementation detail -- do not use these members.
|
||||
struct TableStruct_TestMessage_2eproto {
|
||||
static const ::uint32_t offsets[];
|
||||
};
|
||||
extern const ::google::protobuf::internal::DescriptorTable
|
||||
descriptor_table_TestMessage_2eproto;
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
class TestMessage;
|
||||
struct TestMessageDefaultTypeInternal;
|
||||
extern TestMessageDefaultTypeInternal _TestMessage_default_instance_;
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
namespace google {
|
||||
namespace protobuf {
|
||||
template <>
|
||||
::WhisperCom::Protobuf::TestMessage* Arena::CreateMaybeMessage<::WhisperCom::Protobuf::TestMessage>(Arena*);
|
||||
} // namespace protobuf
|
||||
} // namespace google
|
||||
|
||||
namespace WhisperCom {
|
||||
namespace Protobuf {
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
class TestMessage final :
|
||||
public ::google::protobuf::Message /* @@protoc_insertion_point(class_definition:WhisperCom.Protobuf.TestMessage) */ {
|
||||
public:
|
||||
inline TestMessage() : TestMessage(nullptr) {}
|
||||
~TestMessage() override;
|
||||
template<typename = void>
|
||||
explicit PROTOBUF_CONSTEXPR TestMessage(::google::protobuf::internal::ConstantInitialized);
|
||||
|
||||
TestMessage(const TestMessage& from);
|
||||
TestMessage(TestMessage&& from) noexcept
|
||||
: TestMessage() {
|
||||
*this = ::std::move(from);
|
||||
}
|
||||
|
||||
inline TestMessage& operator=(const TestMessage& from) {
|
||||
CopyFrom(from);
|
||||
return *this;
|
||||
}
|
||||
inline TestMessage& operator=(TestMessage&& from) noexcept {
|
||||
if (this == &from) return *this;
|
||||
if (GetOwningArena() == from.GetOwningArena()
|
||||
#ifdef PROTOBUF_FORCE_COPY_IN_MOVE
|
||||
&& GetOwningArena() != nullptr
|
||||
#endif // !PROTOBUF_FORCE_COPY_IN_MOVE
|
||||
) {
|
||||
InternalSwap(&from);
|
||||
} else {
|
||||
CopyFrom(from);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline const ::google::protobuf::UnknownFieldSet& unknown_fields() const {
|
||||
return _internal_metadata_.unknown_fields<::google::protobuf::UnknownFieldSet>(::google::protobuf::UnknownFieldSet::default_instance);
|
||||
}
|
||||
inline ::google::protobuf::UnknownFieldSet* mutable_unknown_fields() {
|
||||
return _internal_metadata_.mutable_unknown_fields<::google::protobuf::UnknownFieldSet>();
|
||||
}
|
||||
|
||||
static const ::google::protobuf::Descriptor* descriptor() {
|
||||
return GetDescriptor();
|
||||
}
|
||||
static const ::google::protobuf::Descriptor* GetDescriptor() {
|
||||
return default_instance().GetMetadata().descriptor;
|
||||
}
|
||||
static const ::google::protobuf::Reflection* GetReflection() {
|
||||
return default_instance().GetMetadata().reflection;
|
||||
}
|
||||
static const TestMessage& default_instance() {
|
||||
return *internal_default_instance();
|
||||
}
|
||||
static inline const TestMessage* internal_default_instance() {
|
||||
return reinterpret_cast<const TestMessage*>(
|
||||
&_TestMessage_default_instance_);
|
||||
}
|
||||
static constexpr int kIndexInFileMessages =
|
||||
0;
|
||||
|
||||
friend void swap(TestMessage& a, TestMessage& b) {
|
||||
a.Swap(&b);
|
||||
}
|
||||
inline void Swap(TestMessage* 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 {
|
||||
::google::protobuf::internal::GenericSwap(this, other);
|
||||
}
|
||||
}
|
||||
void UnsafeArenaSwap(TestMessage* other) {
|
||||
if (other == this) return;
|
||||
ABSL_DCHECK(GetOwningArena() == other->GetOwningArena());
|
||||
InternalSwap(other);
|
||||
}
|
||||
|
||||
// implements Message ----------------------------------------------
|
||||
|
||||
TestMessage* New(::google::protobuf::Arena* arena = nullptr) const final {
|
||||
return CreateMaybeMessage<TestMessage>(arena);
|
||||
}
|
||||
using ::google::protobuf::Message::CopyFrom;
|
||||
void CopyFrom(const TestMessage& from);
|
||||
using ::google::protobuf::Message::MergeFrom;
|
||||
void MergeFrom( const TestMessage& from) {
|
||||
TestMessage::MergeImpl(*this, from);
|
||||
}
|
||||
private:
|
||||
static void MergeImpl(::google::protobuf::Message& to_msg, const ::google::protobuf::Message& from_msg);
|
||||
public:
|
||||
PROTOBUF_ATTRIBUTE_REINITIALIZES void Clear() final;
|
||||
bool IsInitialized() const final;
|
||||
|
||||
::size_t ByteSizeLong() const final;
|
||||
const char* _InternalParse(const char* ptr, ::google::protobuf::internal::ParseContext* ctx) final;
|
||||
::uint8_t* _InternalSerialize(
|
||||
::uint8_t* target, ::google::protobuf::io::EpsCopyOutputStream* stream) const final;
|
||||
int GetCachedSize() const final { return _impl_._cached_size_.Get(); }
|
||||
|
||||
private:
|
||||
void SharedCtor(::google::protobuf::Arena* arena);
|
||||
void SharedDtor();
|
||||
void SetCachedSize(int size) const final;
|
||||
void InternalSwap(TestMessage* other);
|
||||
|
||||
private:
|
||||
friend class ::google::protobuf::internal::AnyMetadata;
|
||||
static ::absl::string_view FullMessageName() {
|
||||
return "WhisperCom.Protobuf.TestMessage";
|
||||
}
|
||||
protected:
|
||||
explicit TestMessage(::google::protobuf::Arena* arena);
|
||||
public:
|
||||
|
||||
static const ClassData _class_data_;
|
||||
const ::google::protobuf::Message::ClassData*GetClassData() const final;
|
||||
|
||||
::google::protobuf::Metadata GetMetadata() const final;
|
||||
|
||||
// nested types ----------------------------------------------------
|
||||
|
||||
// accessors -------------------------------------------------------
|
||||
|
||||
enum : int {
|
||||
kStrFieldNumber = 1,
|
||||
};
|
||||
// string str = 1;
|
||||
void clear_str() ;
|
||||
const std::string& str() const;
|
||||
template <typename Arg_ = const std::string&, typename... Args_>
|
||||
void set_str(Arg_&& arg, Args_... args);
|
||||
std::string* mutable_str();
|
||||
PROTOBUF_NODISCARD std::string* release_str();
|
||||
void set_allocated_str(std::string* ptr);
|
||||
|
||||
private:
|
||||
const std::string& _internal_str() const;
|
||||
inline PROTOBUF_ALWAYS_INLINE void _internal_set_str(
|
||||
const std::string& value);
|
||||
std::string* _internal_mutable_str();
|
||||
|
||||
public:
|
||||
// @@protoc_insertion_point(class_scope:WhisperCom.Protobuf.TestMessage)
|
||||
private:
|
||||
class _Internal;
|
||||
|
||||
friend class ::google::protobuf::internal::TcParser;
|
||||
static const ::google::protobuf::internal::TcParseTable<0, 1, 0, 43, 2> _table_;
|
||||
template <typename T> friend class ::google::protobuf::Arena::InternalHelper;
|
||||
typedef void InternalArenaConstructable_;
|
||||
typedef void DestructorSkippable_;
|
||||
struct Impl_ {
|
||||
::google::protobuf::internal::ArenaStringPtr str_;
|
||||
mutable ::google::protobuf::internal::CachedSize _cached_size_;
|
||||
};
|
||||
union { Impl_ _impl_; };
|
||||
friend struct ::TableStruct_TestMessage_2eproto;
|
||||
};
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
||||
|
||||
|
||||
// ===================================================================
|
||||
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif // __GNUC__
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// TestMessage
|
||||
|
||||
// string str = 1;
|
||||
inline void TestMessage::clear_str() {
|
||||
_impl_.str_.ClearToEmpty();
|
||||
}
|
||||
inline const std::string& TestMessage::str() const {
|
||||
// @@protoc_insertion_point(field_get:WhisperCom.Protobuf.TestMessage.str)
|
||||
return _internal_str();
|
||||
}
|
||||
template <typename Arg_, typename... Args_>
|
||||
inline PROTOBUF_ALWAYS_INLINE void TestMessage::set_str(Arg_&& arg,
|
||||
Args_... args) {
|
||||
;
|
||||
_impl_.str_.Set(static_cast<Arg_&&>(arg), args..., GetArenaForAllocation());
|
||||
// @@protoc_insertion_point(field_set:WhisperCom.Protobuf.TestMessage.str)
|
||||
}
|
||||
inline std::string* TestMessage::mutable_str() {
|
||||
std::string* _s = _internal_mutable_str();
|
||||
// @@protoc_insertion_point(field_mutable:WhisperCom.Protobuf.TestMessage.str)
|
||||
return _s;
|
||||
}
|
||||
inline const std::string& TestMessage::_internal_str() const {
|
||||
return _impl_.str_.Get();
|
||||
}
|
||||
inline void TestMessage::_internal_set_str(const std::string& value) {
|
||||
;
|
||||
_impl_.str_.Set(value, GetArenaForAllocation());
|
||||
}
|
||||
inline std::string* TestMessage::_internal_mutable_str() {
|
||||
;
|
||||
return _impl_.str_.Mutable( GetArenaForAllocation());
|
||||
}
|
||||
inline std::string* TestMessage::release_str() {
|
||||
// @@protoc_insertion_point(field_release:WhisperCom.Protobuf.TestMessage.str)
|
||||
return _impl_.str_.Release();
|
||||
}
|
||||
inline void TestMessage::set_allocated_str(std::string* value) {
|
||||
_impl_.str_.SetAllocated(value, GetArenaForAllocation());
|
||||
#ifdef PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
if (_impl_.str_.IsDefault()) {
|
||||
_impl_.str_.Set("", GetArenaForAllocation());
|
||||
}
|
||||
#endif // PROTOBUF_FORCE_COPY_DEFAULT_STRING
|
||||
// @@protoc_insertion_point(field_set_allocated:WhisperCom.Protobuf.TestMessage.str)
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // __GNUC__
|
||||
|
||||
// @@protoc_insertion_point(namespace_scope)
|
||||
} // namespace Protobuf
|
||||
} // namespace WhisperCom
|
||||
|
||||
|
||||
// @@protoc_insertion_point(global_scope)
|
||||
|
||||
#include "google/protobuf/port_undef.inc"
|
||||
|
||||
#endif // GOOGLE_PROTOBUF_INCLUDED_TestMessage_2eproto_2epb_2eh
|
6
proto/TestMessage.proto
Normal file
6
proto/TestMessage.proto
Normal file
@ -0,0 +1,6 @@
|
||||
syntax = "proto3";
|
||||
package WhisperCom.Protobuf;
|
||||
|
||||
message TestMessage {
|
||||
string str = 1;
|
||||
}
|
34
src/Listener.cpp
Normal file
34
src/Listener.cpp
Normal file
@ -0,0 +1,34 @@
|
||||
|
||||
#include "Message.pb.h"
|
||||
#include "TestMessage.pb.h"
|
||||
#include "WhisperCom/Service.hpp"
|
||||
#include <memory>
|
||||
#include <thread>
|
||||
#define LOGURU_WITH_STREAMS 1
|
||||
#include <loguru.hpp>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
WhisperCom::Service service{};
|
||||
|
||||
for (int i = 1; i< argc; i++)
|
||||
{
|
||||
service.subscribe(argv[i]);
|
||||
}
|
||||
|
||||
while(1)
|
||||
{
|
||||
std::shared_ptr<WhisperCom::Protobuf::Message> message;
|
||||
if (service.waitForMessage(std::chrono::milliseconds(300), message))
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
DLOG_S(INFO) << "programm terminated";
|
||||
return 0;
|
||||
}
|
322
src/WhisperCom/Router.cpp
Normal file
322
src/WhisperCom/Router.cpp
Normal file
@ -0,0 +1,322 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
#include "RouterMessage.pb.h"
|
||||
#include "google/protobuf/any.pb.h"
|
||||
#include "zmq.hpp"
|
||||
#include <WhisperCom/Router.hpp>
|
||||
#include <atomic>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <exception>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
#define LOGURU_WITH_STREAMS 1
|
||||
#include <loguru.hpp>
|
||||
|
||||
WhisperCom::Router::~Router()
|
||||
{
|
||||
if (isLocalProcessingRunning_)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
DLOG_S(INFO) << "router terminated";
|
||||
}
|
||||
|
||||
WhisperCom::Router::Router(const std::string localUrl, const std::string radioUrl, const std::string dishUrl)
|
||||
:
|
||||
isReady_(false),
|
||||
localUrl_(localUrl),
|
||||
radiolUrl_(radioUrl),
|
||||
dishUrl_(dishUrl),
|
||||
zmqContext_(zmq::context_t{}),
|
||||
localSocket_(zmqContext_, zmq::socket_type::server),
|
||||
listening_(zmqContext_,zmq::socket_type::dish),
|
||||
transmitting_(zmqContext_, zmq::socket_type::radio),
|
||||
dummySocket_(zmqContext_, zmq::socket_type::server),
|
||||
localProcesing_(nullptr),
|
||||
isLocalProcessingRunning_(false),
|
||||
stopLocalProcessing_(false)
|
||||
{
|
||||
isReady_=true;
|
||||
|
||||
try
|
||||
{
|
||||
dummySocket_.bind("tcp://127.0.0.1:23543");
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
DLOG_S(WARNING) << "dummy socket port already in use";
|
||||
zmqContext_.shutdown();
|
||||
isReady_=false;
|
||||
}
|
||||
|
||||
if (isReady_)
|
||||
{
|
||||
try
|
||||
{
|
||||
localSocket_.bind(localUrl_);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
DLOG_S(WARNING) << "local port already in use";
|
||||
zmqContext_.shutdown();
|
||||
isReady_=false;
|
||||
}
|
||||
|
||||
if (localSocket_.handle() == nullptr)
|
||||
{
|
||||
LOG_S(ERROR) << "socket bind failed";
|
||||
isReady_=false;
|
||||
}
|
||||
}
|
||||
|
||||
if (isReady_)
|
||||
{
|
||||
transmitting_.connect(radiolUrl_);
|
||||
if (transmitting_.handle() == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Failed connecting to radio url");
|
||||
}
|
||||
|
||||
listening_.bind(dishUrl_);
|
||||
|
||||
if (listening_.handle() == nullptr)
|
||||
{
|
||||
throw std::runtime_error("Failed binding to dish url");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WhisperCom::Router::start()
|
||||
{
|
||||
if (!isReady_)
|
||||
{
|
||||
LOG_S(ERROR) << "router not ready, can not start";
|
||||
throw std::runtime_error("Can not start, router is not ready");
|
||||
}
|
||||
|
||||
if (isLocalProcessingRunning_)
|
||||
{
|
||||
LOG_S(ERROR) << "router already running, can not start twice";
|
||||
throw std::runtime_error("router already running, can not start twice");
|
||||
}
|
||||
|
||||
stopLocalProcessing_=false;
|
||||
|
||||
localProcesing_ = std::make_unique<std::thread>(&WhisperCom::Router::processLocalMessages_, this);
|
||||
|
||||
std::uint16_t timeout = 1000;
|
||||
while(timeout > 0 && !isLocalProcessingRunning_)
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
std::this_thread::sleep_for(100ms);
|
||||
timeout = timeout - 100;
|
||||
}
|
||||
if (timeout == 0)
|
||||
{
|
||||
LOG_S(ERROR) << "could not start processing thread, router could not be started";
|
||||
throw std::runtime_error("could not start router");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void WhisperCom::Router::stop()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
std::uint16_t timeout = 1000;
|
||||
|
||||
if (!isLocalProcessingRunning_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (stopLocalProcessing_)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
stopLocalProcessing_=true;
|
||||
|
||||
while(timeout > 0 && isLocalProcessingRunning_)
|
||||
{
|
||||
std::this_thread::sleep_for(100ms);
|
||||
timeout = timeout - 100;
|
||||
}
|
||||
|
||||
if (timeout == 0)
|
||||
{
|
||||
throw std::runtime_error("could not stop local processing thread");
|
||||
}
|
||||
|
||||
localProcesing_->join();
|
||||
}
|
||||
|
||||
void WhisperCom::Router::processLocalMessages_()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
isLocalProcessingRunning_=true;
|
||||
|
||||
while(!stopLocalProcessing_)
|
||||
{
|
||||
std::this_thread::sleep_for(300ms);
|
||||
bool finished = false;
|
||||
|
||||
// process messages on internal socket
|
||||
while(!finished)
|
||||
{
|
||||
zmq::message_t msg{};
|
||||
|
||||
zmq::recv_result_t result = localSocket_.recv(msg, zmq::recv_flags::dontwait);
|
||||
if (msg.empty())
|
||||
{
|
||||
finished=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
processLocalMessage_(msg);
|
||||
}
|
||||
}
|
||||
|
||||
finished = false;
|
||||
|
||||
// process messages on external socket
|
||||
while(!finished)
|
||||
{
|
||||
zmq::message_t msg{};
|
||||
|
||||
zmq::recv_result_t result = listening_.recv(msg, zmq::recv_flags::dontwait);
|
||||
if (msg.empty())
|
||||
{
|
||||
finished=true;
|
||||
}
|
||||
else
|
||||
{
|
||||
processExternalMessage_(msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
isLocalProcessingRunning_=false;
|
||||
}
|
||||
|
||||
void WhisperCom::Router::processExternalMessage_(const zmq::message_t &msg)
|
||||
{
|
||||
WhisperCom::Protobuf::Message *eMsg = new WhisperCom::Protobuf::Message();
|
||||
std::uint8_t data[msg.size()];
|
||||
memcpy(data, msg.data(), msg.size());
|
||||
|
||||
eMsg->ParseFromArray(data, msg.size());
|
||||
|
||||
WhisperCom::Protobuf::RouterMessage rmsg;
|
||||
rmsg.set_type(WhisperCom::Protobuf::RouterMessageType::DATA);
|
||||
rmsg.set_allocated_msg(eMsg);
|
||||
|
||||
std::string data2 = rmsg.SerializeAsString();
|
||||
zmq::message_t msg2{data2.data(), data2.size()};
|
||||
for (auto it = localClients_.begin(); it != localClients_.end(); ++it) {
|
||||
DLOG_S(INFO) << "send message to " << it->first;
|
||||
msg2.set_routing_id(it->first);
|
||||
localSocket_.send(msg2, zmq::send_flags::dontwait);
|
||||
}
|
||||
}
|
||||
|
||||
void WhisperCom::Router::processLocalMessage_(zmq::message_t &msg)
|
||||
{
|
||||
WhisperCom::Protobuf::RouterMessage rmsg;
|
||||
rmsg.ParseFromArray(msg.data(), msg.size());
|
||||
|
||||
mutexLocalClients_.lock();
|
||||
localClients_.emplace(msg.routing_id(),std::chrono::steady_clock::now().time_since_epoch().count());
|
||||
mutexLocalClients_.unlock();
|
||||
std::uint32_t sender = msg.routing_id();
|
||||
|
||||
std::string typeName;
|
||||
if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::JOIN)
|
||||
{
|
||||
typeName="JOIN";
|
||||
}
|
||||
else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::LEAVE)
|
||||
{
|
||||
typeName="LEAVE";
|
||||
mutexLocalClients_.lock();
|
||||
localClients_.erase(msg.routing_id());
|
||||
mutexLocalClients_.unlock();
|
||||
}
|
||||
else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::KEEPALIVE)
|
||||
{
|
||||
typeName="KEEPALIVE";
|
||||
WhisperCom::Protobuf::RouterMessage rmsg;
|
||||
rmsg.set_type(WhisperCom::Protobuf::RouterMessageType::LEAVE);
|
||||
std::string data = rmsg.SerializeAsString();
|
||||
zmq::message_t msg2{data.data(), data.size()};
|
||||
msg2.set_routing_id(msg.routing_id());
|
||||
localSocket_.send(msg2, zmq::send_flags::dontwait);
|
||||
}
|
||||
else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::DATA)
|
||||
{
|
||||
WhisperCom::Protobuf::Message externalMsg = rmsg.msg();
|
||||
|
||||
google::protobuf::Any raw;
|
||||
std::string rawPayload=externalMsg.payload().SerializePartialAsString();
|
||||
zmq::message_t emsg{rawPayload.data(), rawPayload.size()};
|
||||
emsg.set_group(rmsg.topic().c_str());
|
||||
transmitting_.send(emsg, zmq::send_flags::dontwait);
|
||||
|
||||
std::lock_guard<std::mutex> guard{mutexLocalClients_};
|
||||
|
||||
typeName="DATA";
|
||||
for (auto it = localClients_.begin(); it != localClients_.end(); ++it)
|
||||
{
|
||||
if ((*it).first != sender)
|
||||
{
|
||||
msg.set_routing_id(it->first);
|
||||
localSocket_.send(msg, zmq::send_flags::dontwait);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::SUBSCRIBE)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard{mutexSubscription_};
|
||||
typeName="Subscribe";
|
||||
subscription_[rmsg.topic()].push_back(sender);
|
||||
listening_.join(rmsg.topic().c_str());
|
||||
}
|
||||
else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::UNSUBSCRIBE)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard{mutexSubscription_};
|
||||
typeName="UnSubscribe";
|
||||
auto it = std::find(subscription_[rmsg.topic()].begin(),subscription_[rmsg.topic()].end(),sender);
|
||||
|
||||
if (it != subscription_[rmsg.topic()].end())
|
||||
{
|
||||
subscription_[rmsg.topic()].erase(it);
|
||||
}
|
||||
|
||||
listening_.leave(rmsg.topic().c_str());
|
||||
}
|
||||
else if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::UNSUBSCRIBE_ALL)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard{mutexSubscription_};
|
||||
typeName="UnSubscribeAll";
|
||||
for (auto topic = subscription_.begin(); topic != subscription_.end(); ++topic)
|
||||
{
|
||||
auto it = std::find(subscription_[topic->first].begin(),subscription_[topic->first].end(),sender);
|
||||
|
||||
if (it != subscription_[topic->first].end()) {
|
||||
subscription_[topic->first].erase(it);
|
||||
}
|
||||
|
||||
listening_.leave(topic->first.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
DLOG_S(INFO) << "received " << typeName << " message from " << sender;
|
||||
|
||||
}
|
310
src/WhisperCom/Service.cpp
Normal file
310
src/WhisperCom/Service.cpp
Normal file
@ -0,0 +1,310 @@
|
||||
/*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
#include "RouterMessage.pb.h"
|
||||
#include "WhisperCom/Router.hpp"
|
||||
#include "google/protobuf/any.pb.h"
|
||||
#include "zmq.hpp"
|
||||
#include <WhisperCom/Service.hpp>
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <exception>
|
||||
#include <future>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <stdexcept>
|
||||
#include <thread>
|
||||
|
||||
#define LOGURU_WITH_STREAMS 1
|
||||
#include <loguru.hpp>
|
||||
|
||||
WhisperCom::Service::~Service()
|
||||
{
|
||||
if (isKeepAliveRunning_ || isReceiveRunning_)
|
||||
{
|
||||
stop();
|
||||
}
|
||||
|
||||
DLOG_S(INFO) << "service terminated";
|
||||
}
|
||||
|
||||
WhisperCom::Service::Service(const std::string localUrl, const std::string radioUrl, const std::string dishUrl, std::uint32_t routerDeadTimeout, std::uint32_t keepaliveTime)
|
||||
:
|
||||
routerDeadTimeOut_(routerDeadTimeout),
|
||||
keepaliveTime_(keepaliveTime),
|
||||
localUrl_(localUrl),
|
||||
radioUrl_(radioUrl),
|
||||
dishUrl_(dishUrl),
|
||||
router_(std::make_unique<WhisperCom::Router>(localUrl,radioUrl,dishUrl)),
|
||||
zmqContext_(),
|
||||
socket_(zmqContext_,zmq::socket_type::client),
|
||||
lastKeepAlive_(std::chrono::steady_clock::now()),
|
||||
keepaliveThread_(nullptr),
|
||||
stopKeepAlive_(false),
|
||||
isKeepAliveRunning_(false),
|
||||
receiveThread_(nullptr),
|
||||
stopReceive_(false),
|
||||
isReceiveRunning_(false)
|
||||
{
|
||||
if (router_->isReady())
|
||||
{
|
||||
router_->start();
|
||||
}
|
||||
else
|
||||
{
|
||||
router_=nullptr;
|
||||
}
|
||||
|
||||
socket_.connect(localUrl);
|
||||
|
||||
WhisperCom::Protobuf::RouterMessage rmsg{};
|
||||
rmsg.set_type(WhisperCom::Protobuf::RouterMessageType::JOIN);
|
||||
|
||||
std::string data = rmsg.SerializeAsString();
|
||||
|
||||
DLOG_S(INFO) << "message size: " << data.size();
|
||||
|
||||
zmq::message_t msg{data.data(), data.size()};
|
||||
|
||||
socket_.send(msg,zmq::send_flags::none);
|
||||
|
||||
|
||||
keepaliveThread_ = std::make_unique<std::thread>(&WhisperCom::Service::keepalive_,this);
|
||||
receiveThread_ = std::make_unique<std::thread>(&WhisperCom::Service::receive_,this);
|
||||
}
|
||||
|
||||
void WhisperCom::Service::verifyRouter_()
|
||||
{
|
||||
std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
|
||||
std::chrono::steady_clock::time_point update = lastKeepAlive_;
|
||||
|
||||
auto elapsed = std::chrono::duration_cast<std::chrono::seconds>(now - update);
|
||||
|
||||
if (elapsed.count() > routerDeadTimeOut_ && router_ == nullptr)
|
||||
{
|
||||
router_ = std::make_unique<WhisperCom::Router>(localUrl_,radioUrl_,dishUrl_);
|
||||
if (router_->isReady())
|
||||
{
|
||||
router_->start();
|
||||
}
|
||||
else
|
||||
{
|
||||
router_=nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void WhisperCom::Service::keepalive_()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
isKeepAliveRunning_=true;
|
||||
WhisperCom::Protobuf::RouterMessage rmsg{};
|
||||
rmsg.set_type(WhisperCom::Protobuf::RouterMessageType::KEEPALIVE);
|
||||
|
||||
while(!stopKeepAlive_)
|
||||
{
|
||||
std::string data = rmsg.SerializeAsString();
|
||||
zmq::message_t msg{data.data(), data.size()};
|
||||
socket_.send(msg, zmq::send_flags::dontwait);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(keepaliveTime_));
|
||||
}
|
||||
isKeepAliveRunning_=false;
|
||||
}
|
||||
|
||||
void WhisperCom::Service::receive_()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
isReceiveRunning_ = true;
|
||||
|
||||
while (!stopReceive_) {
|
||||
std::this_thread::sleep_for(300ms);
|
||||
|
||||
bool finished = false;
|
||||
while(!finished)
|
||||
{
|
||||
zmq::message_t msg{};
|
||||
try
|
||||
{
|
||||
zmq::recv_result_t result = socket_.recv(msg, zmq::recv_flags::dontwait);
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
finished=true;
|
||||
stopReceive_=true;
|
||||
}
|
||||
|
||||
if (!msg.empty()) {
|
||||
DLOG_S(INFO) << "processing message";
|
||||
processMessage_(msg);
|
||||
}
|
||||
else
|
||||
{
|
||||
finished=true;
|
||||
}
|
||||
};
|
||||
|
||||
if (router_ == nullptr)
|
||||
{
|
||||
verifyRouter_();
|
||||
}
|
||||
}
|
||||
|
||||
isReceiveRunning_=false;
|
||||
}
|
||||
|
||||
void WhisperCom::Service::processMessage_(const zmq::message_t &msg)
|
||||
{
|
||||
WhisperCom::Protobuf::RouterMessage rmsg;
|
||||
rmsg.ParseFromArray(msg.data(), msg.size());
|
||||
lastKeepAlive_=std::chrono::steady_clock::now();
|
||||
|
||||
if (rmsg.type() == WhisperCom::Protobuf::RouterMessageType::DATA)
|
||||
{
|
||||
WhisperCom::Protobuf::Message wMsg{};
|
||||
wMsg = rmsg.msg();
|
||||
std::unique_lock lk(mutexMessageQueue_);
|
||||
mutexMessageQueue_.lock();
|
||||
messageQueue_.push(std::make_shared<WhisperCom::Protobuf::Message>(wMsg));
|
||||
mutexMessageQueue_.unlock();
|
||||
condWaitMessageQueue_.notify_one();
|
||||
DLOG_S(INFO) << "received data message";
|
||||
}
|
||||
}
|
||||
|
||||
bool WhisperCom::Service::sendMessage(const std::string &topic,WhisperCom::Protobuf::Message &data)
|
||||
{
|
||||
|
||||
WhisperCom::Protobuf::RouterMessage rmsg{};
|
||||
|
||||
std::unique_ptr<WhisperCom::Protobuf::Message> payload;
|
||||
payload = std::make_unique < WhisperCom::Protobuf::Message>(data);
|
||||
|
||||
rmsg.set_type(WhisperCom::Protobuf::RouterMessageType::DATA);
|
||||
rmsg.set_allocated_msg(payload.release());
|
||||
rmsg.set_topic(topic);
|
||||
|
||||
std::string msgData = rmsg.SerializeAsString();
|
||||
zmq::message_t msg{msgData.data(), msgData.size()};
|
||||
socket_.send(msg, zmq::send_flags::dontwait);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void WhisperCom::Service::stop()
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
WhisperCom::Protobuf::RouterMessage rmsg{};
|
||||
rmsg.set_type(WhisperCom::Protobuf::RouterMessageType::LEAVE);
|
||||
std::string data = rmsg.SerializeAsString();
|
||||
zmq::message_t msg{data.data(), data.size()};
|
||||
socket_.send(msg, zmq::send_flags::dontwait);
|
||||
|
||||
std::uint16_t timeout = 3000;
|
||||
|
||||
stopKeepAlive_=true;
|
||||
stopReceive_=true;
|
||||
socket_.set(zmq::sockopt::linger,0);
|
||||
|
||||
while(timeout > 0 && (isKeepAliveRunning_ || isReceiveRunning_ ))
|
||||
{
|
||||
std::this_thread::sleep_for(100ms);
|
||||
timeout = timeout - 100;
|
||||
DLOG_S(INFO) << "wait termination";
|
||||
}
|
||||
|
||||
if (timeout == 0)
|
||||
{
|
||||
if (isKeepAliveRunning_)
|
||||
{
|
||||
LOG_S(ERROR) << "could not stop keepalive thread";
|
||||
throw std::runtime_error("could not stop keepalive thread");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_S(ERROR) << "could not stop receiver thread";
|
||||
throw std::runtime_error("could not stop receiver thread");
|
||||
}
|
||||
}
|
||||
|
||||
keepaliveThread_->join();
|
||||
DLOG_S(INFO) << "joined keepalive";
|
||||
receiveThread_->join();
|
||||
DLOG_S(INFO) << "joined receiver";
|
||||
|
||||
zmqContext_.shutdown();
|
||||
|
||||
DLOG_S(INFO) << "stopped";
|
||||
}
|
||||
|
||||
void WhisperCom::Service::subscribe(const std::string &topic) {
|
||||
|
||||
WhisperCom::Protobuf::RouterMessage rmsg{};
|
||||
|
||||
rmsg.set_type(WhisperCom::Protobuf::RouterMessageType::SUBSCRIBE);
|
||||
rmsg.set_topic(topic);
|
||||
|
||||
std::string msgData = rmsg.SerializeAsString();
|
||||
zmq::message_t msg{msgData.data(), msgData.size()};
|
||||
|
||||
socket_.send(msg, zmq::send_flags::dontwait);
|
||||
}
|
||||
|
||||
void WhisperCom::Service::unsubscribe(const std::string &topic) {
|
||||
|
||||
WhisperCom::Protobuf::RouterMessage rmsg{};
|
||||
|
||||
rmsg.set_type(WhisperCom::Protobuf::RouterMessageType::UNSUBSCRIBE);
|
||||
rmsg.set_topic(topic);
|
||||
|
||||
std::string msgData = rmsg.SerializeAsString();
|
||||
zmq::message_t msg{msgData.data(), msgData.size()};
|
||||
|
||||
socket_.send(msg, zmq::send_flags::dontwait);
|
||||
}
|
||||
|
||||
void WhisperCom::Service::unsubscribeAll() {
|
||||
|
||||
WhisperCom::Protobuf::RouterMessage rmsg{};
|
||||
|
||||
rmsg.set_type(WhisperCom::Protobuf::RouterMessageType::UNSUBSCRIBE_ALL);
|
||||
|
||||
std::string msgData = rmsg.SerializeAsString();
|
||||
zmq::message_t msg{msgData.data(), msgData.size()};
|
||||
|
||||
socket_.send(msg, zmq::send_flags::dontwait);
|
||||
}
|
||||
|
||||
bool WhisperCom::Service::waitForMessage(std::chrono::milliseconds timeout)
|
||||
{
|
||||
std::unique_lock lk(mutexMessageQueue_);
|
||||
if (messageQueue_.empty())
|
||||
{
|
||||
condWaitMessageQueue_.wait_for(lk,timeout);
|
||||
}
|
||||
|
||||
if (messageQueue_.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WhisperCom::Service::waitForMessage(std::chrono::milliseconds timeout, std::shared_ptr<WhisperCom::Protobuf::Message> message) {
|
||||
std::unique_lock lk(mutexMessageQueue_);
|
||||
if (messageQueue_.empty()) {
|
||||
condWaitMessageQueue_.wait_for(lk, timeout);
|
||||
}
|
||||
|
||||
if (messageQueue_.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
message = messageQueue_.front();
|
||||
messageQueue_.pop();
|
||||
|
||||
return true;
|
||||
}
|
29
src/main.cpp
Normal file
29
src/main.cpp
Normal file
@ -0,0 +1,29 @@
|
||||
|
||||
#include "TestMessage.pb.h"
|
||||
#include "WhisperCom/Service.hpp"
|
||||
#include <thread>
|
||||
#define LOGURU_WITH_STREAMS 1
|
||||
#include <loguru.hpp>
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
using namespace std::chrono_literals;
|
||||
WhisperCom::Service service{};
|
||||
service.subscribe("test");
|
||||
|
||||
std::this_thread::sleep_for(2000ms);
|
||||
WhisperCom::Protobuf::TestMessage msg;
|
||||
msg.set_str("Hello World");
|
||||
|
||||
|
||||
WhisperCom::Protobuf::Message wmsg{};
|
||||
wmsg.mutable_payload()->PackFrom(msg);
|
||||
service.sendMessage("test", wmsg);
|
||||
|
||||
|
||||
std::this_thread::sleep_for(60000ms);
|
||||
service.stop();
|
||||
|
||||
DLOG_S(INFO) << "programm terminated";
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user