From: Mikko Rasa Date: Sun, 15 Jan 2023 21:50:54 +0000 (+0200) Subject: Remove function overloads for manually specifying packet IDs X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=3f46fef7032d97b0dd82971ffece1062fd6b05b8;p=libs%2Fnet.git 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. --- 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 {