From 42f749be456ed5bd3490d4a4da52bfcad4328d8f Mon Sep 17 00:00:00 2001 From: Henry Winkel Date: Wed, 15 Feb 2023 15:28:07 +0100 Subject: [PATCH] CHG: changed message proto and fixed all causing issues after that --- include/WHISPER/Messages/Message.hpp | 2 + include/WHISPER/Messages/Protos/message.pb.cc | 70 ++++++---- include/WHISPER/Messages/Protos/message.pb.h | 128 ++++++++++++------ include/WHISPER/Messages/Protos/message.proto | 2 +- src/WHISPER/Messages/Join.cpp | 9 +- src/WHISPER/Messages/Leave.cpp | 10 +- src/WHISPER/Messages/Message.cpp | 5 +- src/WHISPER/Messages/Ping.cpp | 9 +- src/WHISPER/Messages/Pong.cpp | 8 +- src/WHISPER/Messages/stringData.cpp | 9 +- 10 files changed, 160 insertions(+), 92 deletions(-) diff --git a/include/WHISPER/Messages/Message.hpp b/include/WHISPER/Messages/Message.hpp index ee6c306..c79c64a 100644 --- a/include/WHISPER/Messages/Message.hpp +++ b/include/WHISPER/Messages/Message.hpp @@ -30,6 +30,8 @@ namespace WHISPER { OWN_TRACK, /// raw track message RAW_TRACK, + /// SENSOR Track message + SENSOR_TRACK, /// simple data SIMPLE, /// diff --git a/include/WHISPER/Messages/Protos/message.pb.cc b/include/WHISPER/Messages/Protos/message.pb.cc index b8bb02f..bfa5aed 100644 --- a/include/WHISPER/Messages/Protos/message.pb.cc +++ b/include/WHISPER/Messages/Protos/message.pb.cc @@ -24,7 +24,7 @@ namespace messages { namespace header { PROTOBUF_CONSTEXPR Message::Message( ::_pbi::ConstantInitialized): _impl_{ - /*decltype(_impl_.payload_)*/{} + /*decltype(_impl_.payload_)*/nullptr , /*decltype(_impl_.topic_)*/0u , /*decltype(_impl_.msgtype_)*/0u , /*decltype(_impl_.sourcetype_)*/0u @@ -73,7 +73,7 @@ const char descriptor_table_protodef_message_2eproto[] PROTOBUF_SECTION_VARIABLE "/protobuf/any.proto\"\210\001\n\007Message\022\r\n\005topic" "\030\001 \001(\r\022\017\n\007msgType\030\002 \001(\r\022\022\n\nsourceType\030\003 " "\001(\r\022\020\n\010sourceID\030\004 \001(\r\022\020\n\010parentID\030\005 \001(\r\022" - "%\n\007payload\030\006 \003(\0132\024.google.protobuf.Anyb\006" + "%\n\007payload\030\006 \001(\0132\024.google.protobuf.Anyb\006" "proto3" ; static const ::_pbi::DescriptorTable* const descriptor_table_message_2eproto_deps[1] = { @@ -101,10 +101,18 @@ namespace header { class Message::_Internal { public: + static const ::PROTOBUF_NAMESPACE_ID::Any& payload(const Message* msg); }; +const ::PROTOBUF_NAMESPACE_ID::Any& +Message::_Internal::payload(const Message* msg) { + return *msg->_impl_.payload_; +} void Message::clear_payload() { - _impl_.payload_.Clear(); + if (GetArenaForAllocation() == nullptr && _impl_.payload_ != nullptr) { + delete _impl_.payload_; + } + _impl_.payload_ = nullptr; } Message::Message(::PROTOBUF_NAMESPACE_ID::Arena* arena, bool is_message_owned) @@ -116,7 +124,7 @@ Message::Message(const Message& from) : ::PROTOBUF_NAMESPACE_ID::Message() { Message* const _this = this; (void)_this; new (&_impl_) Impl_{ - decltype(_impl_.payload_){from._impl_.payload_} + decltype(_impl_.payload_){nullptr} , decltype(_impl_.topic_){} , decltype(_impl_.msgtype_){} , decltype(_impl_.sourcetype_){} @@ -125,6 +133,9 @@ Message::Message(const Message& from) , /*decltype(_impl_._cached_size_)*/{}}; _internal_metadata_.MergeFrom<::PROTOBUF_NAMESPACE_ID::UnknownFieldSet>(from._internal_metadata_); + if (from._internal_has_payload()) { + _this->_impl_.payload_ = new ::PROTOBUF_NAMESPACE_ID::Any(*from._impl_.payload_); + } ::memcpy(&_impl_.topic_, &from._impl_.topic_, static_cast(reinterpret_cast(&_impl_.parentid_) - reinterpret_cast(&_impl_.topic_)) + sizeof(_impl_.parentid_)); @@ -136,7 +147,7 @@ inline void Message::SharedCtor( (void)arena; (void)is_message_owned; new (&_impl_) Impl_{ - decltype(_impl_.payload_){arena} + decltype(_impl_.payload_){nullptr} , decltype(_impl_.topic_){0u} , decltype(_impl_.msgtype_){0u} , decltype(_impl_.sourcetype_){0u} @@ -157,7 +168,7 @@ Message::~Message() { inline void Message::SharedDtor() { GOOGLE_DCHECK(GetArenaForAllocation() == nullptr); - _impl_.payload_.~RepeatedPtrField(); + if (this != internal_default_instance()) delete _impl_.payload_; } void Message::SetCachedSize(int size) const { @@ -170,7 +181,10 @@ void Message::Clear() { // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - _impl_.payload_.Clear(); + if (GetArenaForAllocation() == nullptr && _impl_.payload_ != nullptr) { + delete _impl_.payload_; + } + _impl_.payload_ = nullptr; ::memset(&_impl_.topic_, 0, static_cast( reinterpret_cast(&_impl_.parentid_) - reinterpret_cast(&_impl_.topic_)) + sizeof(_impl_.parentid_)); @@ -223,16 +237,11 @@ const char* Message::_InternalParse(const char* ptr, ::_pbi::ParseContext* ctx) } else goto handle_unusual; continue; - // repeated .google.protobuf.Any payload = 6; + // .google.protobuf.Any payload = 6; case 6: if (PROTOBUF_PREDICT_TRUE(static_cast(tag) == 50)) { - ptr -= 1; - do { - ptr += 1; - ptr = ctx->ParseMessage(_internal_add_payload(), ptr); - CHK_(ptr); - if (!ctx->DataAvailable(ptr)) break; - } while (::PROTOBUF_NAMESPACE_ID::internal::ExpectTag<50>(ptr)); + ptr = ctx->ParseMessage(_internal_mutable_payload(), ptr); + CHK_(ptr); } else goto handle_unusual; continue; @@ -295,12 +304,11 @@ uint8_t* Message::_InternalSerialize( target = ::_pbi::WireFormatLite::WriteUInt32ToArray(5, this->_internal_parentid(), target); } - // repeated .google.protobuf.Any payload = 6; - for (unsigned i = 0, - n = static_cast(this->_internal_payload_size()); i < n; i++) { - const auto& repfield = this->_internal_payload(i); + // .google.protobuf.Any payload = 6; + if (this->_internal_has_payload()) { target = ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite:: - InternalWriteMessage(6, repfield, repfield.GetCachedSize(), target, stream); + InternalWriteMessage(6, _Internal::payload(this), + _Internal::payload(this).GetCachedSize(), target, stream); } if (PROTOBUF_PREDICT_FALSE(_internal_metadata_.have_unknown_fields())) { @@ -319,11 +327,11 @@ size_t Message::ByteSizeLong() const { // Prevent compiler warnings about cached_has_bits being unused (void) cached_has_bits; - // repeated .google.protobuf.Any payload = 6; - total_size += 1UL * this->_internal_payload_size(); - for (const auto& msg : this->_impl_.payload_) { - total_size += - ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize(msg); + // .google.protobuf.Any payload = 6; + if (this->_internal_has_payload()) { + total_size += 1 + + ::PROTOBUF_NAMESPACE_ID::internal::WireFormatLite::MessageSize( + *_impl_.payload_); } // uint32 topic = 1; @@ -369,7 +377,10 @@ void Message::MergeImpl(::PROTOBUF_NAMESPACE_ID::Message& to_msg, const ::PROTOB uint32_t cached_has_bits = 0; (void) cached_has_bits; - _this->_impl_.payload_.MergeFrom(from._impl_.payload_); + if (from._internal_has_payload()) { + _this->_internal_mutable_payload()->::PROTOBUF_NAMESPACE_ID::Any::MergeFrom( + from._internal_payload()); + } if (from._internal_topic() != 0) { _this->_internal_set_topic(from._internal_topic()); } @@ -402,13 +413,12 @@ bool Message::IsInitialized() const { void Message::InternalSwap(Message* other) { using std::swap; _internal_metadata_.InternalSwap(&other->_internal_metadata_); - _impl_.payload_.InternalSwap(&other->_impl_.payload_); ::PROTOBUF_NAMESPACE_ID::internal::memswap< PROTOBUF_FIELD_OFFSET(Message, _impl_.parentid_) + sizeof(Message::_impl_.parentid_) - - PROTOBUF_FIELD_OFFSET(Message, _impl_.topic_)>( - reinterpret_cast(&_impl_.topic_), - reinterpret_cast(&other->_impl_.topic_)); + - PROTOBUF_FIELD_OFFSET(Message, _impl_.payload_)>( + reinterpret_cast(&_impl_.payload_), + reinterpret_cast(&other->_impl_.payload_)); } ::PROTOBUF_NAMESPACE_ID::Metadata Message::GetMetadata() const { diff --git a/include/WHISPER/Messages/Protos/message.pb.h b/include/WHISPER/Messages/Protos/message.pb.h index acffaa8..ebee054 100644 --- a/include/WHISPER/Messages/Protos/message.pb.h +++ b/include/WHISPER/Messages/Protos/message.pb.h @@ -188,23 +188,23 @@ class Message final : kSourceIDFieldNumber = 4, kParentIDFieldNumber = 5, }; - // repeated .google.protobuf.Any payload = 6; - int payload_size() const; + // .google.protobuf.Any payload = 6; + bool has_payload() const; private: - int _internal_payload_size() const; + bool _internal_has_payload() const; public: void clear_payload(); - ::PROTOBUF_NAMESPACE_ID::Any* mutable_payload(int index); - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Any >* - mutable_payload(); + const ::PROTOBUF_NAMESPACE_ID::Any& payload() const; + PROTOBUF_NODISCARD ::PROTOBUF_NAMESPACE_ID::Any* release_payload(); + ::PROTOBUF_NAMESPACE_ID::Any* mutable_payload(); + void set_allocated_payload(::PROTOBUF_NAMESPACE_ID::Any* payload); private: - const ::PROTOBUF_NAMESPACE_ID::Any& _internal_payload(int index) const; - ::PROTOBUF_NAMESPACE_ID::Any* _internal_add_payload(); + const ::PROTOBUF_NAMESPACE_ID::Any& _internal_payload() const; + ::PROTOBUF_NAMESPACE_ID::Any* _internal_mutable_payload(); public: - const ::PROTOBUF_NAMESPACE_ID::Any& payload(int index) const; - ::PROTOBUF_NAMESPACE_ID::Any* add_payload(); - const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Any >& - payload() const; + void unsafe_arena_set_allocated_payload( + ::PROTOBUF_NAMESPACE_ID::Any* payload); + ::PROTOBUF_NAMESPACE_ID::Any* unsafe_arena_release_payload(); // uint32 topic = 1; void clear_topic(); @@ -259,7 +259,7 @@ class Message final : typedef void InternalArenaConstructable_; typedef void DestructorSkippable_; struct Impl_ { - ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Any > payload_; + ::PROTOBUF_NAMESPACE_ID::Any* payload_; uint32_t topic_; uint32_t msgtype_; uint32_t sourcetype_; @@ -381,42 +381,90 @@ inline void Message::set_parentid(uint32_t value) { // @@protoc_insertion_point(field_set:messages.header.Message.parentID) } -// repeated .google.protobuf.Any payload = 6; -inline int Message::_internal_payload_size() const { - return _impl_.payload_.size(); +// .google.protobuf.Any payload = 6; +inline bool Message::_internal_has_payload() const { + return this != internal_default_instance() && _impl_.payload_ != nullptr; } -inline int Message::payload_size() const { - return _internal_payload_size(); +inline bool Message::has_payload() const { + return _internal_has_payload(); } -inline ::PROTOBUF_NAMESPACE_ID::Any* Message::mutable_payload(int index) { - // @@protoc_insertion_point(field_mutable:messages.header.Message.payload) - return _impl_.payload_.Mutable(index); +inline const ::PROTOBUF_NAMESPACE_ID::Any& Message::_internal_payload() const { + const ::PROTOBUF_NAMESPACE_ID::Any* p = _impl_.payload_; + return p != nullptr ? *p : reinterpret_cast( + ::PROTOBUF_NAMESPACE_ID::_Any_default_instance_); } -inline ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Any >* -Message::mutable_payload() { - // @@protoc_insertion_point(field_mutable_list:messages.header.Message.payload) - return &_impl_.payload_; -} -inline const ::PROTOBUF_NAMESPACE_ID::Any& Message::_internal_payload(int index) const { - return _impl_.payload_.Get(index); -} -inline const ::PROTOBUF_NAMESPACE_ID::Any& Message::payload(int index) const { +inline const ::PROTOBUF_NAMESPACE_ID::Any& Message::payload() const { // @@protoc_insertion_point(field_get:messages.header.Message.payload) - return _internal_payload(index); + return _internal_payload(); } -inline ::PROTOBUF_NAMESPACE_ID::Any* Message::_internal_add_payload() { - return _impl_.payload_.Add(); +inline void Message::unsafe_arena_set_allocated_payload( + ::PROTOBUF_NAMESPACE_ID::Any* payload) { + if (GetArenaForAllocation() == nullptr) { + delete reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.payload_); + } + _impl_.payload_ = payload; + if (payload) { + + } else { + + } + // @@protoc_insertion_point(field_unsafe_arena_set_allocated:messages.header.Message.payload) } -inline ::PROTOBUF_NAMESPACE_ID::Any* Message::add_payload() { - ::PROTOBUF_NAMESPACE_ID::Any* _add = _internal_add_payload(); - // @@protoc_insertion_point(field_add:messages.header.Message.payload) - return _add; +inline ::PROTOBUF_NAMESPACE_ID::Any* Message::release_payload() { + + ::PROTOBUF_NAMESPACE_ID::Any* temp = _impl_.payload_; + _impl_.payload_ = nullptr; +#ifdef PROTOBUF_FORCE_COPY_IN_RELEASE + auto* old = reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(temp); + temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp); + if (GetArenaForAllocation() == nullptr) { delete old; } +#else // PROTOBUF_FORCE_COPY_IN_RELEASE + if (GetArenaForAllocation() != nullptr) { + temp = ::PROTOBUF_NAMESPACE_ID::internal::DuplicateIfNonNull(temp); + } +#endif // !PROTOBUF_FORCE_COPY_IN_RELEASE + return temp; } -inline const ::PROTOBUF_NAMESPACE_ID::RepeatedPtrField< ::PROTOBUF_NAMESPACE_ID::Any >& -Message::payload() const { - // @@protoc_insertion_point(field_list:messages.header.Message.payload) +inline ::PROTOBUF_NAMESPACE_ID::Any* Message::unsafe_arena_release_payload() { + // @@protoc_insertion_point(field_release:messages.header.Message.payload) + + ::PROTOBUF_NAMESPACE_ID::Any* temp = _impl_.payload_; + _impl_.payload_ = nullptr; + return temp; +} +inline ::PROTOBUF_NAMESPACE_ID::Any* Message::_internal_mutable_payload() { + + if (_impl_.payload_ == nullptr) { + auto* p = CreateMaybeMessage<::PROTOBUF_NAMESPACE_ID::Any>(GetArenaForAllocation()); + _impl_.payload_ = p; + } return _impl_.payload_; } +inline ::PROTOBUF_NAMESPACE_ID::Any* Message::mutable_payload() { + ::PROTOBUF_NAMESPACE_ID::Any* _msg = _internal_mutable_payload(); + // @@protoc_insertion_point(field_mutable:messages.header.Message.payload) + return _msg; +} +inline void Message::set_allocated_payload(::PROTOBUF_NAMESPACE_ID::Any* payload) { + ::PROTOBUF_NAMESPACE_ID::Arena* message_arena = GetArenaForAllocation(); + if (message_arena == nullptr) { + delete reinterpret_cast< ::PROTOBUF_NAMESPACE_ID::MessageLite*>(_impl_.payload_); + } + if (payload) { + ::PROTOBUF_NAMESPACE_ID::Arena* submessage_arena = + ::PROTOBUF_NAMESPACE_ID::Arena::InternalGetOwningArena( + reinterpret_cast<::PROTOBUF_NAMESPACE_ID::MessageLite*>(payload)); + if (message_arena != submessage_arena) { + payload = ::PROTOBUF_NAMESPACE_ID::internal::GetOwnedMessage( + message_arena, payload, submessage_arena); + } + + } else { + + } + _impl_.payload_ = payload; + // @@protoc_insertion_point(field_set_allocated:messages.header.Message.payload) +} #ifdef __GNUC__ #pragma GCC diagnostic pop diff --git a/include/WHISPER/Messages/Protos/message.proto b/include/WHISPER/Messages/Protos/message.proto index 955c718..5bbd786 100644 --- a/include/WHISPER/Messages/Protos/message.proto +++ b/include/WHISPER/Messages/Protos/message.proto @@ -14,7 +14,7 @@ message Message { uint32 parentID = 5; - repeated google.protobuf.Any payload = 6; + google.protobuf.Any payload = 6; } diff --git a/src/WHISPER/Messages/Join.cpp b/src/WHISPER/Messages/Join.cpp index 3b0075b..6a1bc30 100644 --- a/src/WHISPER/Messages/Join.cpp +++ b/src/WHISPER/Messages/Join.cpp @@ -18,11 +18,12 @@ namespace WHISPER { deviceId_ = msg.sourceid(); parentId_ = msg.parentid(); - if ( msg.payload_size()) { - if (msg.payload().begin()->Is()) { - msg.payload().begin()->UnpackTo(&joinMessage); + + if (msg.mutable_payload()->Is()) + { + msg.mutable_payload()->UnpackTo(&joinMessage); } - } + port = joinMessage.port(); sourceAddr = joinMessage.srcaddress(); diff --git a/src/WHISPER/Messages/Leave.cpp b/src/WHISPER/Messages/Leave.cpp index b1e0c3d..71defe3 100644 --- a/src/WHISPER/Messages/Leave.cpp +++ b/src/WHISPER/Messages/Leave.cpp @@ -18,11 +18,13 @@ namespace WHISPER { leaveMessage = messages::leave::Leave(); - if ( msg.payload_size()) { - if (msg.payload().begin()->Is()) { - msg.payload().begin()->UnpackTo(&leaveMessage); - } + if (msg.mutable_payload()->Is()) + { + msg.mutable_payload()->UnpackTo(&leaveMessage); } + + + port = leaveMessage.port(); sourceAddr = leaveMessage.srcaddress(); diff --git a/src/WHISPER/Messages/Message.cpp b/src/WHISPER/Messages/Message.cpp index 421422d..2f2232f 100644 --- a/src/WHISPER/Messages/Message.cpp +++ b/src/WHISPER/Messages/Message.cpp @@ -39,6 +39,7 @@ namespace WHISPER { msg.set_sourcetype(sourceType_); msg.set_msgtype(msgType_); msg.set_parentid(parentId); + } } @@ -52,9 +53,11 @@ namespace WHISPER { void Message::addPayLoad(std::shared_ptr payload){ payload_ = payload; + payloadString_ = payload->SerializeAsString(); msg.clear_payload(); - msg.add_payload()->CopyFrom(*payload_); + msg.mutable_payload()->CopyFrom(*payload); + // msg.add_payload()->CopyFrom(*payload_); } diff --git a/src/WHISPER/Messages/Ping.cpp b/src/WHISPER/Messages/Ping.cpp index e1e0de6..2ac7397 100644 --- a/src/WHISPER/Messages/Ping.cpp +++ b/src/WHISPER/Messages/Ping.cpp @@ -19,11 +19,12 @@ namespace WHISPER { deviceId_ = msg.sourceid(); parentId_ = msg.parentid(); - if ( msg.payload_size()) { - if (msg.payload().begin()->Is()) { - msg.payload().begin()->UnpackTo(&pingMessage); + + if (msg.mutable_payload()->Is()) + { + msg.mutable_payload()->UnpackTo(&pingMessage); } - } + port_ = pingMessage.port(); diff --git a/src/WHISPER/Messages/Pong.cpp b/src/WHISPER/Messages/Pong.cpp index 78b8847..8df0728 100644 --- a/src/WHISPER/Messages/Pong.cpp +++ b/src/WHISPER/Messages/Pong.cpp @@ -19,11 +19,11 @@ namespace WHISPER { deviceId_ = msg.sourceid(); parentId_ = msg.parentid(); - if ( msg.payload_size()) { - if (msg.payload().begin()->Is()) { - msg.payload().begin()->UnpackTo(&message_); + if (msg.mutable_payload()->Is()) + { + msg.mutable_payload()->UnpackTo(&message_); } - } + port_ = message_.port(); diff --git a/src/WHISPER/Messages/stringData.cpp b/src/WHISPER/Messages/stringData.cpp index a528dc3..1617c2e 100644 --- a/src/WHISPER/Messages/stringData.cpp +++ b/src/WHISPER/Messages/stringData.cpp @@ -19,11 +19,12 @@ namespace WHISPER { deviceId_ = msg.sourceid(); parentId_ = msg.parentid(); - if ( msg.payload_size()) { - if (msg.payload().begin()->Is()) { - msg.payload().begin()->UnpackTo(&message_); + + if (msg.mutable_payload()->Is()) + { + msg.mutable_payload()->UnpackTo(&message_); } - } + data_ = message_.data();