]> git.tdb.fi Git - libs/net.git/commitdiff
Remove function overloads for manually specifying packet IDs
authorMikko Rasa <tdb@tdb.fi>
Sun, 15 Jan 2023 21:50:54 +0000 (23:50 +0200)
committerMikko Rasa <tdb@tdb.fi>
Sun, 15 Jan 2023 21:50:54 +0000 (23:50 +0200)
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
source/net/protocol.h

index 358966f643152804ebc0e1b68a3c193179e2a4de..7fde8fe673d4dbba927b7cadec3c449470248539 100644 (file)
@@ -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<PacketHeader, Serializer<PacketHeader>>(*this, header_def, Serializer<PacketHeader>())
                .fields(&PacketHeader::type, &PacketHeader::length);
index 248b97ea5a1d14cb4fde4589ccaf355685370019..e766733cb6a6373839ecefd32c8e95dd9eb24d52 100644 (file)
@@ -191,12 +191,12 @@ private:
        };
 
        PacketTypeDef<PacketHeader> header_def;
-       unsigned next_packet_id;
+       unsigned next_packet_id = 1;
        std::map<unsigned, std::unique_ptr<PacketDefBase>> packet_class_defs;
        std::map<unsigned, PacketDefBase *> 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<PacketDefBase>);
 
 protected:
-       template<typename P>
-       PacketDefBuilder<P, Serializer<P>> add(unsigned);
-
-       template<typename P, typename T, typename... Rest>
-       auto add(unsigned id, T P::*field, Rest P::*...rest) { return add<P>(id).fields(field, rest...); }
-
        template<typename P>
        PacketDefBuilder<P, Serializer<P>> add();
 
@@ -253,20 +247,14 @@ unsigned Protocol::get_packet_class_id()
 }
 
 template<typename P>
-Protocol::PacketDefBuilder<P, Protocol::Serializer<P>> Protocol::add(unsigned id)
+Protocol::PacketDefBuilder<P, Protocol::Serializer<P>> Protocol::add()
 {
-       std::unique_ptr<PacketTypeDef<P>> pdef = std::make_unique<PacketTypeDef<P>>(id);
+       std::unique_ptr<PacketTypeDef<P>> pdef = std::make_unique<PacketTypeDef<P>>(next_packet_id++);
        PacketDefBuilder<P, Serializer<P>> next(*this, *pdef, Serializer<P>());
        add_packet(move(pdef));
        return next;
 }
 
-template<typename P>
-Protocol::PacketDefBuilder<P, Protocol::Serializer<P>> Protocol::add()
-{
-       return add<P>(next_packet_id++);
-}
-
 template<typename P>
 const Protocol::PacketTypeDef<P> &Protocol::get_packet_by_class() const
 {