chia7712 commented on a change in pull request #7409: URL: https://github.com/apache/kafka/pull/7409#discussion_r536206138
########## 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) { + return RequestUtils.serialize(header.data(), header.headerVersion(), data(), version); + } + + protected abstract Message data(); + + // Visible for testing + public final ByteBuffer serializeBody() { + return RequestUtils.serialize(null, (short) 0, data(), version); } - protected abstract Struct toStruct(); + // Visible for testing + final int sizeInBytes() { + return data().size(new ObjectSerializationCache(), version); + } public String toString(boolean verbose) { - return toStruct().toString(); + return data().toString(); Review comment: It seems only ```ProduceRequest``` does produce verbose string. Maybe we can remove the ```toString(boolean verbose)``` as most requests does not generate verbose string. Also, ```ProduceRequest``` should override ```toString()``` to generate a verbose string always. ---------------------------------------------------------------- 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