aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/traccar
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2021-05-11 21:16:25 -0700
committerAnton Tananaev <anton.tananaev@gmail.com>2021-05-11 21:16:25 -0700
commita72d9910a7eafbd01c7b730dc94063727a781a6b (patch)
treef828776a8b8e66958c21bddbe4e9c6ca767b24fd /src/main/java/org/traccar
parent056b1cfb785aa106b62f791b9476002471c2a8c3 (diff)
downloadtrackermap-server-a72d9910a7eafbd01c7b730dc94063727a781a6b.tar.gz
trackermap-server-a72d9910a7eafbd01c7b730dc94063727a781a6b.tar.bz2
trackermap-server-a72d9910a7eafbd01c7b730dc94063727a781a6b.zip
Fix command encoding
Diffstat (limited to 'src/main/java/org/traccar')
-rw-r--r--src/main/java/org/traccar/protocol/TaipPrefixEncoder.java (renamed from src/main/java/org/traccar/protocol/TaipStringEncoder.java)17
-rw-r--r--src/main/java/org/traccar/protocol/TaipProtocol.java7
2 files changed, 11 insertions, 13 deletions
diff --git a/src/main/java/org/traccar/protocol/TaipStringEncoder.java b/src/main/java/org/traccar/protocol/TaipPrefixEncoder.java
index 6af35937c..b690c176d 100644
--- a/src/main/java/org/traccar/protocol/TaipStringEncoder.java
+++ b/src/main/java/org/traccar/protocol/TaipPrefixEncoder.java
@@ -24,29 +24,24 @@ import org.traccar.Context;
import org.traccar.Protocol;
import org.traccar.config.Keys;
-import java.nio.charset.StandardCharsets;
import java.util.List;
@ChannelHandler.Sharable
-public class TaipStringEncoder extends MessageToMessageEncoder<CharSequence> {
+public class TaipPrefixEncoder extends MessageToMessageEncoder<ByteBuf> {
private final Protocol protocol;
- public TaipStringEncoder(Protocol protocol) {
+ public TaipPrefixEncoder(Protocol protocol) {
this.protocol = protocol;
}
@Override
- protected void encode(ChannelHandlerContext ctx, CharSequence msg, List<Object> out) throws Exception {
- if (msg.length() == 0) {
- return;
- }
- ByteBuf buf = Unpooled.buffer();
+ protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception {
if (Context.getConfig().getBoolean(Keys.PROTOCOL_PREFIX.withPrefix(protocol.getName()))) {
- buf.writeBytes(new byte[] {0x20, 0x20, 0x06, 0x00});
+ Unpooled.wrappedBuffer(Unpooled.wrappedBuffer(new byte[] {0x20, 0x20, 0x06, 0x00}), msg);
+ } else {
+ out.add(msg);
}
- buf.writeCharSequence(msg, StandardCharsets.US_ASCII);
- out.add(buf);
}
}
diff --git a/src/main/java/org/traccar/protocol/TaipProtocol.java b/src/main/java/org/traccar/protocol/TaipProtocol.java
index 5df9f7d3c..0966cfd7c 100644
--- a/src/main/java/org/traccar/protocol/TaipProtocol.java
+++ b/src/main/java/org/traccar/protocol/TaipProtocol.java
@@ -16,6 +16,7 @@
package org.traccar.protocol;
import io.netty.handler.codec.string.StringDecoder;
+import io.netty.handler.codec.string.StringEncoder;
import org.traccar.BaseProtocol;
import org.traccar.CharacterDelimiterFrameDecoder;
import org.traccar.PipelineBuilder;
@@ -28,16 +29,18 @@ public class TaipProtocol extends BaseProtocol {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
pipeline.addLast(new CharacterDelimiterFrameDecoder(1024, '<'));
+ pipeline.addLast(new TaipPrefixEncoder(TaipProtocol.this));
pipeline.addLast(new StringDecoder());
- pipeline.addLast(new TaipStringEncoder(TaipProtocol.this));
+ pipeline.addLast(new StringEncoder());
pipeline.addLast(new TaipProtocolDecoder(TaipProtocol.this));
}
});
addServer(new TrackerServer(true, getName()) {
@Override
protected void addProtocolHandlers(PipelineBuilder pipeline) {
+ pipeline.addLast(new TaipPrefixEncoder(TaipProtocol.this));
pipeline.addLast(new StringDecoder());
- pipeline.addLast(new TaipStringEncoder(TaipProtocol.this));
+ pipeline.addLast(new StringEncoder());
pipeline.addLast(new TaipProtocolDecoder(TaipProtocol.this));
}
});