use of io.netty.channel.sctp.SctpMessage in project netty by netty.
the class SctpMessageCompletionHandler method decode.
@Override
protected void decode(ChannelHandlerContext ctx, SctpMessage msg, List<Object> out) throws Exception {
final ByteBuf byteBuf = msg.content();
final int protocolIdentifier = msg.protocolIdentifier();
final int streamIdentifier = msg.streamIdentifier();
final boolean isComplete = msg.isComplete();
final boolean isUnordered = msg.isUnordered();
ByteBuf frag = fragments.remove(streamIdentifier);
if (frag == null) {
frag = Unpooled.EMPTY_BUFFER;
}
if (isComplete && !frag.isReadable()) {
//data chunk is not fragmented
out.add(msg);
} else if (!isComplete && frag.isReadable()) {
//more message to complete
fragments.put(streamIdentifier, Unpooled.wrappedBuffer(frag, byteBuf));
} else if (isComplete && frag.isReadable()) {
//last message to complete
SctpMessage assembledMsg = new SctpMessage(protocolIdentifier, streamIdentifier, isUnordered, Unpooled.wrappedBuffer(frag, byteBuf));
out.add(assembledMsg);
} else {
//first incomplete message
fragments.put(streamIdentifier, byteBuf);
}
byteBuf.retain();
}
Aggregations