本文整理汇总了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));
}
}
}
示例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);
}
示例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();
}
}