You are viewing a plain text version of this content. The canonical link for it is here.
Posted to gitbox@activemq.apache.org by GitBox <gi...@apache.org> on 2021/05/04 20:09:03 UTC

[GitHub] [activemq-artemis] clebertsuconic commented on a change in pull request #3545: ARTEMIS-3243 Improve Mirror with dual mirror

clebertsuconic commented on a change in pull request #3545:
URL: https://github.com/apache/activemq-artemis/pull/3545#discussion_r626071390



##########
File path: artemis-commons/src/main/java/org/apache/activemq/artemis/utils/ByteUtil.java
##########
@@ -205,23 +205,49 @@ public static int bytesToInt(byte[] b) {
             | ((int) b[0] & 0xff) << 24;
    }
 
+   public static long bytesToLong(byte[] b) {
+      return ((long) b[7] & 0xff)
+         | ((long) b[6] & 0xff) << 8
+         | ((long) b[5] & 0xff) << 16
+         | ((long) b[4] & 0xff) << 24
+         | ((long) b[3] & 0xff) << 32
+         | ((long) b[2] & 0xff) << 40
+         | ((long) b[1] & 0xff) << 48
+         | ((long) b[0] & 0xff) << 56;
+   }
+
    public static byte[] longToBytes(long value) {
       byte[] output = new byte[8];
       longToBytes(value, output, 0);
       return output;
    }
 
    public static void longToBytes(long x, byte[] output, int offset) {
-      output[offset] = (byte)(x >> 56);
-      output[offset + 1] = (byte)(x >> 48);
-      output[offset + 2] = (byte)(x >> 40);
-      output[offset + 3] = (byte)(x >> 32);
-      output[offset + 4] = (byte)(x >> 24);
-      output[offset + 5] = (byte)(x >> 16);
-      output[offset + 6] = (byte)(x >>  8);
+      output[offset] = (byte)(x >>> 56);
+      output[offset + 1] = (byte)(x >>> 48);
+      output[offset + 2] = (byte)(x >>> 40);
+      output[offset + 3] = (byte)(x >>> 32);
+      output[offset + 4] = (byte)(x >>> 24);
+      output[offset + 5] = (byte)(x >>> 16);
+      output[offset + 6] = (byte)(x >>>  8);

Review comment:
       this was a bug originally... >> in Java is signaled.. if you had a negative value things would be pretty much broken.




-- 
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:
users@infra.apache.org