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:appeng.core.sync.packets.PacketCompassResponse.java

License:Open Source License

public PacketCompassResponse(final ByteBuf stream) {
    this.attunement = stream.readLong();
    this.cx = stream.readInt();
    this.cz = stream.readInt();
    this.cdy = stream.readInt();

    this.cr = new CompassResult(stream.readBoolean(), stream.readBoolean(), stream.readDouble());
}

From source file:appeng.core.sync.packets.PacketCraftRequest.java

License:Open Source License

public PacketCraftRequest(final ByteBuf stream) {
    this.heldShift = stream.readBoolean();
    this.amount = stream.readLong();
}

From source file:appeng.core.sync.packets.PacketInventoryAction.java

License:Open Source License

public PacketInventoryAction(final ByteBuf stream) throws IOException {
    this.action = InventoryAction.values()[stream.readInt()];
    this.slot = stream.readInt();
    this.id = stream.readLong();
    final boolean hasItem = stream.readBoolean();
    if (hasItem) {
        this.slotItem = AEItemStack.loadItemStackFromPacket(stream);
    } else {//from  ww  w.  j  ava  2 s.c om
        this.slotItem = null;
    }
}

From source file:appeng.core.sync.packets.PacketProgressBar.java

License:Open Source License

public PacketProgressBar(final ByteBuf stream) {
    this.id = stream.readShort();
    this.value = stream.readLong();
}

From source file:appeng.util.item.AEStack.java

License:Open Source License

static long getPacketValue(final byte type, final ByteBuf tag) {
    if (type == 0) {
        long l = tag.readByte();
        l -= Byte.MIN_VALUE;/*from  w ww  .jav  a2s .co m*/
        return l;
    } else if (type == 1) {
        long l = tag.readShort();
        l -= Short.MIN_VALUE;
        return l;
    } else if (type == 2) {
        long l = tag.readInt();
        l -= Integer.MIN_VALUE;
        return l;
    }

    return tag.readLong();
}

From source file:at.yawk.accordion.distributed.ConnectionManager.java

License:Mozilla Public License

/**
 * Handle a raw (encoded) message from the given connection.
 *//* w  w w.j  a v  a2 s . c  om*/
private void handleRawMessage(Connection connection, ByteBuf message) {
    int startIndex = message.readerIndex();

    receivedPacketCountIncludingDuplicates.incrementAndGet();

    // read packet ID
    long packetId = message.readLong();
    if (!packetDistinctionHandler.register(packetId)) {
        // already received, do not handle again
        Log.debug(logger, () -> "Duplicate packet " + packetId);
        return;
    }

    // mark heartbeat as alive
    // not doing this before distinction check should be enough because only duplicate packets over 3s is a problem
    // anyway
    heartbeatManager.markAlive(connection);

    receivedPacketCount.incrementAndGet();

    Stream<Connection> forwards = handleDecodedMessage(connection, compressor.decode(message), packetId);

    // reset reader index so we can copy the message
    message.readerIndex(startIndex);
    // forward packet to other connections that listen to this channel
    forwards
            // except the origin of the packet (they already got it)
            .filter(other -> other != connection)
            // send
            .forEach(other -> copyAndSend(other, message));
}

From source file:blazingcache.network.netty.DodoMessageUtils.java

License:Apache License

