Search in sources :

Example 1 with Decimal64

use of org.apache.qpid.proton.amqp.Decimal64 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

Date (java.util.Date)1 Map (java.util.Map)1 UUID (java.util.UUID)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 UnsignedByte (org.apache.qpid.proton.amqp.UnsignedByte)1 UnsignedInteger (org.apache.qpid.proton.amqp.UnsignedInteger)1 UnsignedLong (org.apache.qpid.proton.amqp.UnsignedLong)1 UnsignedShort (org.apache.qpid.proton.amqp.UnsignedShort)1