diff options
author | Dana Powers <dana.powers@gmail.com> | 2017-03-14 13:34:37 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-03-14 13:34:37 -0700 |
commit | 65ba8822b10e6f8a3ba4e9a6b0a1e6f9b785c18e (patch) | |
tree | c5b7144b04c9238ae459d80339f27b6af33b5a5c /kafka/protocol/api.py | |
parent | a00f9ead161e8b05ac953b460950e42fa0e0b7d6 (diff) | |
download | kafka-python-65ba8822b10e6f8a3ba4e9a6b0a1e6f9b785c18e.tar.gz |
Derive all api classes from Request / Response base classes (#1030)
Diffstat (limited to 'kafka/protocol/api.py')
-rw-r--r-- | kafka/protocol/api.py | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/kafka/protocol/api.py b/kafka/protocol/api.py index 7779aac..ec24a39 100644 --- a/kafka/protocol/api.py +++ b/kafka/protocol/api.py @@ -1,5 +1,7 @@ from __future__ import absolute_import +import abc + from .struct import Struct from .types import Int16, Int32, String, Schema @@ -16,3 +18,50 @@ class RequestHeader(Struct): super(RequestHeader, self).__init__( request.API_KEY, request.API_VERSION, correlation_id, client_id ) + + +class Request(Struct): + __metaclass__ = abc.ABCMeta + + @abc.abstractproperty + def API_KEY(self): + """Integer identifier for api request""" + pass + + @abc.abstractproperty + def API_VERSION(self): + """Integer of api request version""" + pass + + @abc.abstractproperty + def SCHEMA(self): + """An instance of Schema() representing the request structure""" + pass + + @abc.abstractproperty + def RESPONSE_TYPE(self): + """The Response class associated with the api request""" + pass + + def expect_response(self): + """Override this method if an api request does not always generate a response""" + return True + + +class Response(Struct): + __metaclass__ = abc.ABCMeta + + @abc.abstractproperty + def API_KEY(self): + """Integer identifier for api request/response""" + pass + + @abc.abstractproperty + def API_VERSION(self): + """Integer of api request/response version""" + pass + + @abc.abstractproperty + def SCHEMA(self): + """An instance of Schema() representing the response structure""" + pass |