private Begin readBegin()

in protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/transport/BeginTypeDecoder.java [158:221]


    private Begin readBegin(InputStream stream, StreamDecoder decoder, StreamDecoderState state, ListTypeDecoder listDecoder) throws DecodeException {
        final Begin begin = new Begin();

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

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

        if (count > MAX_BEGIN_LIST_ENTRIES) {
            throw new DecodeException("To many entries in Begin 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_BEGIN_LIST_ENTRIES) {
                        throw new DecodeException(errorForMissingRequiredFields(index));
                    }

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

            switch (index) {
                case 0:
                    begin.setRemoteChannel(decoder.readUnsignedShort(stream, state, 0));
                    break;
                case 1:
                    begin.setNextOutgoingId(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 2:
                    begin.setIncomingWindow(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 3:
                    begin.setOutgoingWindow(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 4:
                    begin.setHandleMax(decoder.readUnsignedInteger(stream, state, 0l));
                    break;
                case 5:
                    begin.setOfferedCapabilities(decoder.readMultiple(stream, state, Symbol.class));
                    break;
                case 6:
                    begin.setDesiredCapabilities(decoder.readMultiple(stream, state, Symbol.class));
                    break;
                case 7:
                    begin.setProperties(decoder.readMap(stream, state));
                    break;
            }
        }

        return begin;
    }