Search in sources :

Example 6 with SctpMessage

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();
}
Also used : ByteBuf(io.netty.buffer.ByteBuf) SctpMessage(io.netty.channel.sctp.SctpMessage)

Aggregations

ByteBuf (io.netty.buffer.ByteBuf)6 SctpMessage (io.netty.channel.sctp.SctpMessage)6 MessageInfo (com.sun.nio.sctp.MessageInfo)4 ByteBuffer (java.nio.ByteBuffer)4 RecvByteBufAllocator (io.netty.channel.RecvByteBufAllocator)3 SctpChannel (com.sun.nio.sctp.SctpChannel)1 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)1 SelectionKey (java.nio.channels.SelectionKey)1