|
| 1 | +from . import ( |
| 2 | + produce, fetch, list_offsets, metadata, |
| 3 | + commit, find_coordinator, group, |
| 4 | + sasl_handshake, api_versions, admin, |
| 5 | + init_producer_id, offset_for_leader_epoch, |
| 6 | + add_partitions_to_txn, add_offsets_to_txn, end_txn, |
| 7 | + txn_offset_commit, sasl_authenticate, |
| 8 | +) |
| 9 | + |
1 | 10 | API_KEYS = { |
2 | 11 | 0: 'Produce', |
3 | 12 | 1: 'Fetch', |
|
44 | 53 | 46: 'ListPartitionReassignments', |
45 | 54 | 48: 'DescribeClientQuotas', |
46 | 55 | } |
| 56 | + |
| 57 | +# Mapping of Api_key to a tuple of (request_classes, response_classes) |
| 58 | +REQUEST_TYPES = { |
| 59 | + 0: (produce.ProduceRequest, produce.ProduceResponse), |
| 60 | + 1: (fetch.FetchRequest, fetch.FetchResponse), |
| 61 | + 2: (list_offsets.ListOffsetsRequest, list_offsets.ListOffsetsResponse), |
| 62 | + 3: (metadata.MetadataRequest, metadata.MetadataResponse), |
| 63 | + 8: (commit.OffsetCommitRequest, commit.OffsetCommitResponse), |
| 64 | + 9: (commit.OffsetFetchRequest, commit.OffsetFetchResponse), |
| 65 | + 10: (find_coordinator.FindCoordinatorRequest, find_coordinator.FindCoordinatorResponse), |
| 66 | + 11: (group.JoinGroupRequest, group.JoinGroupResponse), |
| 67 | + 12: (group.HeartbeatRequest, group.HeartbeatResponse), |
| 68 | + 13: (group.LeaveGroupRequest, group.LeaveGroupResponse), |
| 69 | + 14: (group.SyncGroupRequest, group.SyncGroupResponse), |
| 70 | + 15: (admin.DescribeGroupsRequest, admin.DescribeGroupsResponse), |
| 71 | + 16: (admin.ListGroupsRequest, admin.ListGroupsResponse), |
| 72 | + 17: (sasl_handshake.SaslHandshakeRequest, sasl_handshake.SaslHandshakeResponse), |
| 73 | + 18: (api_versions.ApiVersionsRequest, api_versions.ApiVersionsResponse), |
| 74 | + 19: (admin.CreateTopicsRequest, admin.CreateTopicsResponse), |
| 75 | + 20: (admin.DeleteTopicsRequest, admin.DeleteTopicsResponse), |
| 76 | + 21: (admin.DeleteRecordsRequest, admin.DeleteRecordsResponse), |
| 77 | + 22: (init_producer_id.InitProducerIdRequest, init_producer_id.InitProducerIdResponse), |
| 78 | + 23: (offset_for_leader_epoch.OffsetForLeaderEpochRequest, offset_for_leader_epoch.OffsetForLeaderEpochResponse), |
| 79 | + 24: (add_partitions_to_txn.AddPartitionsToTxnRequest, add_partitions_to_txn.AddPartitionsToTxnResponse), |
| 80 | + 25: (add_offsets_to_txn.AddOffsetsToTxnRequest, add_offsets_to_txn.AddOffsetsToTxnResponse), |
| 81 | + 26: (end_txn.EndTxnRequest, end_txn.EndTxnResponse), |
| 82 | + 28: (txn_offset_commit.TxnOffsetCommitRequest, txn_offset_commit.TxnOffsetCommitResponse), |
| 83 | + 29: (admin.DescribeAclsRequest, admin.DescribeAclsResponse), |
| 84 | + 30: (admin.CreateAclsRequest, admin.CreateAclsResponse), |
| 85 | + 31: (admin.DeleteAclsRequest, admin.DeleteAclsResponse), |
| 86 | + 32: (admin.DescribeConfigsRequest, admin.DescribeConfigsResponse), |
| 87 | + 33: (admin.AlterConfigsRequest, admin.AlterConfigsResponse), |
| 88 | + 36: (sasl_authenticate.SaslAuthenticateRequest, sasl_authenticate.SaslAuthenticateResponse), |
| 89 | + 37: (admin.CreatePartitionsRequest, admin.CreatePartitionsResponse), |
| 90 | + 42: (admin.DeleteGroupsRequest, admin.DeleteGroupsResponse) |
| 91 | +} |
| 92 | + |
| 93 | +def get_response_class(api_key, api_version): |
| 94 | + request_type, response_type = REQUEST_TYPES.get(api_key, (None, None)) |
| 95 | + if response_type: |
| 96 | + if hasattr(response_type, '__getitem__'): |
| 97 | + return response_type[api_version] |
| 98 | + return response_type |
| 99 | + return None |
0 commit comments