當前位置: 首頁>>代碼示例>>Java>>正文


Java ByteBuf.getShort方法代碼示例

本文整理匯總了Java中io.netty.buffer.ByteBuf.getShort方法的典型用法代碼示例。如果您正苦於以下問題:Java ByteBuf.getShort方法的具體用法?Java ByteBuf.getShort怎麽用?Java ByteBuf.getShort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在io.netty.buffer.ByteBuf的用法示例。


在下文中一共展示了ByteBuf.getShort方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if(logger.isTraceEnabled()) {
        logger.trace("Got Data: {}", ByteBufUtil.hexDump(in));
    }
    // If at least 4 bytes are readable, peek into them (without changing the read position)
    // and get the packet length. Only if the available amount of readable bytes is larger or
    // equal to this, continue processing the rest.
    if(in.readableBytes() >= 4) {
        logger.debug("ISO on TCP Message received");
        // The ISO on TCP protocol is really simple and in this case the buffer length
        // will take care of the higher levels not reading more than is in the packet.
        // So we just gobble up the header and continue reading in higher levels.
        if (in.getByte(0) != ISO_ON_TCP_MAGIC_NUMBER) {
            logger.warn("Expecting ISO on TCP magic number: {}", ISO_ON_TCP_MAGIC_NUMBER);
            logger.debug("Got Data: " + ByteBufUtil.hexDump(in));
            exceptionCaught(ctx, new PlcProtocolException(
                String.format("Expecting ISO on TCP magic number: %02X", ISO_ON_TCP_MAGIC_NUMBER)));
            return;
        }
        // Byte 1 is a reserved byte set to 0x00
        short packetLength = in.getShort(2);
        if(in.readableBytes() >= packetLength) {
            // Skip the 4 bytes we peeked into manually.
            in.skipBytes(4);
            // Simply place the current buffer to the output ... the next handler will continue.
            ByteBuf payload = in.readBytes(packetLength - 4);
            out.add(new IsoOnTcpMessage(payload));
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-plc4x,代碼行數:32,代碼來源:IsoOnTcpProtocol.java

示例2: decode

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
    if (in.readableBytes() < 8) {
        return;
    }

    short dataLen = in.getShort(in.readerIndex() + 6);
    if (in.readableBytes() < dataLen) {
        return;
    }

    ByteBuf msg = in.readRetainedSlice(8 + dataLen);
    out.add(msg);
}
 
開發者ID:szhnet,項目名稱:kcp-netty,代碼行數:15,代碼來源:TcpRttDecoder.java

示例3: channelRead

import io.netty.buffer.ByteBuf; //導入方法依賴的package包/類
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) {
    ByteBuf buf = (ByteBuf) msg;
    short curCount = buf.getShort(buf.readerIndex());
    ctx.writeAndFlush(msg);

    if (curCount == -1) {
        ctx.close();
    }
}
 
開發者ID:szhnet,項目名稱:kcp-netty,代碼行數:11,代碼來源:TcpRttServerHandler.java


注:本文中的io.netty.buffer.ByteBuf.getShort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。