List of usage examples for io.netty.buffer ByteBuf getUnsignedMediumLE
public abstract int getUnsignedMediumLE(int index);
From source file:org.traccar.protocol.At2000FrameDecoder.java
License:Apache License
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < 5) { return null; }//from ww w. ja va2 s.c om int length; if (firstPacket) { firstPacket = false; length = buf.getUnsignedMediumLE(buf.readerIndex() + 2); } else { length = buf.getUnsignedMediumLE(buf.readerIndex() + 1); } length += BLOCK_LENGTH; if (length % BLOCK_LENGTH != 0) { length = (length / BLOCK_LENGTH + 1) * BLOCK_LENGTH; } if ((buf.readableBytes() >= length || buf.readableBytes() % ACK_LENGTH == 0) && (buf != currentBuffer || buf.readableBytes() > acknowledgedBytes)) { sendResponse(channel); currentBuffer = buf; acknowledgedBytes = buf.readableBytes(); } if (buf.readableBytes() >= length) { return buf.readRetainedSlice(length); } return null; }