zheguang commented on code in PR #21706:
URL: https://github.com/apache/kafka/pull/21706#discussion_r2957894583


##########
streams/src/main/java/org/apache/kafka/streams/state/internals/ValueTimestampHeadersDeserializer.java:
##########
@@ -129,27 +131,19 @@ static long timestamp(final byte[] 
rawValueTimestampHeaders) {
     /**
      * Extract headers from serialized ValueTimestampHeaders.
      */
-    static Headers headers(final byte[] rawValueTimestampHeaders) {
+    public static Headers headers(final byte[] rawValueTimestampHeaders) {
         if (rawValueTimestampHeaders == null) {
             return null;
         }
 
-        final ByteBuffer buffer = ByteBuffer.wrap(rawValueTimestampHeaders);
-        final int headersSize = ByteUtils.readVarint(buffer);
-        final byte[] rawHeaders = readBytes(buffer, headersSize);
-        return HeadersDeserializer.deserialize(rawHeaders);
-    }
-    /**
-     * Extract raw value from serialized ValueTimestampHeaders.
-     */
-    static byte[] rawValue(final byte[] rawValueTimestampHeaders) {
-        if (rawValueTimestampHeaders == null) {
-            return null;
+        // If the header is empty, simply return it
+        if (rawValueTimestampHeaders.length > 0 && rawValueTimestampHeaders[0] 
== 0x00) {
+            return new RecordHeaders();
         }
 
         final ByteBuffer buffer = ByteBuffer.wrap(rawValueTimestampHeaders);
         final int headersSize = ByteUtils.readVarint(buffer);
-        buffer.position(buffer.position() + headersSize + Long.BYTES);
-        return readBytes(buffer, buffer.remaining());
+        final byte[] rawHeaders = readBytes(buffer, headersSize);

Review Comment:
   So this is also a case for stateful read -- notice the sequence: 
`readVarint(buffer)` for the header size, then `readBytes(buffer, ...)` for the 
headers bytes.  Since we can't get rid of bookkeeping entirely -- the varint 
encoding has varying length from 1-5 bytes, so the headers bytes's location is 
also variable.  In such case with bookkeeping needs, the `ByteBuffer` is 
appropriate and performant.  
https://github.com/apache/kafka/commit/028bca95fcc298f6931e1b487b42c433768438a3



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