Commit c156f11a authored by Julien Muchembled's avatar Julien Muchembled

protocol: small cleanup in packet registration

Same as commit a00ab78b.

It was reverted mistakenly when switching to msgpack.
parent e434c253
...@@ -312,6 +312,8 @@ class Packet(object): ...@@ -312,6 +312,8 @@ class Packet(object):
class PacketRegistryFactory(dict): class PacketRegistryFactory(dict):
_next_code = 0
def __call__(self, name, base, d): def __call__(self, name, base, d):
for k, v in d.items(): for k, v in d.items():
if isinstance(v, type) and issubclass(v, Packet): if isinstance(v, type) and issubclass(v, Packet):
...@@ -323,10 +325,9 @@ class PacketRegistryFactory(dict): ...@@ -323,10 +325,9 @@ class PacketRegistryFactory(dict):
def register(self, doc, ignore_when_closed=None, request=False, error=False, def register(self, doc, ignore_when_closed=None, request=False, error=False,
_base=(Packet,), **kw): _base=(Packet,), **kw):
""" Register a packet in the packet registry """ """ Register a packet in the packet registry """
code = len(self) code = self._next_code
if doc is None: assert code < RESPONSE_MASK
self[code] = None self._next_code = code + 1
return # None registered only to skip a code number (for compatibility)
if error and not request: if error and not request:
assert not code assert not code
code = RESPONSE_MASK code = RESPONSE_MASK
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment