Example usage for io.netty.buffer ByteBuf getShortLE

List of usage examples for io.netty.buffer ByteBuf getShortLE

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf getShortLE.

Prototype

public abstract short getShortLE(int index);

Source Link

Document

Gets a 16-bit short integer at the specified absolute index in this buffer in Little Endian Byte Order.

Usage

From source file:org.apache.activemq.artemis.utils.AbstractByteBufPool.java

License:Apache License

private static int byteBufHashCode(final ByteBuf byteBuf, final int offset, final int length) {
    final int intCount = length >>> 1;
    final int byteCount = length & 1;
    int hashCode = 1;
    int arrayIndex = offset;
    for (int i = 0; i < intCount; i++) {
        final short shortLE = byteBuf.getShortLE(arrayIndex);
        final short nativeShort = PlatformDependent.BIG_ENDIAN_NATIVE_ORDER ? Short.reverseBytes(shortLE)
                : shortLE;// w  ww .  j a  v  a  2  s . c om
        hashCode = 31 * hashCode + nativeShort;
        arrayIndex += 2;
    }
    for (int i = 0; i < byteCount; i++) {
        hashCode = 31 * hashCode + byteBuf.getByte(arrayIndex++);
    }
    return hashCode;
}

From source file:org.traccar.protocol.SmokeyProtocolDecoder.java

License:Apache License

private static void sendResponse(Channel channel, SocketAddress remoteAddress, ByteBuf id, int index,
        int report) {

    if (channel != null) {
        ByteBuf response = Unpooled.buffer();
        response.writeBytes("SM".getBytes(StandardCharsets.US_ASCII));
        response.writeByte(3); // protocol version
        response.writeByte(MSG_DATE_RECORD_ACK);
        response.writeBytes(id);/*  ww  w  . j  ava 2 s .  co  m*/
        response.writeInt(
                (int) ChronoUnit.SECONDS.between(Instant.parse("2000-01-01T00:00:00.00Z"), Instant.now()));
        response.writeByte(index);
        response.writeByte(report - 0x200);

        short checksum = (short) 0xF5A0;
        for (int i = 0; i < response.readableBytes(); i += 2) {
            checksum ^= response.getShortLE(i);
        }
        response.writeShort(checksum);

        channel.writeAndFlush(new NetworkMessage(response, remoteAddress));
    }
}