From 3f46fef7032d97b0dd82971ffece1062fd6b05b8 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 15 Jan 2023 23:50:54 +0200 Subject: [PATCH] Remove function overloads for manually specifying packet IDs Since the IDs can be transposed when sending and receiving, this isn't terribly useful anymore. For Communicator's multi-protocol support having abnormally high packet IDs is detrimental. --- source/net/protocol.cpp | 5 ++--- source/net/protocol.h | 20 ++++---------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/source/net/protocol.cpp b/source/net/protocol.cpp index 358966f..7fde8fe 100644 --- a/source/net/protocol.cpp +++ b/source/net/protocol.cpp @@ -10,9 +10,8 @@ using namespace std; namespace Msp { namespace Net { -Protocol::Protocol(unsigned npi): - header_def(0), - next_packet_id(npi) +Protocol::Protocol(): + header_def(0) { PacketDefBuilder>(*this, header_def, Serializer()) .fields(&PacketHeader::type, &PacketHeader::length); diff --git a/source/net/protocol.h b/source/net/protocol.h index 248b97e..e766733 100644 --- a/source/net/protocol.h +++ b/source/net/protocol.h @@ -191,12 +191,12 @@ private: }; PacketTypeDef header_def; - unsigned next_packet_id; + unsigned next_packet_id = 1; std::map> packet_class_defs; std::map packet_id_defs; protected: - Protocol(unsigned = 1); + Protocol(); private: static unsigned get_next_packet_class_id(); @@ -207,12 +207,6 @@ private: void add_packet(std::unique_ptr); protected: - template - PacketDefBuilder> add(unsigned); - - template - auto add(unsigned id, T P::*field, Rest P::*...rest) { return add

(id).fields(field, rest...); } - template PacketDefBuilder> add(); @@ -253,20 +247,14 @@ unsigned Protocol::get_packet_class_id() } template -Protocol::PacketDefBuilder> Protocol::add(unsigned id) +Protocol::PacketDefBuilder> Protocol::add() { - std::unique_ptr> pdef = std::make_unique>(id); + std::unique_ptr> pdef = std::make_unique>(next_packet_id++); PacketDefBuilder> next(*this, *pdef, Serializer

()); add_packet(move(pdef)); return next; } -template -Protocol::PacketDefBuilder> Protocol::add() -{ - return add

(next_packet_id++); -} - template const Protocol::PacketTypeDef

&Protocol::get_packet_by_class() const { -- 2.43.0