showuon commented on code in PR #12545:
URL: https://github.com/apache/kafka/pull/12545#discussion_r1174314208


##########
clients/src/main/java/org/apache/kafka/common/serialization/DoubleDeserializer.java:
##########
@@ -35,4 +41,22 @@ public Double deserialize(String topic, byte[] data) {
         }
         return Double.longBitsToDouble(value);
     }
+
+    @Override
+    public Double deserialize(String topic, Headers headers, ByteBuffer data) {
+        if (data == null) {
+            return null;
+        }
+
+        if (data.remaining() != 8) {
+            throw new SerializationException("Size of data received by 
DoubleDeserializer is not 8");
+        }
+
+        final ByteOrder srcOrder = data.order();
+        data.order(BIG_ENDIAN);
+
+        final double value = data.getDouble(data.position());

Review Comment:
   @LinShunKang 
   > Because DoubleDeserializer and other Number Deserializers use BIG_ENDIAN 
byte order to read from byte[], and the current byte order of ByteBuffer may 
not be BIG_ENDIAN, we set the byte order of ByteBuffer to BIG_ENDIAN to be 
consistent with the byte order used when reading from byte[].
   
   Again, from the 
[javadoc](https://docs.oracle.com/javase/8/docs/api/java/nio/ByteBuffer.html#getDouble--):
   
   > Reads the next eight bytes at this buffer's current position, composing 
them into a double value according to the current byte order, and then 
increments the position by eight.
   
   The byte order is already considered while reading from the byte buffer. 
That means, this is not true:
   > Because DoubleDeserializer and other Number Deserializers use BIG_ENDIAN 
byte order to read from byte[]
   
   It will read from byte[] using the current byte order. Did I miss anything?



-- 
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: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to