当前位置: 首页>>代码示例>>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;未经允许,请勿转载。