Example usage for io.netty.buffer ByteBuf readLong

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

Introduction

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

Prototype

public abstract long readLong();

Source Link

Document

Gets a 64-bit integer at the current readerIndex and increases the readerIndex by 8 in this buffer.

Usage

From source file:org.spout.vanilla.protocol.codec.player.PlayerTimeCodec.java

License:Open Source License

@Override
public PlayerTimeMessage decode(ByteBuf buffer) throws IOException {
    return new PlayerTimeMessage(buffer.readLong(), buffer.readLong());
}

From source file:org.starmod.net.object.field.type.NetworkLong.java

License:MIT License

@Override
public void decode(ByteBuf buf) {
    setValue(buf.readLong());
}

From source file:org.starnub.starbounddata.packets.Packet.java

License:Open Source License

/**
 * Recommended: For Plugin Developers & Anyone else.
 * <p>//from w  w  w.  j a  v a 2 s.c o m
 * Uses: This will read a uuid value from a {@link io.netty.buffer.ByteBuf} and advanced the buffer reader index 16 bytes
 * <p>
 *
 * @param in ByteBuf representing the data to be read
 * @return uuid the uuid that was read
 */
public static UUID readUUID(ByteBuf in) {
    long mostSignificantBits = in.readLong();
    long leastSignificantBits = in.readLong();
    return new UUID(mostSignificantBits, leastSignificantBits);
}

From source file:org.starnub.starbounddata.types.celestial.general.CelestialParameters.java

License:Open Source License

@Override
public void read(ByteBuf in) {
    this.coordinate.read(in);
    in.skipBytes(2);//DEBUG Unknown # of bytes - not in SB documents
    this.seed = in.readLong();
    this.name = readVLQString(in);
    this.parameters.read(in);
}

From source file:org.stem.utils.BBUtils.java

License:Apache License

public static UUID readUuid(ByteBuf in) {
    long mostBits = in.readLong();
    long leastBits = in.readLong();
    return new UUID(mostBits, leastBits);
}

From source file:org.tiger.netty.rpc.all.codec.NettyMessageDecoder.java

License:Apache License

@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    System.out.println("NettyMessageDecoder decode ..." + System.currentTimeMillis());
    System.out.println("in>" + in.toString());
    print(in);//from   ww  w.j a va 2  s.com

    System.out.println(in.readableBytes() + ",");
    //LengthFieldBasedFrameDecoder???
    ByteBuf frame = (ByteBuf) super.decode(ctx, in);
    print(frame);
    if (frame == null) {
        return null;
    }

    NettyMessage message = new NettyMessage();
    Header header = new Header();
    header.setCrcCode(frame.readInt());
    header.setLength(frame.readInt());
    header.setSessionID(frame.readLong());
    header.setType(frame.readByte());
    header.setPriority(frame.readByte());

    int size = frame.readInt();
    if (size > 0) {
        Map<String, Object> attch = new HashMap<String, Object>(size);
        int keySize = 0;
        byte[] keyArray = null;
        String key = null;
        for (int i = 0; i < size; i++) {
            keySize = frame.readInt();
            keyArray = new byte[keySize];
            frame.readBytes(keyArray);
            key = new String(keyArray, "UTF-8");
            attch.put(key, marshallingDecoder.decode(frame));
        }
        keyArray = null;
        key = null;
        header.setAttachment(attch);
    }
    if (frame.readableBytes() > 4) {
        message.setBody(marshallingDecoder.decode(frame));
    }
    message.setHeader(header);
    return message;
}

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

License:Apache License

