From commits-return-13109-apmail-activemq-commits-archive=activemq.apache.org@activemq.apache.org Sun Feb 14 22:40:08 2010 Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 11249 invoked from network); 14 Feb 2010 22:40:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 14 Feb 2010 22:40:08 -0000 Received: (qmail 62439 invoked by uid 500); 14 Feb 2010 22:40:08 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 62381 invoked by uid 500); 14 Feb 2010 22:40:08 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 62372 invoked by uid 99); 14 Feb 2010 22:40:08 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Feb 2010 22:40:08 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 14 Feb 2010 22:40:07 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 609422388A19; Sun, 14 Feb 2010 22:39:47 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r910107 - in /activemq/sandbox/activemq-apollo-actor/activemq-amqp/src: main/java/org/apache/activemq/amqp/protocol/BitUtils.java test/java/org/apache/activemq/amqp/protocol/AmqpProtocolTest.java Date: Sun, 14 Feb 2010 22:39:46 -0000 To: commits@activemq.apache.org From: cmacnaug@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20100214223947.609422388A19@eris.apache.org> Author: cmacnaug Date: Sun Feb 14 22:39:45 2010 New Revision: 910107 URL: http://svn.apache.org/viewvc?rev=910107&view=rev Log: Fixing sign extension problems in bitutils. Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp/src/main/java/org/apache/activemq/amqp/protocol/BitUtils.java activemq/sandbox/activemq-apollo-actor/activemq-amqp/src/test/java/org/apache/activemq/amqp/protocol/AmqpProtocolTest.java Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp/src/main/java/org/apache/activemq/amqp/protocol/BitUtils.java URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp/src/main/java/org/apache/activemq/amqp/protocol/BitUtils.java?rev=910107&r1=910106&r2=910107&view=diff ============================================================================== --- activemq/sandbox/activemq-apollo-actor/activemq-amqp/src/main/java/org/apache/activemq/amqp/protocol/BitUtils.java (original) +++ activemq/sandbox/activemq-apollo-actor/activemq-amqp/src/main/java/org/apache/activemq/amqp/protocol/BitUtils.java Sun Feb 14 22:39:45 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); } } Modified: activemq/sandbox/activemq-apollo-actor/activemq-amqp/src/test/java/org/apache/activemq/amqp/protocol/AmqpProtocolTest.java URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-apollo-actor/activemq-amqp/src/test/java/org/apache/activemq/amqp/protocol/AmqpProtocolTest.java?rev=910107&r1=910106&r2=910107&view=diff ============================================================================== --- activemq/sandbox/activemq-apollo-actor/activemq-amqp/src/test/java/org/apache/activemq/amqp/protocol/AmqpProtocolTest.java (original) +++ activemq/sandbox/activemq-apollo-actor/activemq-amqp/src/test/java/org/apache/activemq/amqp/protocol/AmqpProtocolTest.java Sun Feb 14 22:39:45 2010 @@ -8,11 +8,7 @@ import org.apache.activemq.amqp.protocol.marshaller.AmqpEncodingError; import org.apache.activemq.amqp.protocol.marshaller.AmqpMarshaller; -import org.apache.activemq.amqp.protocol.types.AmqpFlow; -import org.apache.activemq.amqp.protocol.types.AmqpHandle; -import org.apache.activemq.amqp.protocol.types.AmqpOptions; -import org.apache.activemq.amqp.protocol.types.AmqpSequenceNo; -import org.apache.activemq.amqp.protocol.types.AmqpType; +import org.apache.activemq.amqp.protocol.types.*; import org.apache.activemq.amqp.protocol.types.TypeFactory; import static org.apache.activemq.amqp.protocol.types.TypeFactory.*; @@ -26,6 +22,21 @@ assertTrue(val1.equals(val2)); } + public void testAmqpOpen() throws Exception { + AmqpOpen open = createAmqpOpen(); + open.setHeartbeatInterval(60); + open.setChannelMax(1024); + open.setContainerId("TestContainer"); + open.setHostname("localhost"); + open.setDesiredCapabilities(createAmqpList()); + open.setMaxFrameSize(16000); + + AmqpOpen read = marshalUnmarshal(open); + + assertTrue(open.equals(read)); + System.out.println("Value: " + read); + } + public void testAmqpFlow() throws Exception { AmqpFlow flow = createAmqpFlow(); flow.setHandle(1);