HTHou commented on a change in pull request #464: Modified Decoder and 
SequenceReader to support old version of TsFile
URL: https://github.com/apache/incubator-iotdb/pull/464#discussion_r337409169
 
 

 ##########
 File path: 
tsfile/src/main/java/org/apache/iotdb/tsfile/encoding/decoder/PlainDecoder.java
 ##########
 @@ -56,53 +57,39 @@ public boolean readBoolean(ByteBuffer buffer) {
   @Override
   public short readShort(ByteBuffer buffer) {
     if (this.endianType == EndianType.LITTLE_ENDIAN) {
-      int ch1 = ReadWriteIOUtils.read(buffer);
-      int ch2 = ReadWriteIOUtils.read(buffer);
-      return (short) (ch1 + (ch2 << 8));
+      buffer.order(ByteOrder.LITTLE_ENDIAN);
     }
     return buffer.getShort();
   }
 
   @Override
   public int readInt(ByteBuffer buffer) {
     if (this.endianType == EndianType.LITTLE_ENDIAN) {
-      int ch1 = ReadWriteIOUtils.read(buffer);
-      int ch2 = ReadWriteIOUtils.read(buffer);
-      int ch3 = ReadWriteIOUtils.read(buffer);
-      int ch4 = ReadWriteIOUtils.read(buffer);
-      return ch1 + (ch2 << 8) + (ch3 << 16) + (ch4 << 24);
+      buffer.order(ByteOrder.LITTLE_ENDIAN);
     }
     return buffer.getInt();
   }
 
   @Override
   public long readLong(ByteBuffer buffer) {
     if (this.endianType == EndianType.LITTLE_ENDIAN) {
-      int[] buf = new int[8];
-      for (int i = 0; i < 8; i++) {
-        buf[i] = ReadWriteIOUtils.read(buffer);
-      }
-      Long res = 0L;
-      for (int i = 0; i < 8; i++) {
-        res += ((long) buf[i] << (i * 8));
-      }
-      return res;
+      buffer.order(ByteOrder.LITTLE_ENDIAN);
     }
     return buffer.getLong();
   }
 
   @Override
   public float readFloat(ByteBuffer buffer) {
     if (this.endianType == EndianType.LITTLE_ENDIAN) {
-      return Float.intBitsToFloat(readInt(buffer));
+      buffer.order(ByteOrder.LITTLE_ENDIAN);
     }
     return buffer.getFloat();
   }
 
   @Override
   public double readDouble(ByteBuffer buffer) {
     if (this.endianType == EndianType.LITTLE_ENDIAN) {
-      return Double.longBitsToDouble(readLong(buffer));
+      buffer.order(ByteOrder.LITTLE_ENDIAN);
 
 Review comment:
   > This is okay. But the checks can be saved if you set the byte order when 
the buffer is created instead of when calling these methods.
   
   Yes, you are right! Thanks a lot.

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to