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


##########
streams/src/main/java/org/apache/kafka/streams/state/internals/Utils.java:
##########
@@ -35,11 +35,19 @@ public class Utils {
      * Input:  [headersSize(varint)][headers][timestamp(8)][value]
      * Output: [value]
      */
-    static byte[] rawPlainValue(final byte[] rawValueTimestampHeaders) {
+    public static byte[] rawPlainValue(final byte[] rawValueTimestampHeaders) {
         if (rawValueTimestampHeaders == null) {
             return null;
         }
 
+        // If the header is empty, then copy the value bytes directly
+        if (hasEmptyHeadersAndTimestamp(rawValueTimestampHeaders)) {
+            // Strip header size (varint 1 byte), empty headers (no bytes), 
and timestamp
+            final byte[] res = new byte[rawValueTimestampHeaders.length - 1 - 
StateSerdes.TIMESTAMP_SIZE]; 
+            System.arraycopy(rawValueTimestampHeaders, 1 + 
StateSerdes.TIMESTAMP_SIZE, res, 0, res.length);

Review Comment:
   Yep, this is validated within the `hasEmptyHeadersAndTimestamp` call above, 
at l.64:
   ```
   if (rawValueTimestampHeaders.length - 1 - StateSerdes.TIMESTAMP_SIZE < 0) {
      // throw serialization exception
   ```



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