Search in sources :

Example 1 with UnsignedByte

use of org.apache.qpid.proton.amqp.UnsignedByte in project activemq-artemis by apache.

the class AmqpManagementTest method testUnsignedValues.

/**
 * Some clients use Unsigned types from org.apache.qpid.proton.amqp
 * @throws Exception
 */
@Test(timeout = 60000)
public void testUnsignedValues() throws Exception {
    int sequence = 42;
    LinkedHashMap<String, Object> map = new LinkedHashMap<>();
    map.put("sequence", new UnsignedInteger(sequence));
    ServerJMSMapMessage msg = createMapMessage(1, map, null);
    assertEquals(msg.getInt("sequence"), sequence);
    map.clear();
    map.put("sequence", new UnsignedLong(sequence));
    msg = createMapMessage(1, map, null);
    assertEquals(msg.getLong("sequence"), sequence);
    map.clear();
    map.put("sequence", new UnsignedShort((short) sequence));
    msg = createMapMessage(1, map, null);
    assertEquals(msg.getShort("sequence"), sequence);
    map.clear();
    map.put("sequence", new UnsignedByte((byte) sequence));
    msg = createMapMessage(1, map, null);
    assertEquals(msg.getByte("sequence"), sequence);
}
Also used : UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) ServerJMSMapMessage(org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) UnsignedByte(org.apache.qpid.proton.amqp.UnsignedByte) LinkedHashMap(java.util.LinkedHashMap) UnsignedShort(org.apache.qpid.proton.amqp.UnsignedShort) Test(org.junit.Test)

Example 2 with UnsignedByte

use of org.apache.qpid.proton.amqp.UnsignedByte in project activemq-artemis by apache.

the class ServerJMSMapMessage method setObject.

@Override
public void setObject(final String name, final Object value) throws JMSException {
    try {
        // primitives and String
        Object val = value;
        if (value instanceof UnsignedInteger) {
            val = ((UnsignedInteger) value).intValue();
        } else if (value instanceof UnsignedShort) {
            val = ((UnsignedShort) value).shortValue();
        } else if (value instanceof UnsignedByte) {
            val = ((UnsignedByte) value).byteValue();
        } else if (value instanceof UnsignedLong) {
            val = ((UnsignedLong) value).longValue();
        }
        TypedProperties.setObjectProperty(new SimpleString(name), val, map);
    } catch (ActiveMQPropertyConversionException e) {
        throw new MessageFormatException(e.getMessage());
    }
}
Also used : MessageFormatException(javax.jms.MessageFormatException) UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) UnsignedByte(org.apache.qpid.proton.amqp.UnsignedByte) ActiveMQPropertyConversionException(org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException) UnsignedShort(org.apache.qpid.proton.amqp.UnsignedShort)

Example 3 with UnsignedByte

use of org.apache.qpid.proton.amqp.UnsignedByte in project azure-service-bus-java by Azure.

the class Util method sizeof.

static int sizeof(Object obj) {
    if (obj == null) {
        return 0;
    }
    if (obj instanceof String) {
        return obj.toString().length() << 1;
    }
    if (obj instanceof Symbol) {
        return ((Symbol) obj).length() << 1;
    }
    if (obj instanceof Byte || obj instanceof UnsignedByte) {
        return Byte.BYTES;
    }
    if (obj instanceof Integer || obj instanceof UnsignedInteger) {
        return Integer.BYTES;
    }
    if (obj instanceof Long || obj instanceof UnsignedLong || obj instanceof Date) {
        return Long.BYTES;
    }
    if (obj instanceof Short || obj instanceof UnsignedShort) {
        return Short.BYTES;
    }
    if (obj instanceof Character) {
        return 4;
    }
    if (obj instanceof Float) {
        return Float.BYTES;
    }
    if (obj instanceof Double) {
        return Double.BYTES;
    }
    if (obj instanceof UUID) {
        // return 72;
        return 16;
    }
    if (obj instanceof Decimal32) {
        return 4;
    }
    if (obj instanceof Decimal64) {
        return 8;
    }
    if (obj instanceof Decimal128) {
        return 16;
    }
    if (obj instanceof Binary) {
        return ((Binary) obj).getLength();
    }
    if (obj instanceof Map) {
        // Size and Count each take a max of 4 bytes
        int size = 8;
        Map map = (Map) obj;
        for (Object value : map.keySet()) {
            size += Util.sizeof(value);
        }
        for (Object value : map.values()) {
            size += Util.sizeof(value);
        }
        return size;
    }
    if (obj instanceof Iterable) {
        // Size and Count each take a max of 4 bytes
        int size = 8;
        for (Object innerObject : (Iterable) obj) {
            size += Util.sizeof(innerObject);
        }
        return size;
    }
    if (obj.getClass().isArray()) {
        // Size and Count each take a max of 4 bytes
        int size = 8;
        int length = Array.getLength(obj);
        for (int i = 0; i < length; i++) {
            size += Util.sizeof(Array.get(obj, i));
        }
        return size;
    }
    throw new IllegalArgumentException(String.format(Locale.US, "Encoding Type: %s is not supported", obj.getClass()));
}
Also used : UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) Symbol(org.apache.qpid.proton.amqp.Symbol) Decimal64(org.apache.qpid.proton.amqp.Decimal64) Decimal128(org.apache.qpid.proton.amqp.Decimal128) UnsignedByte(org.apache.qpid.proton.amqp.UnsignedByte) Date(java.util.Date) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) UnsignedByte(org.apache.qpid.proton.amqp.UnsignedByte) Decimal32(org.apache.qpid.proton.amqp.Decimal32) UnsignedLong(org.apache.qpid.proton.amqp.UnsignedLong) Binary(org.apache.qpid.proton.amqp.Binary) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) UUID(java.util.UUID) Map(java.util.Map) UnsignedShort(org.apache.qpid.proton.amqp.UnsignedShort) UnsignedShort(org.apache.qpid.proton.amqp.UnsignedShort)

Aggregations

UnsignedByte (org.apache.qpid.proton.amqp.UnsignedByte)3 UnsignedInteger (org.apache.qpid.proton.amqp.UnsignedInteger)3 UnsignedLong (org.apache.qpid.proton.amqp.UnsignedLong)3 UnsignedShort (org.apache.qpid.proton.amqp.UnsignedShort)3 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 UUID (java.util.UUID)1 MessageFormatException (javax.jms.MessageFormatException)1 ActiveMQPropertyConversionException (org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException)1 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 ServerJMSMapMessage (org.apache.activemq.artemis.protocol.amqp.converter.jms.ServerJMSMapMessage)1 Binary (org.apache.qpid.proton.amqp.Binary)1 Decimal128 (org.apache.qpid.proton.amqp.Decimal128)1 Decimal32 (org.apache.qpid.proton.amqp.Decimal32)1 Decimal64 (org.apache.qpid.proton.amqp.Decimal64)1 Symbol (org.apache.qpid.proton.amqp.Symbol)1 Test (org.junit.Test)1