diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-26 11:38:04 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-26 11:38:04 +1300 |
commit | 511b1807da62c225afc70d45f6eb047382d242a9 (patch) | |
tree | 1a7bd7776d34ab65e8608bbec6ba4f4793c6660f /src/org/traccar/protocol | |
parent | a1081fad2f0b4fa1668ee2eb175d7c71fcc8ae8c (diff) | |
download | trackermap-server-511b1807da62c225afc70d45f6eb047382d242a9.tar.gz trackermap-server-511b1807da62c225afc70d45f6eb047382d242a9.tar.bz2 trackermap-server-511b1807da62c225afc70d45f6eb047382d242a9.zip |
Modify Totem frame decoder
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r-- | src/org/traccar/protocol/TotemFrameDecoder.java | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/src/org/traccar/protocol/TotemFrameDecoder.java b/src/org/traccar/protocol/TotemFrameDecoder.java index 0b1a3e7c2..c6309b8d6 100644 --- a/src/org/traccar/protocol/TotemFrameDecoder.java +++ b/src/org/traccar/protocol/TotemFrameDecoder.java @@ -21,29 +21,25 @@ import org.jboss.netty.channel.Channel; import org.jboss.netty.channel.ChannelHandlerContext; import org.jboss.netty.handler.codec.frame.FrameDecoder; import org.traccar.helper.ChannelBufferTools; +import org.traccar.helper.StringFinder; public class TotemFrameDecoder 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 if (buf.readableBytes() < 10) { return null; } - // Find start - Integer beginIndex = ChannelBufferTools.find(buf, buf.readerIndex(), "$$"); - if (beginIndex == null) { + int beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("$$")); + if (beginIndex == -1) { return null; } else if (beginIndex > buf.readerIndex()) { buf.readerIndex(beginIndex); } - // Read message int length = Integer.parseInt(buf.toString(buf.readerIndex() + 2, 2, Charset.defaultCharset()), 16); if (length <= buf.readableBytes()) { return buf.readBytes(length); |