aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2020-07-13 20:36:13 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2020-07-13 20:36:13 -0700
commitef52b738c452023472e00ef2aea75822777c5a9d (patch)
tree3a746fe77081fbaa27bda456b387a1e9a79b0b1b /src
parent2507a8183ff78cc75dea82327523d9e151d95920 (diff)
downloadtrackermap-server-ef52b738c452023472e00ef2aea75822777c5a9d.tar.gz
trackermap-server-ef52b738c452023472e00ef2aea75822777c5a9d.tar.bz2
trackermap-server-ef52b738c452023472e00ef2aea75822777c5a9d.zip
Improve eSky frame decoder
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/traccar/protocol/EskyFrameDecoder.java20
-rw-r--r--src/test/java/org/traccar/protocol/EskyFrameDecoderTest.java3
2 files changed, 15 insertions, 8 deletions
diff --git a/src/main/java/org/traccar/protocol/EskyFrameDecoder.java b/src/main/java/org/traccar/protocol/EskyFrameDecoder.java
index da24c1273..a374f29b1 100644
--- a/src/main/java/org/traccar/protocol/EskyFrameDecoder.java
+++ b/src/main/java/org/traccar/protocol/EskyFrameDecoder.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2017 - 2018 Anton Tananaev (anton@traccar.org)
+ * Copyright 2017 - 2020 Anton Tananaev (anton@traccar.org)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -26,14 +26,18 @@ public class EskyFrameDecoder extends BaseFrameDecoder {
protected Object decode(
ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception {
- buf.readerIndex(buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 'E'));
-
- int endIndex = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 'E');
- if (endIndex > 0) {
- return buf.readRetainedSlice(endIndex - buf.readerIndex());
- } else {
- return buf.readRetainedSlice(buf.readableBytes()); // assume full frame
+ int startIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) 'E');
+ if (startIndex >= 0) {
+ buf.readerIndex(startIndex);
+ int endIndex = buf.indexOf(buf.readerIndex() + 1, buf.writerIndex(), (byte) 'E');
+ if (endIndex > 0) {
+ return buf.readRetainedSlice(endIndex - buf.readerIndex());
+ } else {
+ return buf.readRetainedSlice(buf.readableBytes()); // assume full frame
+ }
}
+
+ return null;
}
}
diff --git a/src/test/java/org/traccar/protocol/EskyFrameDecoderTest.java b/src/test/java/org/traccar/protocol/EskyFrameDecoderTest.java
index ed587e4f3..20b5dfcd5 100644
--- a/src/test/java/org/traccar/protocol/EskyFrameDecoderTest.java
+++ b/src/test/java/org/traccar/protocol/EskyFrameDecoderTest.java
@@ -10,6 +10,9 @@ public class EskyFrameDecoderTest extends ProtocolTest {
EskyFrameDecoder decoder = new EskyFrameDecoder();
+ verifyNull(
+ decoder.decode(null, null, binary("00")));
+
verifyFrame(
binary("454f3b303b3836313331313030363436313930383b523b363b3138303432303130343735313b322e39373839363b3130312e36353039313b302e37353b3332303b333339383b313b7c"),
decoder.decode(null, null, binary("454f3b303b3836313331313030363436313930383b523b363b3138303432303130343735313b322e39373839363b3130312e36353039313b302e37353b3332303b333339383b313b7c")));