private void decodeEventData(Position position, ByteBuf buf, int event) {
    switch (event) {
    case 2://ww w .  j  a  va 2s . c om
    case 40:
        buf.readUnsignedByte();
        break;
    case 9:
        buf.readUnsignedMedium();
        break;
    case 31:
    case 32:
        buf.readUnsignedShort();
        break;
    case 38:
        buf.skipBytes(4 * 9);
        break;
    case 113:
        buf.readUnsignedInt();
        buf.readUnsignedByte();
        break;
    case 119:
        position.set("eventData",
                ByteBufUtil.hexDump(buf, buf.readerIndex(), Math.min(buf.readableBytes(), 1024)));
        break;
    case 121:
    case 142:
        buf.readLong();
        break;
    case 130:
        buf.readUnsignedInt(); // incorrect
        break;
    case 188:
        decodeEB(position, buf);
        break;
    default:
        break;
    }
}

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

License:Apache License

private void readBinaryCustomData(Position position, ByteBuf buf, String form) {
    CellTower cellTower = new CellTower();
    String[] keys = form.substring(1).split("%");
    for (String key : keys) {
        switch (key) {
        case "SA":
            position.set(Position.KEY_SATELLITES, buf.readUnsignedByte());
            break;
        case "MV":
            position.set(Position.KEY_POWER, buf.readUnsignedShort() * 0.1);
            break;
        case "BV":
            position.set(Position.KEY_BATTERY, buf.readUnsignedShort() * 0.1);
            break;
        case "GQ":
            cellTower.setSignalStrength((int) buf.readUnsignedByte());
            break;
        case "CE":
            cellTower.setCellId(buf.readUnsignedInt());
            break;
        case "LC":
            cellTower.setLocationAreaCode(buf.readUnsignedShort());
            break;
        case "CN":
            int combinedMobileCodes = (int) (buf.readUnsignedInt() % 100000); // cccnn
            cellTower.setMobileCountryCode(combinedMobileCodes / 100);
            cellTower.setMobileNetworkCode(combinedMobileCodes % 100);
            break;
        case "RL":
            buf.readUnsignedByte(); // rxlev
            break;
        case "PC":
            position.set(Position.PREFIX_COUNT + 1, buf.readUnsignedInt());
            break;
        case "AT":
            position.setAltitude(buf.readUnsignedInt());
            break;
        case "RP":
            position.set(Position.KEY_RPM, buf.readUnsignedShort());
            break;
        case "GS":
            position.set(Position.KEY_RSSI, buf.readUnsignedByte());
            break;
        case "DT":
            position.set(Position.KEY_ARCHIVE, buf.readUnsignedByte() == 1);
            break;
        case "VN":
            position.set(Position.KEY_VIN, readString(buf));
            break;
        case "MF":
            buf.readUnsignedShort(); // mass air flow rate
            break;
        case "EL":
            buf.readUnsignedByte(); // engine load
            break;
        case "TR":
            position.set(Position.KEY_THROTTLE, buf.readUnsignedByte());
            break;
        case "ET":
            position.set(Position.PREFIX_TEMP + 1, buf.readUnsignedShort());
            break;
        case "FL":
            position.set(Position.KEY_FUEL_LEVEL, buf.readUnsignedByte());
            break;
        case "ML":
            buf.readUnsignedByte(); // mil status
            break;
        case "FC":
            position.set(Position.KEY_FUEL_CONSUMPTION, buf.readUnsignedInt());
            break;
        case "CI":
            readString(buf); // format string
            break;
        case "AV1":
            position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort());
            break;
        case "NC":
            readString(buf); // gsm neighbor cell info
            break;
        case "SM":
            buf.readUnsignedShort(); // max speed between reports
            break;
        case "GL":
            readString(buf); // google link
            break;
        case "MA":
            readString(buf); // mac address
            break;
        case "PD":
            buf.readUnsignedByte(); // pending code status
            break;
        case "CD":
            readString(buf); // sim cid
            break;
        case "CM":
            buf.readLong(); // imsi
            break;
        case "GN":
            buf.skipBytes(60); // g sensor data
            break;
        case "GV":
            buf.skipBytes(6); // maximum g force
            break;
        case "ME":
            buf.readLong(); // imei
            break;
        case "IA":
            buf.readUnsignedByte(); // intake air temperature
            break;
        case "MP":
            buf.readUnsignedByte(); // manifold absolute pressure
            break;
        default://w w w  .  j av a2  s. com
            break;
        }
    }

    if (cellTower.getMobileCountryCode() != null && cellTower.getMobileNetworkCode() != null
            && cellTower.getCellId() != null && cellTower.getCellId() != 0
            && cellTower.getLocationAreaCode() != null) {
        position.setNetwork(new Network(cellTower));
    } else if (cellTower.getSignalStrength() != null) {
        position.set(Position.KEY_RSSI, cellTower.getSignalStrength());
    }
}

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

