public List readValue()

in proton-j/src/main/java/org/apache/qpid/proton/codec/ListType.java [158:233]


        public List readValue()
        {
            DecoderImpl decoder = getDecoder();
            ReadableBuffer buffer = decoder.getBuffer();

            int size = decoder.readRawInt();
            // todo - limit the decoder with size
            int count = decoder.readRawInt();
            // Ensure we do not allocate an array of size greater then the available data, otherwise there is a risk for an OOM error
            if (count > decoder.getByteBufferRemaining()) {
                throw new IllegalArgumentException("List element count "+count+" is specified to be greater than the amount of data available ("+
                                                   decoder.getByteBufferRemaining()+")");
            }

            TypeConstructor<?> typeConstructor = null;

            List<Object> list = new ArrayList<>(count);
            for (int i = 0; i < count; i++)
            {
                boolean arrayType = false;
                byte encodingCode = buffer.get(buffer.position());
                switch (encodingCode)
                {
                    case EncodingCodes.ARRAY8:
                    case EncodingCodes.ARRAY32:
                        arrayType = true;
                }

                // Whenever we can just reuse the previously used TypeDecoder instead
                // of spending time looking up the same one again.
                if (typeConstructor == null)
                {
                    typeConstructor = getDecoder().readConstructor();
                }
                else
                {
                    if (encodingCode == EncodingCodes.DESCRIBED_TYPE_INDICATOR || !(typeConstructor instanceof PrimitiveTypeEncoding<?>))
                    {
                        typeConstructor = getDecoder().readConstructor();
                    }
                    else
                    {
                        PrimitiveTypeEncoding<?> primitiveConstructor = (PrimitiveTypeEncoding<?>) typeConstructor;
                        if (encodingCode != primitiveConstructor.getEncodingCode())
                        {
                            typeConstructor = getDecoder().readConstructor();
                        }
                        else
                        {
                            // consume the encoding code byte for real
                            encodingCode = buffer.get();
                        }
                    }
                }

                if(typeConstructor == null)
                {
                    throw new DecodeException("Unknown constructor");
                }

                final Object value;

                if (arrayType)
                {
                    value = ((ArrayType.ArrayEncoding) typeConstructor).readValueArray();
                }
                else
                {
                    value = typeConstructor.readValue();
                }

                list.add(value);
            }

            return list;
        }