当前位置: 首页>>代码示例>>Java>>正文


Java ChannelBuffer.getUnsignedShort方法代码示例

本文整理汇总了Java中org.jboss.netty.buffer.ChannelBuffer.getUnsignedShort方法的典型用法代码示例。如果您正苦于以下问题:Java ChannelBuffer.getUnsignedShort方法的具体用法?Java ChannelBuffer.getUnsignedShort怎么用?Java ChannelBuffer.getUnsignedShort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jboss.netty.buffer.ChannelBuffer的用法示例。


在下文中一共展示了ChannelBuffer.getUnsignedShort方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    // Strip not '$' (0x24) bytes from the beginning
    while (buf.readable() && buf.getUnsignedByte(buf.readerIndex()) != 0x24) {
        buf.readByte();
    }

    // Check length and return buffer
    if (buf.readableBytes() >= MESSAGE_HEADER) {
        int length = buf.getUnsignedShort(buf.readerIndex() + 2);
        if (buf.readableBytes() >= length) {
            return buf.readBytes(length);
        }
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:20,代码来源:MeiligaoFrameDecoder.java

示例2: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    int indexEnd = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
    if (indexEnd != -1) {
        int indexTilde = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("~"));
        if (indexTilde != -1 && indexTilde < indexEnd) {
            int length = buf.getUnsignedShort(indexTilde + 1);
            indexEnd = buf.indexOf(indexTilde + 2 + length, buf.writerIndex(), new StringFinder("\r\n"));
            if (indexEnd == -1) {
                return null;
            }
        }
        ChannelBuffer frame = buf.readBytes(indexEnd - buf.readerIndex());
        buf.skipBytes(2);
        return frame;
    }
    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:21,代码来源:GranitFrameDecoder.java

示例3: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx,
        Channel channel,
        ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() < 4 + 2) {
        return null;
    }

    int length;
    if (buf.getUnsignedByte(buf.readerIndex()) == 0) {
        length = 2 + buf.getUnsignedShort(buf.readerIndex());
    } else {
        length = 4 + 2 + buf.getUnsignedShort(buf.readerIndex() + 4) + 2;
    }

    if (buf.readableBytes() >= length) {
        return buf.readBytes(length);
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:24,代码来源:NvsFrameDecoder.java

示例4: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    // Check minimum length
    if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
        return null;
    }

    // Check for sync packet
    if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) {
        ChannelBuffer syncMessage = buf.readBytes(8);
        if (channel != null) {
            channel.write(syncMessage);
        }
    }

    return super.decode(ctx, channel, buf);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:19,代码来源:IntellitracFrameDecoder.java

