aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/protocol
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-10-09 11:11:31 +1300
committerAnton Tananaev <anton.tananaev@gmail.com>2018-10-09 11:11:31 +1300
commit1264c4cec35c7e26aaaa32362bbf5ab3d97635aa (patch)
treec8d9b88f4051cc6643e2a0263f387d7652f309a5 /src/org/traccar/protocol
parent3226dac7a8831d96a0adbee9740f78693ea601b9 (diff)
downloadtraccar-server-1264c4cec35c7e26aaaa32362bbf5ab3d97635aa.tar.gz
traccar-server-1264c4cec35c7e26aaaa32362bbf5ab3d97635aa.tar.bz2
traccar-server-1264c4cec35c7e26aaaa32362bbf5ab3d97635aa.zip
Simplify Watch frame decoder
Diffstat (limited to 'src/org/traccar/protocol')
-rw-r--r--src/org/traccar/protocol/WatchFrameDecoder.java45
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();