private static AbstractRequest doParseRequest(ApiKeys apiKey, short apiVersion, ByteBuffer buffer) {
        switch (apiKey) {
            case PRODUCE:
                return ProduceRequest.parse(buffer, apiVersion);
            case FETCH:
                return FetchRequest.parse(buffer, apiVersion);
            case LIST_OFFSETS:
                return ListOffsetsRequest.parse(buffer, apiVersion);
            case METADATA:
                return MetadataRequest.parse(buffer, apiVersion);
            case OFFSET_COMMIT:
                return OffsetCommitRequest.parse(buffer, apiVersion);
            case OFFSET_FETCH:
                return OffsetFetchRequest.parse(buffer, apiVersion);
            case FIND_COORDINATOR:
                return FindCoordinatorRequest.parse(buffer, apiVersion);
            case JOIN_GROUP:
                return JoinGroupRequest.parse(buffer, apiVersion);
            case HEARTBEAT:
                return HeartbeatRequest.parse(buffer, apiVersion);
            case LEAVE_GROUP:
                return LeaveGroupRequest.parse(buffer, apiVersion);
            case SYNC_GROUP:
                return SyncGroupRequest.parse(buffer, apiVersion);
            case STOP_REPLICA:
                return StopReplicaRequest.parse(buffer, apiVersion);
            case CONTROLLED_SHUTDOWN:
                return ControlledShutdownRequest.parse(buffer, apiVersion);
            case UPDATE_METADATA:
                return UpdateMetadataRequest.parse(buffer, apiVersion);
            case LEADER_AND_ISR:
                return LeaderAndIsrRequest.parse(buffer, apiVersion);
            case DESCRIBE_GROUPS:
                return DescribeGroupsRequest.parse(buffer, apiVersion);
            case LIST_GROUPS:
                return ListGroupsRequest.parse(buffer, apiVersion);
            case SASL_HANDSHAKE:
                return SaslHandshakeRequest.parse(buffer, apiVersion);
            case API_VERSIONS:
                return ApiVersionsRequest.parse(buffer, apiVersion);
            case CREATE_TOPICS:
                return CreateTopicsRequest.parse(buffer, apiVersion);
            case DELETE_TOPICS:
                return DeleteTopicsRequest.parse(buffer, apiVersion);
            case DELETE_RECORDS:
                return DeleteRecordsRequest.parse(buffer, apiVersion);
            case INIT_PRODUCER_ID:
                return InitProducerIdRequest.parse(buffer, apiVersion);
            case OFFSET_FOR_LEADER_EPOCH:
                return OffsetsForLeaderEpochRequest.parse(buffer, apiVersion);
            case ADD_PARTITIONS_TO_TXN:
                return AddPartitionsToTxnRequest.parse(buffer, apiVersion);
            case ADD_OFFSETS_TO_TXN:
                return AddOffsetsToTxnRequest.parse(buffer, apiVersion);
            case END_TXN:
                return EndTxnRequest.parse(buffer, apiVersion);
            case WRITE_TXN_MARKERS:
                return WriteTxnMarkersRequest.parse(buffer, apiVersion);
            case TXN_OFFSET_COMMIT:
                return TxnOffsetCommitRequest.parse(buffer, apiVersion);
            case DESCRIBE_ACLS:
                return DescribeAclsRequest.parse(buffer, apiVersion);
            case CREATE_ACLS:
                return CreateAclsRequest.parse(buffer, apiVersion);
            case DELETE_ACLS:
                return DeleteAclsRequest.parse(buffer, apiVersion);
            case DESCRIBE_CONFIGS:
                return DescribeConfigsRequest.parse(buffer, apiVersion);
            case ALTER_CONFIGS:
                return AlterConfigsRequest.parse(buffer, apiVersion);
            case ALTER_REPLICA_LOG_DIRS:
                return AlterReplicaLogDirsRequest.parse(buffer, apiVersion);
            case DESCRIBE_LOG_DIRS:
                return DescribeLogDirsRequest.parse(buffer, apiVersion);
            case SASL_AUTHENTICATE:
                return SaslAuthenticateRequest.parse(buffer, apiVersion);
            case CREATE_PARTITIONS:
                return CreatePartitionsRequest.parse(buffer, apiVersion);
            case CREATE_DELEGATION_TOKEN:
                return CreateDelegationTokenRequest.parse(buffer, apiVersion);
            case RENEW_DELEGATION_TOKEN:
                return RenewDelegationTokenRequest.parse(buffer, apiVersion);
            case EXPIRE_DELEGATION_TOKEN:
                return ExpireDelegationTokenRequest.parse(buffer, apiVersion);
            case DESCRIBE_DELEGATION_TOKEN:
                return DescribeDelegationTokenRequest.parse(buffer, apiVersion);
            case DELETE_GROUPS:
                return DeleteGroupsRequest.parse(buffer, apiVersion);
            case ELECT_LEADERS:
                return ElectLeadersRequest.parse(buffer, apiVersion);
            case INCREMENTAL_ALTER_CONFIGS:
                return IncrementalAlterConfigsRequest.parse(buffer, apiVersion);
            case ALTER_PARTITION_REASSIGNMENTS:
                return AlterPartitionReassignmentsRequest.parse(buffer, apiVersion);
            case LIST_PARTITION_REASSIGNMENTS:
                return ListPartitionReassignmentsRequest.parse(buffer, apiVersion);
            case OFFSET_DELETE:
                return OffsetDeleteRequest.parse(buffer, apiVersion);
            case DESCRIBE_CLIENT_QUOTAS:
                return DescribeClientQuotasRequest.parse(buffer, apiVersion);
            case ALTER_CLIENT_QUOTAS:
                return AlterClientQuotasRequest.parse(buffer, apiVersion);
            case DESCRIBE_USER_SCRAM_CREDENTIALS:
                return DescribeUserScramCredentialsRequest.parse(buffer, apiVersion);
            case ALTER_USER_SCRAM_CREDENTIALS:
                return AlterUserScramCredentialsRequest.parse(buffer, apiVersion);
            case VOTE:
                return VoteRequest.parse(buffer, apiVersion);
            case BEGIN_QUORUM_EPOCH:
                return BeginQuorumEpochRequest.parse(buffer, apiVersion);
            case END_QUORUM_EPOCH:
                return EndQuorumEpochRequest.parse(buffer, apiVersion);
            case DESCRIBE_QUORUM:
                return DescribeQuorumRequest.parse(buffer, apiVersion);
            case ALTER_PARTITION:
                return AlterPartitionRequest.parse(buffer, apiVersion);
            case UPDATE_FEATURES:
                return UpdateFeaturesRequest.parse(buffer, apiVersion);
            case ENVELOPE:
                return EnvelopeRequest.parse(buffer, apiVersion);
            case FETCH_SNAPSHOT:
                return FetchSnapshotRequest.parse(buffer, apiVersion);
            case DESCRIBE_CLUSTER:
                return DescribeClusterRequest.parse(buffer, apiVersion);
            case DESCRIBE_PRODUCERS:
                return DescribeProducersRequest.parse(buffer, apiVersion);
            case BROKER_REGISTRATION:
                return BrokerRegistrationRequest.parse(buffer, apiVersion);
            case BROKER_HEARTBEAT:
                return BrokerHeartbeatRequest.parse(buffer, apiVersion);
            case UNREGISTER_BROKER:
                return UnregisterBrokerRequest.parse(buffer, apiVersion);
            case DESCRIBE_TRANSACTIONS:
                return DescribeTransactionsRequest.parse(buffer, apiVersion);
            case LIST_TRANSACTIONS:
                return ListTransactionsRequest.parse(buffer, apiVersion);
            case ALLOCATE_PRODUCER_IDS:
                return AllocateProducerIdsRequest.parse(buffer, apiVersion);
            case CONSUMER_GROUP_HEARTBEAT:
                return ConsumerGroupHeartbeatRequest.parse(buffer, apiVersion);
            case CONSUMER_GROUP_DESCRIBE:
                return ConsumerGroupDescribeRequest.parse(buffer, apiVersion);
            case CONTROLLER_REGISTRATION:
                return ControllerRegistrationRequest.parse(buffer, apiVersion);
            case GET_TELEMETRY_SUBSCRIPTIONS:
                return GetTelemetrySubscriptionsRequest.parse(buffer, apiVersion);
            case PUSH_TELEMETRY:
                return PushTelemetryRequest.parse(buffer, apiVersion);
            case ASSIGN_REPLICAS_TO_DIRS:
                return AssignReplicasToDirsRequest.parse(buffer, apiVersion);
            case LIST_CLIENT_METRICS_RESOURCES:
                return ListClientMetricsResourcesRequest.parse(buffer, apiVersion);
            case DESCRIBE_TOPIC_PARTITIONS:
                return DescribeTopicPartitionsRequest.parse(buffer, apiVersion);

            // AutoMQ for Kafka inject start
            case CREATE_STREAMS:
                return CreateStreamsRequest.parse(buffer, apiVersion);
            case OPEN_STREAMS:
                return OpenStreamsRequest.parse(buffer, apiVersion);
            case CLOSE_STREAMS:
                return CloseStreamsRequest.parse(buffer, apiVersion);
            case DELETE_STREAMS:
                return DeleteStreamsRequest.parse(buffer, apiVersion);
            case TRIM_STREAMS:
                return TrimStreamsRequest.parse(buffer, apiVersion);
            case PREPARE_S3_OBJECT:
                return PrepareS3ObjectRequest.parse(buffer, apiVersion);
            case COMMIT_STREAM_SET_OBJECT:
                return CommitStreamSetObjectRequest.parse(buffer, apiVersion);
            case COMMIT_STREAM_OBJECT:
                return CommitStreamObjectRequest.parse(buffer, apiVersion);
            case GET_OPENING_STREAMS:
                return GetOpeningStreamsRequest.parse(buffer, apiVersion);
            case GET_KVS:
                return GetKVsRequest.parse(buffer, apiVersion);
            case PUT_KVS:
                return PutKVsRequest.parse(buffer, apiVersion);
            case DELETE_KVS:
                return DeleteKVsRequest.parse(buffer, apiVersion);
            case AUTOMQ_REGISTER_NODE:
                return AutomqRegisterNodeRequest.parse(buffer, apiVersion);
            case AUTOMQ_GET_NODES:
                return AutomqGetNodesRequest.parse(buffer, apiVersion);
            case AUTOMQ_ZONE_ROUTER:
                return AutomqZoneRouterRequest.parse(buffer, apiVersion);
            case AUTOMQ_GET_PARTITION_SNAPSHOT:
                return AutomqGetPartitionSnapshotRequest.parse(buffer, apiVersion);
            case GET_NEXT_NODE_ID:
                return GetNextNodeIdRequest.parse(buffer, apiVersion);
            case DESCRIBE_STREAMS:
                return DescribeStreamsRequest.parse(buffer, apiVersion);
            case AUTOMQ_UPDATE_GROUP:
                return AutomqUpdateGroupRequest.parse(buffer, apiVersion);
            // AutoMQ for Kafka inject end

            case SHARE_GROUP_HEARTBEAT:
                return ShareGroupHeartbeatRequest.parse(buffer, apiVersion);
            case SHARE_GROUP_DESCRIBE:
                return ShareGroupDescribeRequest.parse(buffer, apiVersion);
            case SHARE_FETCH:
                return ShareFetchRequest.parse(buffer, apiVersion);
            case SHARE_ACKNOWLEDGE:
                return ShareAcknowledgeRequest.parse(buffer, apiVersion);
            case ADD_RAFT_VOTER:
                return AddRaftVoterRequest.parse(buffer, apiVersion);
            case REMOVE_RAFT_VOTER:
                return RemoveRaftVoterRequest.parse(buffer, apiVersion);
            case UPDATE_RAFT_VOTER:
                return UpdateRaftVoterRequest.parse(buffer, apiVersion);
            case INITIALIZE_SHARE_GROUP_STATE:
                return InitializeShareGroupStateRequest.parse(buffer, apiVersion);
            case READ_SHARE_GROUP_STATE:
                return ReadShareGroupStateRequest.parse(buffer, apiVersion);
            case WRITE_SHARE_GROUP_STATE:
                return WriteShareGroupStateRequest.parse(buffer, apiVersion);
            case DELETE_SHARE_GROUP_STATE:
                return DeleteShareGroupStateRequest.parse(buffer, apiVersion);
            case READ_SHARE_GROUP_STATE_SUMMARY:
                return ReadShareGroupStateSummaryRequest.parse(buffer, apiVersion);
            default:
                throw new AssertionError(String.format("ApiKey %s is not currently handled in `parseRequest`, the " +
                        "code should be updated to do so.", apiKey));
        }
    }
Factory method for getting a request object based on ApiKey ID and a version
clients/src/main/java/org/apache/kafka/common/requests/AbstractRequest.java