List of usage examples for io.netty.buffer ByteBuf readRetainedSlice
public abstract ByteBuf readRetainedSlice(int length);
From source file:org.traccar.protocol.WondexFrameDecoder.java
License:Apache License
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < KEEP_ALIVE_LENGTH) { return null; }// w ww. jav a 2s . c o m if (buf.getUnsignedByte(buf.readerIndex()) == 0xD0) { // Send response ByteBuf frame = buf.readRetainedSlice(KEEP_ALIVE_LENGTH); if (channel != null) { frame.retain(); channel.writeAndFlush(new NetworkMessage(frame, channel.remoteAddress())); } return frame; } else { int index = BufferUtil.indexOf("\r\n", buf); if (index != -1) { ByteBuf frame = buf.readRetainedSlice(index - buf.readerIndex()); buf.skipBytes(2); return frame; } } return null; }
From source file:org.traccar.protocol.XexunFrameDecoder.java
License:Apache License
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < 80) { return null; }/*from w w w.ja v a 2 s . c om*/ int beginIndex = BufferUtil.indexOf("GPRMC", buf); if (beginIndex == -1) { beginIndex = BufferUtil.indexOf("GNRMC", buf); if (beginIndex == -1) { return null; } } int identifierIndex = BufferUtil.indexOf("imei:", buf, beginIndex, buf.writerIndex()); if (identifierIndex == -1) { return null; } int endIndex = buf.indexOf(identifierIndex, buf.writerIndex(), (byte) ','); if (endIndex == -1) { return null; } buf.skipBytes(beginIndex - buf.readerIndex()); return buf.readRetainedSlice(endIndex - beginIndex + 1); }