junrao commented on code in PR #23665:
URL: https://github.com/apache/kafka/pull/23665#discussion_r4330765154


##########
clients/src/main/java/org/apache/kafka/common/requests/RequestHeader.java:
##########
@@ -137,11 +137,27 @@ public ResponseHeader toResponseHeader() {
         return new ResponseHeader(data.correlationId(), 
apiKey().responseHeaderVersion(apiVersion()));

Review Comment:
   @AndrewJSchofield : Good point. Claude suggested the following way to 
tighten this up.
   
   ```
   RequestContext is the only production caller of toResponseHeader() (:159, 
:173). Compute both the body version and the header version from the same 
supported version:
   
   public Send buildResponseSend(AbstractResponse body) {
       short version = apiVersion();
       return body.toSend(responseHeader(version), version);
   }
   public ByteBuffer buildResponseEnvelopePayload(AbstractResponse body) {
       short version = apiVersion();
       return body.serializeWithHeader(responseHeader(version), version);
   }
   /**
    * The response header follows the version the response is written at, which 
for an unsupported
    * ApiVersionsRequest is v0 rather than the version of the request.
    */
   private ResponseHeader responseHeader(short responseVersion) {
       return new ResponseHeader(header.correlationId(), 
header.apiKey().responseHeaderVersion(responseVersion));
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to