License:Apache License

private List<Position> decodeBinary(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {

    buf.skipBytes(2); // prefix
    buf.readUnsignedShort(); // checksum
    buf.readUnsignedShort(); // length
    int index = buf.readUnsignedShort();

    long id = buf.readLong();
    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress, String.valueOf(id));
    if (deviceSession == null) {
        return null;
    }//from   ww w .  j a va2 s  .  c o m

    sendResponse(channel, remoteAddress, id, index);

    List<Position> positions = new LinkedList<>();

    while (buf.readableBytes() >= MIN_DATA_LENGTH) {

        Position position = new Position(getProtocolName());
        position.setDeviceId(deviceSession.getDeviceId());

        if (longDate) {

            DateBuilder dateBuilder = new DateBuilder()
                    .setDate(buf.readUnsignedShort(), buf.readUnsignedByte(), buf.readUnsignedByte())
                    .setTime(buf.readUnsignedByte(), buf.readUnsignedByte(), buf.readUnsignedByte());
            position.setTime(dateBuilder.getDate());

            buf.skipBytes(7 + 7);

        } else {
            position.setFixTime(new Date(buf.readUnsignedInt() * 1000));
            position.setDeviceTime(new Date(buf.readUnsignedInt() * 1000));
            buf.readUnsignedInt(); // send time
        }

        position.setValid(true);
        position.setLongitude(buf.readInt() * 0.000001);
        position.setLatitude(buf.readInt() * 0.000001);
        position.setCourse(buf.readUnsignedShort());

        int type = buf.readUnsignedByte();
        position.set(Position.KEY_TYPE, type);
        position.set(Position.KEY_ALARM, alarmMap.get(type));

        position.set(Position.KEY_ODOMETER, buf.readUnsignedInt() * 100);
        position.set(Position.KEY_HDOP, buf.readUnsignedShort() * 0.1);
        position.set(Position.KEY_INPUT, buf.readUnsignedByte());

        position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedShort()));

        position.set(Position.KEY_OUTPUT, buf.readUnsignedByte());
        position.set(Position.PREFIX_ADC + 1, buf.readUnsignedShort() * 0.001);

        position.set(Position.KEY_DRIVER_UNIQUE_ID, readString(buf));

        position.set(Position.PREFIX_TEMP + 1, buf.readShort() * 0.1);
        position.set(Position.PREFIX_TEMP + 2, buf.readShort() * 0.1);

        String message = readString(buf);
        if (message != null && !message.isEmpty()) {
            Pattern pattern = Pattern.compile("FULS:F=(\\p{XDigit}+) t=(\\p{XDigit}+) N=(\\p{XDigit}+)");
            Matcher matcher = pattern.matcher(message);
            if (matcher.find()) {
                int value = Integer.parseInt(matcher.group(3), decimalFuel ? 10 : 16);
                position.set(Position.KEY_FUEL_LEVEL, value * 0.1);
            } else {
                position.set("message", message);
            }
        }

        if (custom) {
            String form = this.form;
            if (form == null) {
                form = readString(buf).trim().substring("%CI".length());
            }
            readBinaryCustomData(position, buf, form);
        }

        positions.add(position);

    }

    return positions;
}

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

License:Apache License

