From a71dd10a966b491c64232180a2075450f0a258db Mon Sep 17 00:00:00 2001 From: Ivan Muratov Date: Fri, 14 Jul 2017 09:32:52 +0300 Subject: Switch from the unnecessary creating the byte array to direct working with origin buffer. Remove tag value parsing inside case block. --- src/org/traccar/protocol/Arnavi4FrameDecoder.java | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'src/org/traccar/protocol/Arnavi4FrameDecoder.java') diff --git a/src/org/traccar/protocol/Arnavi4FrameDecoder.java b/src/org/traccar/protocol/Arnavi4FrameDecoder.java index 2587420c9..a50ece641 100644 --- a/src/org/traccar/protocol/Arnavi4FrameDecoder.java +++ b/src/org/traccar/protocol/Arnavi4FrameDecoder.java @@ -44,19 +44,16 @@ public class Arnavi4FrameDecoder extends FrameDecoder { return null; } - byte[] bytes = new byte[buf.readableBytes()]; - buf.getBytes(0, bytes); - - if (bytes[0] == HEADER_START_SIGN - && bytes.length == HEADER_LENGTH - && (bytes[1] == HEADER_VERSION_1 || bytes[1] == HEADER_VERSION_2)) { + if (buf.getByte(0) == HEADER_START_SIGN + && buf.readableBytes() == HEADER_LENGTH + && (buf.getByte(1) == HEADER_VERSION_1 || buf.getByte(1) == HEADER_VERSION_2)) { return buf.readBytes(HEADER_LENGTH); } - int parcelNumber = bytes[1] & 0xFF; - if (bytes[0] == PACKAGE_START_SIGN && bytes[bytes.length - 1] == PACKAGE_END_SIGN + int parcelNumber = buf.getByte(1) & 0xFF; + if (buf.getByte(0) == PACKAGE_START_SIGN && buf.getByte(buf.readableBytes() - 1) == PACKAGE_END_SIGN && parcelNumber >= PACKAGE_MIN_PARCEL_NUMBER && parcelNumber <= PACKAGE_MAX_PARCEL_NUMBER) { - return buf.readBytes(bytes.length); + return buf; } return null; -- cgit v1.2.3