private Flow readFlow()

in protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/transport/FlowTypeDecoder.java [168:241]


    private Flow readFlow(InputStream stream, StreamDecoder decoder, StreamDecoderState state, ListTypeDecoder listDecoder) throws DecodeException {
        final Flow flow = new Flow();

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

        // Don't decode anything if things already look wrong.
        if (count < MIN_FLOW_LIST_ENTRIES) {
            throw new DecodeException(errorForMissingRequiredFields(count));
        }

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

        for (int index = 0; index < count; ++index) {
            // If the stream allows we 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 (stream.markSupported()) {
                stream.mark(1);
                final boolean nullValue = ProtonStreamUtils.readByte(stream) == EncodingCodes.NULL;
                if (nullValue) {
                    // Ensure mandatory fields are set
                    if (index > 0 && index < MIN_FLOW_LIST_ENTRIES) {
                        throw new DecodeException(errorForMissingRequiredFields(index));
                    }

                    continue;
                } else {
                    ProtonStreamUtils.reset(stream);
                }
            }

            switch (index) {
                case 0:
                    flow.setNextIncomingId(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 1:
                    flow.setIncomingWindow(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 2:
                    flow.setNextOutgoingId(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 3:
                    flow.setOutgoingWindow(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 4:
                    flow.setHandle(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 5:
                    flow.setDeliveryCount(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 6:
                    flow.setLinkCredit(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 7:
                    flow.setAvailable(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 8:
                    flow.setDrain(decoder.readBoolean(stream, state, false));
                    break;
                case 9:
                    flow.setEcho(decoder.readBoolean(stream, state, false));
                    break;
                case 10:
                    flow.setProperties(decoder.readMap(stream, state));
                    break;
            }
        }

        return flow;
    }