private List<Position> decodeLocation(Channel channel, SocketAddress remoteAddress, ByteBuf buf) {

    List<Position> positions = new LinkedList<>();

    int type = buf.readUnsignedByte();

    buf.readUnsignedInt(); // mask
    buf.readUnsignedShort(); // length
    buf.readUnsignedByte(); // device type
    buf.readUnsignedShort(); // protocol version
    buf.readUnsignedShort(); // firmware version

    DeviceSession deviceSession = getDeviceSession(channel, remoteAddress,
            String.format("%015d", buf.readLong()));
    if (deviceSession == null) {
        return null;
    }// w  w w .j  a v a2s.  co m

    int battery = buf.readUnsignedByte();
    int power = buf.readUnsignedShort();

    if (type == MSG_RSP_GEO) {
        buf.readUnsignedByte(); // reserved
        buf.readUnsignedByte(); // reserved
    }

    buf.readUnsignedByte(); // motion status
    int satellites = buf.readUnsignedByte();

    if (type != MSG_RSP_COMPRESSED) {
        buf.readUnsignedByte(); // index
    }

    if (type == MSG_RSP_LCB) {
        buf.readUnsignedByte(); // phone length
        for (int b = buf.readUnsignedByte();; b = buf.readUnsignedByte()) {
            if ((b & 0xf) == 0xf || (b & 0xf0) == 0xf0) {
                break;
            }
        }
    }

    if (type == MSG_RSP_COMPRESSED) {

        int count = buf.readUnsignedShort();

        BitBuffer bits;
        int speed = 0;
        int heading = 0;
        int latitude = 0;
        int longitude = 0;
        long time = 0;

        for (int i = 0; i < count; i++) {

            if (time > 0) {
                time += 1;
            }

            Position position = new Position(getProtocolName());
            position.setDeviceId(deviceSession.getDeviceId());

            switch (BitUtil.from(buf.getUnsignedByte(buf.readerIndex()), 8 - 2)) {
            case 1:
                bits = new BitBuffer(buf.readSlice(3));
                bits.readUnsigned(2); // point attribute
                bits.readUnsigned(1); // fix type
                speed = bits.readUnsigned(12);
                heading = bits.readUnsigned(9);
                longitude = buf.readInt();
                latitude = buf.readInt();
                if (time == 0) {
                    time = buf.readUnsignedInt();
                }
                break;
            case 2:
                bits = new BitBuffer(buf.readSlice(5));
                bits.readUnsigned(2); // point attribute
                bits.readUnsigned(1); // fix type
                speed += bits.readSigned(7);
                heading += bits.readSigned(7);
                longitude += bits.readSigned(12);
                latitude += bits.readSigned(11);
                break;
            default:
                buf.readUnsignedByte(); // invalid or same
                continue;
            }

            position.setValid(true);
            position.setTime(new Date(time * 1000));
            position.setSpeed(UnitsConverter.knotsFromKph(speed * 0.1));
            position.setCourse(heading);
            position.setLongitude(longitude * 0.000001);
            position.setLatitude(latitude * 0.000001);

            positions.add(position);

        }

    } else {

        int count = buf.readUnsignedByte();

        for (int i = 0; i < count; i++) {

            Position position = new Position(getProtocolName());
            position.setDeviceId(deviceSession.getDeviceId());

            position.set(Position.KEY_BATTERY_LEVEL, battery);
            position.set(Position.KEY_POWER, power);
            position.set(Position.KEY_SATELLITES, satellites);

            int hdop = buf.readUnsignedByte();
            position.setValid(hdop > 0);
            position.set(Position.KEY_HDOP, hdop);

            position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedMedium() * 0.1));
            position.setCourse(buf.readUnsignedShort());
            position.setAltitude(buf.readShort());
            position.setLongitude(buf.readInt() * 0.000001);
            position.setLatitude(buf.readInt() * 0.000001);

            position.setTime(decodeTime(buf));

            position.setNetwork(new Network(CellTower.from(buf.readUnsignedShort(), buf.readUnsignedShort(),
                    buf.readUnsignedShort(), buf.readUnsignedShort())));

            buf.readUnsignedByte(); // reserved

            positions.add(position);

        }

    }

    return positions;
}