示例5: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx,
        Channel channel,
        ChannelBuffer buf) throws Exception {

    if (header && buf.readableBytes() >= HANDSHAKE_LENGTH) {
        buf.skipBytes(HANDSHAKE_LENGTH);
        header = false;
    }

    int end = 8; // IMEI

    while (buf.readableBytes() >= end + 2 + 1 + 1 + 1) {
        end += buf.getUnsignedShort(buf.readerIndex() + end) + 2;

        if (buf.readableBytes() > end && checksum(buf, end) == buf.getByte(buf.readerIndex() + end)) {
            return buf.readBytes(end + 1);
        }
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:24,代码来源:BceFrameDecoder.java

示例6: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
        return null;
    }

    if (buf.getUnsignedShort(buf.readerIndex()) == 0xFAF8) {
        ChannelBuffer heartbeat = buf.readBytes(12);
        if (channel != null) {
            channel.write(heartbeat);
        }
    }

    return super.decode(ctx, channel, buf);
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:17,代码来源:AlematicsFrameDecoder.java

示例7: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx,
        Channel channel,
        ChannelBuffer buf) throws Exception {

    // Check minimum length
    if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
        return null;
    }

    // Read packet
    int length = buf.getUnsignedShort(buf.readerIndex());
    if (length > 0) {
        if (buf.readableBytes() >= (length + 2)) {
            return buf.readBytes(length + 2);
        }
    } else {
        int dataLength = buf.getInt(buf.readerIndex() + 4);
        if (buf.readableBytes() >= (dataLength + 12)) {
            return buf.readBytes(dataLength + 12);
        }
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:27,代码来源:TeltonikaFrameDecoder.java

示例8: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx,
        Channel channel,
        ChannelBuffer buf) throws Exception {

    // Check minimum length
    if (buf.readableBytes() < MESSAGE_MINIMUM_LENGTH) {
        return null;
    }

    // Read packet
    int length = buf.getUnsignedShort(buf.readerIndex() + 1) & 0x7fff;
    if (buf.readableBytes() >= (length + MESSAGE_MINIMUM_LENGTH)) {
        return buf.readBytes(length + MESSAGE_MINIMUM_LENGTH);
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:20,代码来源:GalileoFrameDecoder.java

示例9: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    // Skip Alive message
    while (buf.readable() && Character.isDigit(buf.getByte(buf.readerIndex()))) {
        buf.readByte();
    }

    // Check minimum length
    if (buf.readableBytes() < 11) {
        return null;
    }

    // Read flags
    int version = buf.getUnsignedByte(buf.readerIndex() + 1);
    int offset = 1 + 1 + 3;
    if ((version & 0x80) != 0) {
        offset += 4;
    }

    // Get data length
    int length = buf.getUnsignedShort(buf.readerIndex() + offset);
    offset += 2;
    if ((version & 0x40) != 0) {
        offset += 3;
    }
    length += offset; // add header

    // Return buffer
    if (buf.readableBytes() >= length) {
        return buf.readBytes(length);
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:37,代码来源:AplicomFrameDecoder.java

示例10: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() < 10) {
        return null;
    }

    char type = (char) buf.getByte(buf.readerIndex());

    if (type == '$') {
        boolean longFormat = buf.getUnsignedByte(buf.readerIndex() + 1) == 0x75;
        int length = buf.getUnsignedShort(buf.readerIndex() + (longFormat ? 8 : 7)) + 10;
        if (length >= buf.readableBytes()) {
            return buf.readBytes(length);
        }
    } else if (type == '(') {
        int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ')');
        if (endIndex != -1) {
            return buf.readBytes(endIndex + 1);
        }
    } else {
        throw new ParseException(null, 0); // unknown message
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:28,代码来源:Jt600FrameDecoder.java

示例11: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() < 5) {
        return null;
    }

    int length = 2 + 2; // head and tail

    if (buf.getByte(buf.readerIndex()) == 0x78) {
        length += 1 + buf.getUnsignedByte(buf.readerIndex() + 2);
    } else {
        length += 2 + buf.getUnsignedShort(buf.readerIndex() + 2);
    }

    if (buf.readableBytes() >= length && buf.getUnsignedShort(buf.readerIndex() + length - 2) == 0x0d0a) {
        return buf.readBytes(length);
    }

    int endIndex = buf.readerIndex() - 1;
    do {
        endIndex = buf.indexOf(endIndex + 1, buf.writerIndex(), (byte) 0x0d);
        if (endIndex > 0 && buf.writerIndex() > endIndex + 1 && buf.getByte(endIndex + 1) == 0x0a) {
            return buf.readBytes(endIndex + 2 - buf.readerIndex());
        }
    } while (endIndex > 0);

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:31,代码来源:Gt06FrameDecoder.java

示例12: decodeCoordinate

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private static double decodeCoordinate(ChannelBuffer buf) {
    double degrees = buf.getUnsignedShort(buf.readerIndex()) / 100;
    double minutes = buf.readUnsignedShort() % 100 + buf.readUnsignedShort() * 0.0001;
    degrees += minutes / 60;
    byte hemisphere = buf.readByte();
    if (hemisphere == 'S' || hemisphere == 'W') {
        degrees = -degrees;
    }
    return degrees;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:11,代码来源:Gps056ProtocolDecoder.java

示例13: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx,
        Channel channel,
        ChannelBuffer buf) throws Exception {

    // Check minimum length
    if (buf.readableBytes() < MESSAGE_HEADER) {
        return null;
    }

    // Check for preamble
    boolean hasPreamble = false;
    if (buf.getUnsignedInt(buf.readerIndex()) == PREAMBLE) {
        hasPreamble = true;
    }

    // Check length and return buffer
    int length = buf.getUnsignedShort(buf.readerIndex() + 6);
    if (buf.readableBytes() >= length) {
        if (hasPreamble) {
            buf.readUnsignedInt();
            length -= 4;
        }
        return buf.readBytes(length);
    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:30,代码来源:NavigilFrameDecoder.java

示例14: decode

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
@Override
protected Object decode(
        ChannelHandlerContext ctx, Channel channel, ChannelBuffer buf) throws Exception {

    if (buf.readableBytes() >= 2) {

        if (buf.getUnsignedShort(buf.readerIndex()) == 0xfe02) {

            if (buf.readableBytes() >= KEEPALIVE_LENGTH) {
                return buf.readBytes(KEEPALIVE_LENGTH);
            }

        } else if (buf.getUnsignedShort(buf.readerIndex()) == 0x4050) {

            if (buf.readableBytes() > 6) {
                int length = buf.getUnsignedShort(buf.readerIndex() + 4) + 4 + 2;
                if (buf.readableBytes() >= length) {
                    return buf.readBytes(length);
                }
            }

        } else {

            int endIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), new StringFinder("\r\n"));
            if (endIndex > 0) {
                return buf.readBytes(endIndex - buf.readerIndex() + 2);
            }

        }

    }

    return null;
}
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:35,代码来源:AtrackFrameDecoder.java

示例15: decodeTcp

import org.jboss.netty.buffer.ChannelBuffer; //导入方法依赖的package包/类
private Object decodeTcp(Channel channel, SocketAddress remoteAddress, ChannelBuffer buf) throws Exception {

        if (buf.getUnsignedShort(0) > 0) {
            parseIdentification(channel, remoteAddress, buf);
        } else {
            buf.skipBytes(4);
            return parseData(channel, remoteAddress, buf, 0);
        }

        return null;
    }
 
开发者ID:bamartinezd,项目名称:traccar-service,代码行数:12,代码来源:TeltonikaProtocolDecoder.java


注:本文中的org.jboss.netty.buffer.ChannelBuffer.getUnsignedShort方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。