List of usage examples for io.netty.buffer ByteBuf getUnsignedShortLE
public abstract int getUnsignedShortLE(int index);
From source file:org.traccar.protocol.RoboTrackFrameDecoder.java
License:Apache License
private int messageLength(ByteBuf buf) { switch (buf.getUnsignedByte(buf.readerIndex())) { case RoboTrackProtocolDecoder.MSG_ID: return 69; case RoboTrackProtocolDecoder.MSG_ACK: return 3; case RoboTrackProtocolDecoder.MSG_GPS: case RoboTrackProtocolDecoder.MSG_GSM: case RoboTrackProtocolDecoder.MSG_IMAGE_START: return 24; case RoboTrackProtocolDecoder.MSG_IMAGE_DATA: return 8 + buf.getUnsignedShortLE(buf.readerIndex() + 1); case RoboTrackProtocolDecoder.MSG_IMAGE_END: return 6; default:/*from w w w . j a va 2 s .co m*/ return Integer.MAX_VALUE; } }
From source file:org.traccar.protocol.TramigoFrameDecoder.java
License:Apache License
@Override protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < 20) { return null; }/*from w w w .j a v a 2 s.co m*/ int length; if (buf.getUnsignedByte(buf.readerIndex()) == 0x80) { length = buf.getUnsignedShortLE(buf.readerIndex() + 6); } else { length = buf.getUnsignedShort(buf.readerIndex() + 6); } if (length >= buf.readableBytes()) { return buf.readRetainedSlice(length); } return null; }