in protonj2/src/main/java/org/apache/qpid/protonj2/codec/decoders/transport/AttachTypeDecoder.java [181:262]
private Attach readAttach(InputStream stream, StreamDecoder decoder, StreamDecoderState state, ListTypeDecoder listDecoder) throws DecodeException {
final Attach attach = new Attach();
@SuppressWarnings("unused")
final int size = listDecoder.readSize(stream, state);
final int count = listDecoder.readCount(stream, state);
if (count < MIN_ATTACH_LIST_ENTRIES) {
throw new DecodeException(errorForMissingRequiredFields(count));
}
if (count > MAX_ATTACH_LIST_ENTRIES) {
throw new DecodeException("To many entries in Attach 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 < MIN_ATTACH_LIST_ENTRIES) {
throw new DecodeException(errorForMissingRequiredFields(index));
}
continue;
} else {
ProtonStreamUtils.reset(stream);
}
}
switch (index) {
case 0:
attach.setName(decoder.readString(stream, state));
break;
case 1:
attach.setHandle(decoder.readUnsignedInteger(stream, state, 0l));
break;
case 2:
attach.setRole(decoder.readBoolean(stream, state, false) ? Role.RECEIVER : Role.SENDER);
break;
case 3:
attach.setSenderSettleMode(SenderSettleMode.valueOf(decoder.readUnsignedByte(stream, state, (byte) 2)));
break;
case 4:
attach.setReceiverSettleMode(ReceiverSettleMode.valueOf(decoder.readUnsignedByte(stream, state, (byte) 0)));
break;
case 5:
attach.setSource(decoder.readObject(stream, state, Source.class));
break;
case 6:
attach.setTarget(decoder.readObject(stream, state, Terminus.class));
break;
case 7:
attach.setUnsettled(decoder.readMap(stream, state));
break;
case 8:
attach.setIncompleteUnsettled(decoder.readBoolean(stream, state, true));
break;
case 9:
attach.setInitialDeliveryCount(decoder.readUnsignedInteger(stream, state, 0l));
break;
case 10:
attach.setMaxMessageSize(decoder.readUnsignedLong(stream, state));
break;
case 11:
attach.setOfferedCapabilities(decoder.readMultiple(stream, state, Symbol.class));
break;
case 12:
attach.setDesiredCapabilities(decoder.readMultiple(stream, state, Symbol.class));
break;
case 13:
attach.setProperties(decoder.readMap(stream, state));
break;
}
}
return attach;
}