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



##########
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:
       Actually, I need to think about this more. Because `SendBuilder` is not 
being used, we actually need to copy all the bytes to the returned buffer. I 
need to check what happens for a message contains records.




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