diff options
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/Jt600FrameDecoder.java | 26 |
1 files changed, 9 insertions, 17 deletions
diff --git a/src/org/traccar/protocol/Jt600FrameDecoder.java b/src/org/traccar/protocol/Jt600FrameDecoder.java index 8b8f4f642..22bbd5514 100644 --- a/src/org/traccar/protocol/Jt600FrameDecoder.java +++ b/src/org/traccar/protocol/Jt600FrameDecoder.java @@ -26,34 +26,26 @@ public class Jt600FrameDecoder extends FrameDecoder { @Override protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - // Check minimum length - int available = buf.readableBytes(); - if (available < 10) { + if (buf.readableBytes() < 10) { return null; } - // Message identifier - char first = (char) buf.getByte(buf.readerIndex()); + char type = (char) buf.getByte(buf.readerIndex()); - if (first == '$') { - // Check length + if (type == '$') { int length = buf.getUnsignedShort(buf.readerIndex() + 7) + 10; - if (length >= available) { + if (length >= buf.readableBytes()) { return buf.readBytes(length); } - } else if (first == '(') { - // Find ending - Integer endIndex = ChannelBufferTools.find(buf, buf.readerIndex(), available, ")"); - if (endIndex != null) { + } else if (type == '(') { + int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')'); + if (endIndex != -1) { return buf.readBytes(endIndex + 1); } } else { - // Unknown message - throw new ParseException(null, 0); + throw new ParseException(null, 0); // unknown message } return null; |