ivanzlenko commented on code in PR #4670:
URL: https://github.com/apache/ignite-3/pull/4670#discussion_r1828914990


##########
modules/core/src/main/java/org/apache/ignite/internal/hlc/HybridTimestamp.java:
##########
@@ -131,7 +132,18 @@ public static long hybridTimestampToLong(@Nullable 
HybridTimestamp timestamp) {
      * @param bytes Byte array representing a timestamp.
      */
     public static HybridTimestamp fromBytes(byte[] bytes) {
-        return hybridTimestamp(ByteUtils.bytesToLong(bytes));
+        // Reversing bytes as ByteUtils works in BE, but we store in LE (as 
IgniteDataOutput uses LE and we want to be consistent between

Review Comment:
   Fine by me. Fixed



##########
modules/core/src/main/java/org/apache/ignite/internal/hlc/HybridTimestamp.java:
##########
@@ -256,8 +268,21 @@ public HybridTimestamp roundUpToPhysicalTick() {
     /**
      * Returns a byte array representing this timestamp.
      */
+    @SuppressWarnings("NumericCastThatLosesPrecision")
     public byte[] toBytes() {
-        return ByteUtils.longToBytes(longValue());
+        long physical = getPhysical();
+        int logical = getLogical();
+
+        byte[] bytes = new byte[Integer.BYTES + Short.BYTES + 
VarIntUtils.varIntLength(logical)];
+
+        // Reversing bytes as ByteUtils works in BE, but we store in LE (as 
IgniteDataOutput uses LE and we want to be consistent between

Review Comment:
   Fine by me. Fixed



##########
modules/core/src/main/java/org/apache/ignite/internal/util/ByteUtils.java:
##########
@@ -195,11 +215,32 @@ public static byte[] intToBytesKeepingOrder(int i) {
      */
     public static byte[] putIntToBytes(int i, byte[] bytes, int off) {
         assert bytes != null;
-        assert bytes.length >= off + Integer.BYTES;
+        assert off + Integer.BYTES <= bytes.length;
 
         for (int k = Integer.BYTES - 1; k >= 0; k--) {
             bytes[off + k] = (byte) i;
-            i >>>= 8;
+            i >>>= Byte.SIZE;
+        }
+
+        return bytes;
+    }
+
+    /**
+     * Converts a primitive {@code short} value to a byte array in Big Endian 
order and stores it in the specified byte array.
+     *
+     * @param s Unsigned int value.
+     * @param bytes Bytes array to write result to.
+     * @param off Offset in the target array to write result to.
+     * @return The array.
+     */
+    public static byte[] putShortToBytes(short s, byte[] bytes, int off) {

Review Comment:
   Fixed



-- 
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: notifications-unsubscr...@ignite.apache.org

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

Reply via email to