private static Object decodeArray()

in protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/primitives/AbstractArrayTypeDecoder.java [88:156]


    private static Object decodeArray(ProtonBuffer buffer, DecoderState state, int count) throws DecodeException {
        final TypeDecoder<?> decoder = state.getDecoder().readNextTypeDecoder(buffer, state);

        if (decoder instanceof PrimitiveTypeDecoder) {
            final PrimitiveTypeDecoder<?> primitiveTypeDecoder = (PrimitiveTypeDecoder<?>) decoder;
            final int typeCode = primitiveTypeDecoder.getTypeCode();

            if (primitiveTypeDecoder.isJavaPrimitive()) {

                if (typeCode != EncodingCodes.BOOLEAN_TRUE && typeCode != EncodingCodes.BOOLEAN_FALSE) {
                    if (count > buffer.getReadableBytes()) {
                        throw new DecodeException(String.format(
                            "Array element count %d is specified to be greater than the amount of data available (%d)",
                            count, buffer.getReadableBytes()));
                    }
                }

                final Class<?> typeClass = decoder.getTypeClass();

                if (Boolean.class.equals(typeClass)) {
                    return decodePrimitiveTypeArray((BooleanTypeDecoder) decoder, buffer, state, count);
                } else if (Byte.class.equals(typeClass)) {
                    return decodePrimitiveTypeArray((ByteTypeDecoder) decoder, buffer, state, count);
                } else if (Short.class.equals(typeClass)) {
                    return decodePrimitiveTypeArray((ShortTypeDecoder) decoder, buffer, state, count);
                } else if (Integer.class.equals(typeClass)) {
                    if (primitiveTypeDecoder.getTypeCode() == (EncodingCodes.INT & 0xff)) {
                        return decodePrimitiveTypeArray((Integer32TypeDecoder) decoder, buffer, state, count);
                    } else {
                        return decodePrimitiveTypeArray((Integer8TypeDecoder) decoder, buffer, state, count);
                    }
                } else if (Long.class.equals(typeClass)) {
                    if (primitiveTypeDecoder.getTypeCode() == (EncodingCodes.LONG & 0xff)) {
                        return decodePrimitiveTypeArray((LongTypeDecoder) decoder, buffer, state, count);
                    } else {
                        return decodePrimitiveTypeArray((Long8TypeDecoder) decoder, buffer, state, count);
                    }
                } else if (Double.class.equals(typeClass)) {
                    return decodePrimitiveTypeArray((DoubleTypeDecoder) decoder, buffer, state, count);
                } else if (Float.class.equals(typeClass)) {
                    return decodePrimitiveTypeArray((FloatTypeDecoder) decoder, buffer, state, count);
                } else if (Character.class.equals(typeClass)) {
                    return decodePrimitiveTypeArray((CharacterTypeDecoder) decoder, buffer, state, count);
                } else {
                    throw new DecodeException("Unexpected class " + decoder.getClass().getName());
                }
            } else if (decoder.isArrayType()) {
                return decodeNonPrimitiveArray(decoder, buffer, state, count);
            } else {
                if (typeCode != EncodingCodes.ULONG0 && typeCode != EncodingCodes.UINT0 && typeCode != EncodingCodes.LIST0) {
                    if (count > buffer.getReadableBytes()) {
                        throw new DecodeException(String.format(
                            "Array element count %d is specified to be greater than the amount of data available (%d)",
                            count, buffer.getReadableBytes()));
                    }
                }

                return decoder.readArrayElements(buffer, state, count);
            }
        } else {
            if (count > buffer.getReadableBytes()) {
                throw new DecodeException(String.format(
                    "Array element count %d is specified to be greater than the amount of data available (%d)",
                    count, buffer.getReadableBytes()));
            }

            return decodeNonPrimitiveArray(decoder, buffer, state, count);
        }
    }