下面列出了io.netty.channel.sctp.SctpMessage#protocolIdentifier ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected final Object filterOutboundMessage(Object msg) throws Exception {
if (msg instanceof SctpMessage) {
SctpMessage m = (SctpMessage) msg;
ByteBuf buf = m.content();
if (buf.isDirect() && buf.nioBufferCount() == 1) {
return m;
}
return new SctpMessage(m.protocolIdentifier(), m.streamIdentifier(), m.isUnordered(),
newDirectBuffer(m, buf));
}
throw new UnsupportedOperationException(
"unsupported message type: " + StringUtil.simpleClassName(msg) +
" (expected: " + StringUtil.simpleClassName(SctpMessage.class));
}
@Override
protected final Object filterOutboundMessage(Object msg) throws Exception {
if (msg instanceof SctpMessage) {
SctpMessage m = (SctpMessage) msg;
ByteBuf buf = m.content();
if (buf.isDirect() && buf.nioBufferCount() == 1) {
return m;
}
return new SctpMessage(m.protocolIdentifier(), m.streamIdentifier(), newDirectBuffer(m, buf));
}
throw new UnsupportedOperationException(
"unsupported message type: " + StringUtil.simpleClassName(msg) +
" (expected: " + StringUtil.simpleClassName(SctpMessage.class));
}
@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();
}
@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();
ByteBuf frag;
if (fragments.containsKey(streamIdentifier)) {
frag = fragments.remove(streamIdentifier);
} else {
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
fragments.remove(streamIdentifier);
SctpMessage assembledMsg = new SctpMessage(
protocolIdentifier,
streamIdentifier,
Unpooled.wrappedBuffer(frag, byteBuf));
out.add(assembledMsg);
} else {
//first incomplete message
fragments.put(streamIdentifier, byteBuf);
}
byteBuf.retain();
}
protected boolean acceptInboundMessage(SctpMessage msg) {
return msg.protocolIdentifier() == protocolIdentifier && msg.streamIdentifier() == streamIdentifier;
}
protected boolean acceptInboundMessage(SctpMessage msg) {
return msg.protocolIdentifier() == protocolIdentifier && msg.streamIdentifier() == streamIdentifier;
}