Source code for zoonado.protocol.response

from __future__ import unicode_literals

from zoonado.compat import add_metaclass

from .part import Part


response_xref = {}


class ResponseMeta(type):

    def __new__(cls, name, bases, attrs):
        new_class = super(ResponseMeta, cls).__new__(cls, name, bases, attrs)

        response_xref[new_class.opcode] = new_class

        return new_class


@add_metaclass(ResponseMeta)
[docs]class Response(Part): """ Base class for all operation response classes. A simple class, has only an ``opcode`` attribute expected to be defined by subclasses, and a `deserialize()` classmethod. """ opcode = None @classmethod
[docs] def deserialize(cls, raw_bytes): """ Deserializes the given raw bytes into an instance. Since this is a subclass of ``Part`` but a top-level one (i.e. no other subclass of ``Part`` would have a ``Response`` as a part) this merely has to parse the raw bytes and discard the resulting offset. """ instance, _ = cls.parse(raw_bytes, offset=0) return instance