]> git.tdb.fi Git - libs/net.git/blobdiff - source/net/receiver.cpp
Add a dynamic receiver class for more flexible packet handling
[libs/net.git] / source / net / receiver.cpp
diff --git a/source/net/receiver.cpp b/source/net/receiver.cpp
new file mode 100644 (file)
index 0000000..46c12f3
--- /dev/null
@@ -0,0 +1,16 @@
+#include "receiver.h"
+
+namespace Msp {
+namespace Net {
+
+void DynamicDispatcher::receive(unsigned packet_id, const Variant &packet)
+{
+       auto i = lower_bound_member(targets, packet_id, &Target::packet_id);
+       if(i==targets.end() || i->packet_id!=packet_id)
+               throw key_error(packet_id);
+
+       i->func(*i->receiver, packet);
+}
+
+} // namespace Net
+} // namespace Msp