You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cm...@apache.org on 2010/02/14 23:39:32 UTC
svn commit: r910106 -
/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java
Author: cmacnaug
Date: Sun Feb 14 22:39:32 2010
New Revision: 910106
URL: http://svn.apache.org/viewvc?rev=910106&view=rev
Log:
Fixing sign extension problems in bitutils.
Modified:
activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java
Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java?rev=910106&r1=910105&r2=910106&view=diff
==============================================================================
--- activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java (original)
+++ activemq/sandbox/activemq-apollo-actor/activemq-amqp-generator/src/handcoded/org/apache/activemq/amqp/generator/handcoded/BitUtils.java Sun Feb 14 22:39:32 2010
@@ -23,41 +23,43 @@
//!!!!!!Instead, modify the generator in activemq-amqp-generator!!!!!!!!//
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!//
public class BitUtils {
-
+
public static final void setUByte(final byte[] target, final int offset, final short value) {
target[offset + 0] = (byte) (0xff & target[offset]);
}
-
+
public static final short getUByte(final byte[] source, final int offset) {
return (short) (0xFFFF & source[offset]);
}
-
+
public static final void setByte(final byte[] target, final int offset, final byte value) {
target[offset + 0] = value;
}
-
+
public static final short getByte(final byte[] source, final int offset) {
return source[offset];
}
-
+
public static final void setUShort(final byte[] target, final int offset, final long value) {
target[offset + 0] = (byte) ((value >> 8) & 0xff);
target[offset + 1] = (byte) ((value >> 0) & 0xff);
}
-
+
public static final int getUShort(final byte[] source, final int offset) {
- return source[offset + 0] << 8 & 0xff | source[offset + 1];
+ return
+ (source[offset + 0] & 0xff) << 8 |
+ (source[offset + 1]);
}
-
+
public static final void setShort(final byte[] target, final int offset, final short value) {
target[offset + 0] = (byte) ((value >> 8) & 0xff);
target[offset + 1] = (byte) ((value >> 0) & 0xff);
}
-
+
public static final short getShort(final byte[] source, final int offset) {
return (short) (source[offset + 0] << 8 & 0xff | source[offset + 1]);
}
-
+
public static final void setUInt(final byte[] target, final int offset, final long value) {
assert value < Integer.MAX_VALUE * 2 + 1;
target[offset + 0] = (byte) (value >> 24 & 0xff);
@@ -67,9 +69,13 @@
}
public static final long getUInt(final byte[] source, final int offset) {
- return source[offset + 0] << 24 | source[offset + 1] << 16 | source[offset + 2] << 8 | source[offset + 3];
+ return
+ ((long)(source[offset + 0] & 0xff) << 24 |
+ (source[offset + 1] & 0xff) << 16 |
+ (source[offset + 2] & 0xff) << 8 |
+ (source[offset + 3] & 0xff)) & 0xFFFFFFFFL;
}
-
+
public static final void setInt(final byte[] target, final int offset, final int value) {
assert value < Integer.MAX_VALUE * 2 + 1;
target[offset + 0] = (byte) (value >> 24 & 0xff);
@@ -79,9 +85,13 @@
}
public static final int getInt(final byte[] source, final int offset) {
- return source[offset + 0] << 3 | source[offset + 1] << 2 | source[offset + 2] << 1 | source[offset + 3];
+ return
+ (source[offset + 0] & 0xff) << 24 |
+ (source[offset + 1] & 0xff) << 16 |
+ (source[offset + 2] & 0xff) << 8 |
+ (source[offset + 3] & 0xff);
}
-
+
public static final void setLong(final byte[] target, final int offset, final long value) {
assert value < Integer.MAX_VALUE * 2 + 1;
target[offset + 0] = (byte) (value >> 56 & 0xff);
@@ -96,26 +106,26 @@
public static final long getLong(final byte[] source, final int offset) {
long rc =
- (int) source[offset + 0] << 56 |
- (int) source[offset + 1] << 48 |
- (int) source[offset + 2] << 40 |
- (int) source[offset + 3] << 32 |
- (int) source[offset + 4] << 24 |
- (int) source[offset + 5] << 16 |
- (int) source[offset + 6] << 8 |
- (int) source[offset + 7];
-
+ ((long) (source[offset + 0] & 0xff) << 56) |
+ ((long) (source[offset + 1] & 0xff) << 48) |
+ ((long) (source[offset + 2] & 0xff) << 40) |
+ ((long) (source[offset + 3] & 0xff) << 32) |
+ ((long) (source[offset + 4] & 0xff) << 24) |
+ ((long) (source[offset + 5] & 0xff) << 16) |
+ ((long) (source[offset + 6] & 0xff) << 8) |
+ ((long) (source[offset + 7] & 0xff));
+
return rc;
}
-
+
public static final BigInteger getULong(final byte[] source, final int offset) {
- byte [] bi = new byte [9];
+ byte[] bi = new byte[9];
System.arraycopy(source, offset, bi, 1, 8);
return new BigInteger(bi);
}
-
+
public static final void setULong(final byte[] target, final int offset, final BigInteger value) {
- byte [] b = value.toByteArray();
+ byte[] b = value.toByteArray();
System.arraycopy(b, b.length - 8, target, offset, 8);
}
}