muralibasani commented on code in PR #21676:
URL: https://github.com/apache/kafka/pull/21676#discussion_r3564491216


##########
clients/src/main/java/org/apache/kafka/common/record/internal/DefaultRecord.java:
##########
@@ -222,6 +222,54 @@ public static int writeTo(DataOutputStream out,
         return ByteUtils.sizeOfVarint(sizeInBytes) + sizeInBytes;
     }
 
+    /**
+     * Write the record to {@code out} using pre-serialized header bytes, 
bypassing per-header
+     * iteration. The {@code rawSerializedHeaders} must use the standard Kafka 
header wire format:
+     * {@code [count(varint)][header1][header2]...}, or be empty (length 0) 
for zero headers.
+     */
+    public static int writeTo(DataOutputStream out,
+                              int offsetDelta,
+                              long timestampDelta,
+                              ByteBuffer key,
+                              ByteBuffer value,
+                              byte[] rawSerializedHeaders) throws IOException {
+        int sizeInBytes = sizeOfBodyInBytes(offsetDelta, timestampDelta, key, 
value, rawSerializedHeaders);
+        ByteUtils.writeVarint(sizeInBytes, out);
+
+        byte attributes = 0;
+        out.write(attributes);
+
+        ByteUtils.writeVarlong(timestampDelta, out);
+        ByteUtils.writeVarint(offsetDelta, out);
+
+        if (key == null) {
+            ByteUtils.writeVarint(-1, out);
+        } else {
+            int keySize = key.remaining();
+            ByteUtils.writeVarint(keySize, out);
+            Utils.writeTo(out, key, keySize);
+        }
+
+        if (value == null) {
+            ByteUtils.writeVarint(-1, out);
+        } else {
+            int valueSize = value.remaining();
+            ByteUtils.writeVarint(valueSize, out);
+            Utils.writeTo(out, value, valueSize);
+        }
+
+        if (rawSerializedHeaders == null)
+            throw new IllegalArgumentException("Raw serialized headers cannot 
be null");
+
+        if (rawSerializedHeaders.length == 0) {
+            ByteUtils.writeVarint(0, out);
+        } else {
+            out.write(rawSerializedHeaders);

Review Comment:
   Agree. added that comment.



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