m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

232 lines
6.3 KiB

6 months ago
  1. from __future__ import absolute_import
  2. from kafka.protocol.api import Request, Response
  3. from kafka.protocol.types import Int16, Int32, Int64, String, Array, Schema, Bytes
  4. class ProduceResponse_v0(Response):
  5. API_KEY = 0
  6. API_VERSION = 0
  7. SCHEMA = Schema(
  8. ('topics', Array(
  9. ('topic', String('utf-8')),
  10. ('partitions', Array(
  11. ('partition', Int32),
  12. ('error_code', Int16),
  13. ('offset', Int64)))))
  14. )
  15. class ProduceResponse_v1(Response):
  16. API_KEY = 0
  17. API_VERSION = 1
  18. SCHEMA = Schema(
  19. ('topics', Array(
  20. ('topic', String('utf-8')),
  21. ('partitions', Array(
  22. ('partition', Int32),
  23. ('error_code', Int16),
  24. ('offset', Int64))))),
  25. ('throttle_time_ms', Int32)
  26. )
  27. class ProduceResponse_v2(Response):
  28. API_KEY = 0
  29. API_VERSION = 2
  30. SCHEMA = Schema(
  31. ('topics', Array(
  32. ('topic', String('utf-8')),
  33. ('partitions', Array(
  34. ('partition', Int32),
  35. ('error_code', Int16),
  36. ('offset', Int64),
  37. ('timestamp', Int64))))),
  38. ('throttle_time_ms', Int32)
  39. )
  40. class ProduceResponse_v3(Response):
  41. API_KEY = 0
  42. API_VERSION = 3
  43. SCHEMA = ProduceResponse_v2.SCHEMA
  44. class ProduceResponse_v4(Response):
  45. """
  46. The version number is bumped up to indicate that the client supports KafkaStorageException.
  47. The KafkaStorageException will be translated to NotLeaderForPartitionException in the response if version <= 3
  48. """
  49. API_KEY = 0
  50. API_VERSION = 4
  51. SCHEMA = ProduceResponse_v3.SCHEMA
  52. class ProduceResponse_v5(Response):
  53. API_KEY = 0
  54. API_VERSION = 5
  55. SCHEMA = Schema(
  56. ('topics', Array(
  57. ('topic', String('utf-8')),
  58. ('partitions', Array(
  59. ('partition', Int32),
  60. ('error_code', Int16),
  61. ('offset', Int64),
  62. ('timestamp', Int64),
  63. ('log_start_offset', Int64))))),
  64. ('throttle_time_ms', Int32)
  65. )
  66. class ProduceResponse_v6(Response):
  67. """
  68. The version number is bumped to indicate that on quota violation brokers send out responses before throttling.
  69. """
  70. API_KEY = 0
  71. API_VERSION = 6
  72. SCHEMA = ProduceResponse_v5.SCHEMA
  73. class ProduceResponse_v7(Response):
  74. """
  75. V7 bumped up to indicate ZStandard capability. (see KIP-110)
  76. """
  77. API_KEY = 0
  78. API_VERSION = 7
  79. SCHEMA = ProduceResponse_v6.SCHEMA
  80. class ProduceResponse_v8(Response):
  81. """
  82. V8 bumped up to add two new fields record_errors offset list and error_message
  83. (See KIP-467)
  84. """
  85. API_KEY = 0
  86. API_VERSION = 8
  87. SCHEMA = Schema(
  88. ('topics', Array(
  89. ('topic', String('utf-8')),
  90. ('partitions', Array(
  91. ('partition', Int32),
  92. ('error_code', Int16),
  93. ('offset', Int64),
  94. ('timestamp', Int64),
  95. ('log_start_offset', Int64)),
  96. ('record_errors', (Array(
  97. ('batch_index', Int32),
  98. ('batch_index_error_message', String('utf-8'))
  99. ))),
  100. ('error_message', String('utf-8'))
  101. ))),
  102. ('throttle_time_ms', Int32)
  103. )
  104. class ProduceRequest(Request):
  105. API_KEY = 0
  106. def expect_response(self):
  107. if self.required_acks == 0: # pylint: disable=no-member
  108. return False
  109. return True
  110. class ProduceRequest_v0(ProduceRequest):
  111. API_VERSION = 0
  112. RESPONSE_TYPE = ProduceResponse_v0
  113. SCHEMA = Schema(
  114. ('required_acks', Int16),
  115. ('timeout', Int32),
  116. ('topics', Array(
  117. ('topic', String('utf-8')),
  118. ('partitions', Array(
  119. ('partition', Int32),
  120. ('messages', Bytes)))))
  121. )
  122. class ProduceRequest_v1(ProduceRequest):
  123. API_VERSION = 1
  124. RESPONSE_TYPE = ProduceResponse_v1
  125. SCHEMA = ProduceRequest_v0.SCHEMA
  126. class ProduceRequest_v2(ProduceRequest):
  127. API_VERSION = 2
  128. RESPONSE_TYPE = ProduceResponse_v2
  129. SCHEMA = ProduceRequest_v1.SCHEMA
  130. class ProduceRequest_v3(ProduceRequest):
  131. API_VERSION = 3
  132. RESPONSE_TYPE = ProduceResponse_v3
  133. SCHEMA = Schema(
  134. ('transactional_id', String('utf-8')),
  135. ('required_acks', Int16),
  136. ('timeout', Int32),
  137. ('topics', Array(
  138. ('topic', String('utf-8')),
  139. ('partitions', Array(
  140. ('partition', Int32),
  141. ('messages', Bytes)))))
  142. )
  143. class ProduceRequest_v4(ProduceRequest):
  144. """
  145. The version number is bumped up to indicate that the client supports KafkaStorageException.
  146. The KafkaStorageException will be translated to NotLeaderForPartitionException in the response if version <= 3
  147. """
  148. API_VERSION = 4
  149. RESPONSE_TYPE = ProduceResponse_v4
  150. SCHEMA = ProduceRequest_v3.SCHEMA
  151. class ProduceRequest_v5(ProduceRequest):
  152. """
  153. Same as v4. The version number is bumped since the v5 response includes an additional
  154. partition level field: the log_start_offset.
  155. """
  156. API_VERSION = 5
  157. RESPONSE_TYPE = ProduceResponse_v5
  158. SCHEMA = ProduceRequest_v4.SCHEMA
  159. class ProduceRequest_v6(ProduceRequest):
  160. """
  161. The version number is bumped to indicate that on quota violation brokers send out responses before throttling.
  162. """
  163. API_VERSION = 6
  164. RESPONSE_TYPE = ProduceResponse_v6
  165. SCHEMA = ProduceRequest_v5.SCHEMA
  166. class ProduceRequest_v7(ProduceRequest):
  167. """
  168. V7 bumped up to indicate ZStandard capability. (see KIP-110)
  169. """
  170. API_VERSION = 7
  171. RESPONSE_TYPE = ProduceResponse_v7
  172. SCHEMA = ProduceRequest_v6.SCHEMA
  173. class ProduceRequest_v8(ProduceRequest):
  174. """
  175. V8 bumped up to add two new fields record_errors offset list and error_message to PartitionResponse
  176. (See KIP-467)
  177. """
  178. API_VERSION = 8
  179. RESPONSE_TYPE = ProduceResponse_v8
  180. SCHEMA = ProduceRequest_v7.SCHEMA
  181. ProduceRequest = [
  182. ProduceRequest_v0, ProduceRequest_v1, ProduceRequest_v2,
  183. ProduceRequest_v3, ProduceRequest_v4, ProduceRequest_v5,
  184. ProduceRequest_v6, ProduceRequest_v7, ProduceRequest_v8,
  185. ]
  186. ProduceResponse = [
  187. ProduceResponse_v0, ProduceResponse_v1, ProduceResponse_v2,
  188. ProduceResponse_v3, ProduceResponse_v4, ProduceResponse_v5,
  189. ProduceResponse_v6, ProduceResponse_v7, ProduceResponse_v8,
  190. ]