use of org.apache.qpid.proton.amqp.UnsignedShort 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);
}
use of org.apache.qpid.proton.amqp.UnsignedShort 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());
}
}
use of org.apache.qpid.proton.amqp.UnsignedShort 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()));
}
Aggregations