From 4d88fa05bb1b673d676ff92b0b2b53bfba19cece Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sat, 9 Jun 2018 09:35:25 +1200 Subject: Migrate remaining protocols --- src/org/traccar/protocol/TramigoFrameDecoder.java | 45 ++++++++--------------- 1 file changed, 16 insertions(+), 29 deletions(-) (limited to 'src/org/traccar/protocol/TramigoFrameDecoder.java') 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; } } -- cgit v1.2.3