chia7712 commented on a change in pull request #7409: URL: https://github.com/apache/kafka/pull/7409#discussion_r536215626
########## File path: clients/src/main/java/org/apache/kafka/common/requests/AbstractRequest.java ########## @@ -95,21 +93,33 @@ public short version() { return version; } - public Send toSend(String destination, RequestHeader header) { - return new NetworkSend(destination, serialize(header)); + public ApiKeys apiKey() { + return apiKey; } - /** - * Use with care, typically {@link #toSend(String, RequestHeader)} should be used instead. - */ - public ByteBuffer serialize(RequestHeader header) { - return RequestUtils.serialize(header.toStruct(), toStruct()); + public final Send toSend(String destination, RequestHeader header) { + return SendBuilder.buildRequestSend(destination, header, data()); + } + + // Visible for testing + public final ByteBuffer serializeWithHeader(RequestHeader header) { Review comment: > Do you have a concern that it may be misused? yes. Also the various serialization methods are a bit chaos to me :( ########## File path: clients/src/main/java/org/apache/kafka/common/requests/AbstractRequest.java ########## @@ -95,21 +93,33 @@ public short version() { return version; } - public Send toSend(String destination, RequestHeader header) { - return new NetworkSend(destination, serialize(header)); + public ApiKeys apiKey() { + return apiKey; } - /** - * Use with care, typically {@link #toSend(String, RequestHeader)} should be used instead. - */ - public ByteBuffer serialize(RequestHeader header) { - return RequestUtils.serialize(header.toStruct(), toStruct()); + public final Send toSend(String destination, RequestHeader header) { + return SendBuilder.buildRequestSend(destination, header, data()); + } + + // Visible for testing + public final ByteBuffer serializeWithHeader(RequestHeader header) { Review comment: > Do you have a concern that it may be misused? yes. Also the various serialization methods are a bit chaos to me :( ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org