diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-09 09:35:25 +1200 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2018-06-09 09:35:25 +1200 |
commit | 4d88fa05bb1b673d676ff92b0b2b53bfba19cece (patch) | |
tree | 8b1241bbddfa6d17691e8318296e26f72e20a982 /src/org/traccar/protocol/TramigoFrameDecoder.java | |
parent | 46274ffddf31d0f09a7c370b2e374f53f6ecc2b6 (diff) | |
download | trackermap-server-4d88fa05bb1b673d676ff92b0b2b53bfba19cece.tar.gz trackermap-server-4d88fa05bb1b673d676ff92b0b2b53bfba19cece.tar.bz2 trackermap-server-4d88fa05bb1b673d676ff92b0b2b53bfba19cece.zip |
Migrate remaining protocols
Diffstat (limited to 'src/org/traccar/protocol/TramigoFrameDecoder.java')
-rw-r--r-- | src/org/traccar/protocol/TramigoFrameDecoder.java | 45 |
1 files changed, 16 insertions, 29 deletions
diff --git a/src/org/traccar/protocol/TramigoFrameDecoder.java b/src/org/traccar/protocol/TramigoFrameDecoder.java index 20992c04b..6c7e639ac 100644 --- a/src/org/traccar/protocol/TramigoFrameDecoder.java +++ b/src/org/traccar/protocol/TramigoFrameDecoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 Anton Tananaev (anton@traccar.org) + * Copyright 2015 - 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,45 +15,32 @@ */ package org.traccar.protocol; -import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; -import org.jboss.netty.channel.Channel; -import org.jboss.netty.channel.ChannelHandlerContext; -import org.jboss.netty.handler.codec.frame.LengthFieldBasedFrameDecoder; +import io.netty.buffer.ByteBuf; +import io.netty.channel.Channel; +import io.netty.channel.ChannelHandlerContext; +import org.traccar.BaseFrameDecoder; -import java.nio.ByteOrder; - -public class TramigoFrameDecoder extends LengthFieldBasedFrameDecoder { - - public TramigoFrameDecoder() { - super(1024, 6, 2, -8, 0); - } +public class TramigoFrameDecoder extends BaseFrameDecoder { @Override - protected Object decode( - ChannelHandlerContext ctx, - Channel channel, - ChannelBuffer buf) throws Exception { + protected Object decode(ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < 20) { return null; } - // Swap byte order for legacy protocol + int length; if (buf.getUnsignedByte(buf.readerIndex()) == 0x80) { - int length = buf.readableBytes(); - byte[] bytes = new byte[length]; - buf.getBytes(buf.readerIndex(), bytes); - - ChannelBuffer result = (ChannelBuffer) super.decode( - ctx, channel, ChannelBuffers.wrappedBuffer(ByteOrder.LITTLE_ENDIAN, bytes)); - if (result != null) { - buf.skipBytes(result.readableBytes()); - } - return result; + length = buf.getUnsignedShort(buf.readerIndex() + 6); + } else { + length = buf.getUnsignedShortLE(buf.readerIndex() + 6); + } + + if (length >= buf.readableBytes()) { + return buf.readBytes(length); } - return super.decode(ctx, channel, buf); + return null; } } |