You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Message handling is a giant switch on the first byte, plus a hand-rolled helper to cope with the ID_TIMESTAMP prefix. From Chat Example Client.cpp:276-282 and :355-367:
for (p=client->Receive(); p; client->DeallocatePacket(p), p=client->Receive()) {
packetIdentifier = GetPacketIdentifier(p); // see belowswitch (packetIdentifier) { caseID_CONNECTION_REQUEST_ACCEPTED: ... }
}
unsignedcharGetPacketIdentifier(MafiaNet::Packet *p) {
if (p==0) return255;
if ((unsignedchar)p->data[0] == ID_TIMESTAMP)
return (unsignedchar) p->data[sizeof(MafiaNet::MessageID) + sizeof(MafiaNet::Time)];
return (unsignedchar) p->data[0];
}
Custom messages are arithmetic on ID_USER_PACKET_ENUM (last enum in MessageIdentifiers.h), e.g. bsOut.Write((MessageID)(ID_USER_PACKET_ENUM+1)).
Goal
A typed dispatcher built on the receive iterator (#17) and archive (#19):
New header Source/include/mafianet/Dispatcher.h. Export from umbrella (#12).
Notes
on<T>() assigns the next ID from ID_USER_PACKET_ENUM; dispatch() reads the ID byte, skips the header (and the ID_TIMESTAMP+Time prefix exactly like GetPacketIdentifier above), constructs T, runs its serialize() ([DX L2] Serialization adapter over BitStream #19) in read mode, and invokes the handler.
Context
Message handling is a giant
switchon the first byte, plus a hand-rolled helper to cope with theID_TIMESTAMPprefix. FromChat Example Client.cpp:276-282and:355-367:Custom messages are arithmetic on
ID_USER_PACKET_ENUM(last enum inMessageIdentifiers.h), e.g.bsOut.Write((MessageID)(ID_USER_PACKET_ENUM+1)).Goal
A typed dispatcher built on the receive iterator (#17) and archive (#19):
Where
New header
Source/include/mafianet/Dispatcher.h. Export from umbrella (#12).Notes
on<T>()assigns the next ID fromID_USER_PACKET_ENUM;dispatch()reads the ID byte, skips the header (and theID_TIMESTAMP+Timeprefix exactly likeGetPacketIdentifierabove), constructsT, runs itsserialize()([DX L2] Serialization adapter over BitStream #19) in read mode, and invokes the handler.Sendershould exposeguid()/address()using the optional/to_stringhelpers from [DX L0] Value-type fixes: thread-safe Guid::to_string, optional/string_view #15.switch (pkt.id())path fully usable — the dispatcher is opt-in sugar.Acceptance criteria
ChatMessage, send it ([DX L3] Typed send/broadcast overloads #21), handler fires with equal fields.ID_TIMESTAMP-prefixed packets dispatch to the correct handler.ID_NEW_INCOMING_CONNECTION) dispatch viaon(id, ...).Dependencies
peer.incoming()#17 (iterator), [DX L1] RAII handles:PeerandPacketPtr(keystone) #16 (PacketPtr), [DX L2] Serialization adapter over BitStream #19 (archive); Layer 0 scoped enums ([DX L0] Scoped-enum façade for Reliability & Priority #13).