diff options
author | Abyss777 <abyss@fox5.ru> | 2018-06-08 17:04:44 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2018-06-08 17:04:44 +0500 |
commit | c176b7b4bf4eef6f71767f92ada2591ef27c1cfa (patch) | |
tree | fd7ef0e30a4644760154ffc14101749311040d85 /src/org/traccar/protocol/TmgFrameDecoder.java | |
parent | ecb7bb33fcec52491f917dbc65a82990dcddb808 (diff) | |
download | trackermap-server-c176b7b4bf4eef6f71767f92ada2591ef27c1cfa.tar.gz trackermap-server-c176b7b4bf4eef6f71767f92ada2591ef27c1cfa.tar.bz2 trackermap-server-c176b7b4bf4eef6f71767f92ada2591ef27c1cfa.zip |
Migrate part of T protocols
Diffstat (limited to 'src/org/traccar/protocol/TmgFrameDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/TmgFrameDecoder.java | 45 |
1 files changed, 24 insertions, 21 deletions
diff --git a/src/org/traccar/protocol/TmgFrameDecoder.java b/src/org/traccar/protocol/TmgFrameDecoder.java index c39cf03ac..a2039ff52 100644 --- a/src/org/traccar/protocol/TmgFrameDecoder.java +++ b/src/org/traccar/protocol/TmgFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2017 Anton Tananaev (anton@traccar.org) + * Copyright 2017 - 2018 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. @@ -15,34 +15,37 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBufferIndexFinder; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.FrameDecoder; +import org.traccar.BaseFrameDecoder; -public class TmgFrameDecoder extends FrameDecoder { +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; + +public class TmgFrameDecoder extends BaseFrameDecoder { private boolean isLetter(byte c) { return c >= 'a' && c <= 'z'; } - @Override - protected Object decode( - ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception { - - int beginIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new ChannelBufferIndexFinder() { - @Override - public boolean find(ChannelBuffer buffer, int guessedIndex) { - if (buffer.getByte(guessedIndex) != (byte) '$' || buffer.writerIndex() - guessedIndex < 5) { - return false; - } - return buffer.getByte(guessedIndex + 4) == ',' + private int findHeader(ByteBuf buffer) { + int guessedIndex = buffer.indexOf(buffer.readerIndex(), buffer.writerIndex(), (byte) '$'); + while (guessedIndex != -1 && buffer.writerIndex() - guessedIndex >= 5) { + if (buffer.getByte(guessedIndex + 4) == ',' && isLetter(buffer.getByte(guessedIndex + 1)) && isLetter(buffer.getByte(guessedIndex + 2)) - && isLetter(buffer.getByte(guessedIndex + 3)); + && isLetter(buffer.getByte(guessedIndex + 3))) { + return guessedIndex; } - }); + guessedIndex = buffer.indexOf(guessedIndex, buffer.writerIndex(), (byte) '$'); + } + return -1; + } + + @Override + protected Object decode( + ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { + + int beginIndex = findHeader(buf); if (beginIndex >= 0) { @@ -51,7 +54,7 @@ public class TmgFrameDecoder extends FrameDecoder { int endIndex = buf.indexOf(beginIndex, buf.writerIndex(), (byte) '\n'); if (endIndex >= 0) { - ChannelBuffer frame = buf.readBytes(endIndex - beginIndex); + ByteBuf frame = buf.readBytes(endIndex - beginIndex); buf.readByte(); // delimiter return frame; } |