private static Object readEncodedSimpleValue(ByteBuf encoded) {
    byte _opcode = encoded.readByte();
    switch (_opcode) {
    case OPCODE_NULL_VALUE:
        return null;
    case OPCODE_STRING_VALUE:
        return readUTF8String(encoded);
    case OPCODE_INT_VALUE:
        return encoded.readInt();
    case OPCODE_MAP_VALUE: {
        int len = encoded.readInt();
        Map<Object, Object> ret = new HashMap<>();
        for (int i = 0; i < len; i++) {
            Object mapkey = readEncodedSimpleValue(encoded);
            Object value = readEncodedSimpleValue(encoded);
            ret.put(mapkey, value);//from  w  ww .  j ava 2s .c om
        }
        return ret;
    }
    case OPCODE_SET_VALUE: {
        int len = encoded.readInt();
        Set<Object> ret = new HashSet<>();
        for (int i = 0; i < len; i++) {
            Object o = readEncodedSimpleValue(encoded);
            ret.add(o);
        }
        return ret;
    }
    case OPCODE_LIST_VALUE: {
        int len = encoded.readInt();
        List<Object> ret = new ArrayList<>(len);
        for (int i = 0; i < len; i++) {
            Object o = readEncodedSimpleValue(encoded);
            ret.add(o);
        }
        return ret;
    }
    case OPCODE_BYTEARRAY_VALUE: {
        int len = encoded.readInt();
        byte[] ret = new byte[len];
        encoded.readBytes(ret);
        return ret;
    }
    case OPCODE_LONG_VALUE:
        return encoded.readLong();
    default:
        throw new RuntimeException("invalid opcode: " + _opcode);
    }
}

From source file:blazingcache.network.netty.MessageUtils.java

License:Apache License

private static Object readEncodedSimpleValue(ByteBuf encoded) {
    byte _opcode = encoded.readByte();
    switch (_opcode) {
    case OPCODE_NULL_VALUE:
        return null;
    case OPCODE_STRING_VALUE:
        return RawString.of(readUTF8String(encoded));
    case OPCODE_INT_VALUE:
        return encoded.readInt();
    case OPCODE_MAP_VALUE: {
        int len = encoded.readInt();
        Map<Object, Object> ret = new HashMap<>();
        for (int i = 0; i < len; i++) {
            Object mapkey = readEncodedSimpleValue(encoded);
            Object value = readEncodedSimpleValue(encoded);
            ret.put(mapkey, value);//  w  w  w . j  a v a  2  s.  com
        }
        return ret;
    }
    case OPCODE_SET_VALUE: {
        int len = encoded.readInt();
        Set<Object> ret = new HashSet<>();
        for (int i = 0; i < len; i++) {
            Object o = readEncodedSimpleValue(encoded);
            ret.add(o);
        }
        return ret;
    }
    case OPCODE_LIST_VALUE: {
        int len = encoded.readInt();
        List<Object> ret = new ArrayList<>(len);
        for (int i = 0; i < len; i++) {
            Object o = readEncodedSimpleValue(encoded);
            ret.add(o);
        }
        return ret;
    }
    case OPCODE_BYTEARRAY_VALUE: {
        int len = encoded.readInt();
        byte[] ret = new byte[len];
        encoded.readBytes(ret);
        return ret;
    }
    case OPCODE_LONG_VALUE:
        return encoded.readLong();
    default:
        throw new RuntimeException("invalid opcode: " + _opcode);
    }
}

From source file:books.netty.protocol.netty.codec.NettyMessageDecoder.java

License:Apache License

@Override
protected Object decode(ChannelHandlerContext ctx, ByteBuf in) throws Exception {
    ByteBuf frame = (ByteBuf) super.decode(ctx, in);
    if (frame == null) {
        return null;
    }/*w  w  w .j  a  v  a 2  s. c om*/

    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:books.netty.protocol.netty.codec.TestCodeC.java

License:Apache License

public NettyMessage decode(ByteBuf in) throws Exception {
    NettyMessage message = new NettyMessage();
    Header header = new Header();
    header.setCrcCode(in.readInt());/* w w w  .  ja  v a  2s  .  com*/
    header.setLength(in.readInt());
    header.setSessionID(in.readLong());
    header.setType(in.readByte());
    header.setPriority(in.readByte());

    int size = in.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 = in.readInt();
            keyArray = new byte[keySize];
            in.readBytes(keyArray);
            key = new String(keyArray, "UTF-8");
            attch.put(key, marshallingDecoder.decode(in));
        }
        keyArray = null;
        key = null;
        header.setAttachment(attch);
    }
    if (in.readableBytes() > 4) {
        message.setBody(marshallingDecoder.decode(in));
    }
    message.setHeader(header);
    return message;
}