diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-10-09 11:11:31 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-10-09 11:11:31 +1300 |
commit | 1264c4cec35c7e26aaaa32362bbf5ab3d97635aa (patch) | |
tree | c8d9b88f4051cc6643e2a0263f387d7652f309a5 /src | |
parent | 3226dac7a8831d96a0adbee9740f78693ea601b9 (diff) | |
download | trackermap-server-1264c4cec35c7e26aaaa32362bbf5ab3d97635aa.tar.gz trackermap-server-1264c4cec35c7e26aaaa32362bbf5ab3d97635aa.tar.bz2 trackermap-server-1264c4cec35c7e26aaaa32362bbf5ab3d97635aa.zip |
Simplify Watch frame decoder
Diffstat (limited to 'src')
-rw-r--r-- | src/org/traccar/protocol/WatchFrameDecoder.java | 45 |
1 files changed, 8 insertions, 37 deletions
diff --git a/src/org/traccar/protocol/WatchFrameDecoder.java b/src/org/traccar/protocol/WatchFrameDecoder.java index 1e2f0cea3..b2ac5b4f7 100644 --- a/src/org/traccar/protocol/WatchFrameDecoder.java +++ b/src/org/traccar/protocol/WatchFrameDecoder.java @@ -19,9 +19,6 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; - -import java.nio.charset.StandardCharsets; - import org.traccar.BaseFrameDecoder; public class WatchFrameDecoder extends BaseFrameDecoder { @@ -30,53 +27,27 @@ public class WatchFrameDecoder extends BaseFrameDecoder { protected Object decode( ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { - int idIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) '*') + 1; - if (idIndex <= 0) { - return null; - } - - int lengthIndex = buf.indexOf(idIndex, buf.writerIndex(), (byte) '*') + 1; - if (lengthIndex <= 0) { - return null; - } - - int payloadIndex = buf.indexOf(lengthIndex, buf.writerIndex(), (byte) '*'); - if (payloadIndex < 0) { - return null; - } - - if (payloadIndex + 5 < buf.writerIndex() && buf.getByte(payloadIndex + 5) == '*' - && buf.toString(payloadIndex + 1, 4, StandardCharsets.US_ASCII).matches("\\p{XDigit}+")) { - lengthIndex = payloadIndex + 1; - payloadIndex = buf.indexOf(lengthIndex, buf.writerIndex(), (byte) '*'); - if (payloadIndex < 0) { - return null; - } - } - - int length = Integer.parseInt( - buf.toString(lengthIndex, payloadIndex - lengthIndex, StandardCharsets.US_ASCII), 16); - if (buf.readableBytes() >= payloadIndex + 1 + length + 1) { + int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ']') + 1; + if (endIndex > 0) { ByteBuf frame = Unpooled.buffer(); - int endIndex = buf.readerIndex() + payloadIndex + 1 + length + 1; while (buf.readerIndex() < endIndex) { byte b = buf.readByte(); - if (b == 0x7D) { + if (b == '}') { switch (buf.readByte()) { case 0x01: - frame.writeByte(0x7D); + frame.writeByte('}'); break; case 0x02: - frame.writeByte(0x5B); + frame.writeByte('['); break; case 0x03: - frame.writeByte(0x5D); + frame.writeByte(']'); break; case 0x04: - frame.writeByte(0x2C); + frame.writeByte(','); break; case 0x05: - frame.writeByte(0x2A); + frame.writeByte('*'); break; default: throw new IllegalArgumentException(); |