private Disposition readDisposition()

in protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/transport/DispositionTypeDecoder.java [81:133]


    private Disposition readDisposition(ProtonBuffer buffer, Decoder decoder, DecoderState state, ListTypeDecoder listDecoder) throws DecodeException {
        final Disposition disposition = new Disposition();

        @SuppressWarnings("unused")
        final int size = listDecoder.readSize(buffer, state);
        final int count = listDecoder.readCount(buffer, state);

        if (count < MIN_DISPOSITION_LIST_ENTRIES) {
            throw new DecodeException(errorForMissingRequiredFields(count));
        }

        if (count > MAX_DISPOSITION_LIST_ENTRIES) {
            throw new DecodeException("To many entries in Disposition list encoding: " + count);
        }

        for (int index = 0; index < count; ++index) {
            // Peek ahead and see if there is a null in the next slot, if so we don't call
            // the setter for that entry to ensure the returned type reflects the encoded
            // state in the modification entry.
            if (buffer.peekByte() == EncodingCodes.NULL) {
                // Ensure mandatory fields are set
                if (index < MIN_DISPOSITION_LIST_ENTRIES) {
                    throw new DecodeException(errorForMissingRequiredFields(index));
                }

                buffer.advanceReadOffset(1);
                continue;
            }

            switch (index) {
                case 0:
                    disposition.setRole(decoder.readBoolean(buffer, state, false) ? Role.RECEIVER : Role.SENDER);
                    break;
                case 1:
                    disposition.setFirst(decoder.readUnsignedInteger(buffer, state, 0l));
                    break;
                case 2:
                    disposition.setLast(decoder.readUnsignedInteger(buffer, state, 0l));
                    break;
                case 3:
                    disposition.setSettled(decoder.readBoolean(buffer, state, false));
                    break;
                case 4:
                    disposition.setState(decoder.readObject(buffer, state, DeliveryState.class));
                    break;
                case 5:
                    disposition.setBatchable(decoder.readBoolean(buffer, state, false));
                    break;
            }
        }

        return disposition;
    }