ijuma commented on a change in pull request #7409:
URL: https://github.com/apache/kafka/pull/7409#discussion_r536206699



##########
File path: 
clients/src/main/java/org/apache/kafka/common/requests/RequestUtils.java
##########
@@ -90,4 +75,37 @@ public static boolean hasTransactionalRecords(ProduceRequest 
request) {
         }
         return new AbstractMap.SimpleEntry<>(hasIdempotentRecords, 
hasTransactionalRecords);
     }
+
+    public static MessageSizeAccumulator size(
+        ObjectSerializationCache serializationCache,
+        Message header,
+        short headerVersion,
+        Message apiMessage,
+        short apiVersion
+    ) {
+        MessageSizeAccumulator messageSize = new MessageSizeAccumulator();
+        if (header != null)
+            header.addSize(messageSize, serializationCache, headerVersion);
+        apiMessage.addSize(messageSize, serializationCache, apiVersion);
+        return messageSize;
+    }
+
+    public static ByteBuffer serialize(
+        Message header,
+        short headerVersion,
+        Message apiMessage,
+        short apiVersion
+    ) {
+        ObjectSerializationCache serializationCache = new 
ObjectSerializationCache();
+        MessageSizeAccumulator messageSize = 
RequestUtils.size(serializationCache, header, headerVersion, apiMessage, 
apiVersion);
+
+        ByteBuffer buffer = ByteBuffer.allocate(messageSize.totalSize());

Review comment:
       Yeah, good point. I don't think it affects its current non test usage, 
but could result in a bug as the code changes. Will fix.




----------------------------------------------------------------
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


Reply via email to