Example usage for io.netty.buffer ByteBuf writeLong

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

Introduction

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

Prototype

public abstract ByteBuf writeLong(long value);

Source Link

Document

Sets the specified 64-bit long integer at the current writerIndex and increases the writerIndex by 8 in this buffer.

Usage

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

License:Open Source License

public PacketCompassRequest(final long attunement, final int cx, final int cz, final int cdy) {

    final ByteBuf data = Unpooled.buffer();

    data.writeInt(this.getPacketID());
    data.writeLong(this.attunement = attunement);
    data.writeInt(this.cx = cx);
    data.writeInt(this.cz = cz);
    data.writeInt(this.cdy = cdy);

    this.configureWrite(data);
}

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

License:Open Source License

public PacketCompassResponse(final PacketCompassRequest req, final boolean hasResult, final boolean spin,
        final double radians) {

    final ByteBuf data = Unpooled.buffer();

    data.writeInt(this.getPacketID());
    data.writeLong(this.attunement = req.attunement);
    data.writeInt(this.cx = req.cx);
    data.writeInt(this.cz = req.cz);
    data.writeInt(this.cdy = req.cdy);

    data.writeBoolean(hasResult);/*w w  w.  j a v a 2s . co m*/
    data.writeBoolean(spin);
    data.writeDouble(radians);

    this.configureWrite(data);
}

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

License:Open Source License

public PacketCraftRequest(final int craftAmt, final boolean shift) {
    this.amount = craftAmt;
    this.heldShift = shift;

    final ByteBuf data = Unpooled.buffer();

    data.writeInt(this.getPacketID());
    data.writeBoolean(shift);//from  w  ww .  j ava 2  s  .com
    data.writeLong(this.amount);

    this.configureWrite(data);
}

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

License:Open Source License

public PacketInventoryAction(final InventoryAction action, final int slot, final IAEItemStack slotItem)
        throws IOException {

    if (Platform.isClient()) {
        throw new IllegalStateException("invalid packet, client cannot post inv actions with stacks.");
    }/*from w ww.ja  v a2  s .c  o  m*/

    this.action = action;
    this.slot = slot;
    this.id = 0;
    this.slotItem = slotItem;

    final ByteBuf data = Unpooled.buffer();

    data.writeInt(this.getPacketID());
    data.writeInt(action.ordinal());
    data.writeInt(slot);
    data.writeLong(this.id);

    if (slotItem == null) {
        data.writeBoolean(false);
    } else {
        data.writeBoolean(true);
        slotItem.writeToPacket(data);
    }

    this.configureWrite(data);
}

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

License:Open Source License

public PacketInventoryAction(final InventoryAction action, final int slot, final long id) {
    this.action = action;
    this.slot = slot;
    this.id = id;
    this.slotItem = null;

    final ByteBuf data = Unpooled.buffer();

    data.writeInt(this.getPacketID());
    data.writeInt(action.ordinal());//w w  w.j  a v  a2s. co  m
    data.writeInt(slot);
    data.writeLong(id);
    data.writeBoolean(false);

    this.configureWrite(data);
}

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

License:Open Source License

public PacketProgressBar(final int shortID, final long value) {
    this.id = (short) shortID;
    this.value = value;

    final ByteBuf data = Unpooled.buffer();

    data.writeInt(this.getPacketID());
    data.writeShort(shortID);/*w  w w .j a  v a  2  s  .  c om*/
    data.writeLong(value);

    this.configureWrite(data);
}

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

License:Open Source License

private void putPacketValue(final ByteBuf tag, final long num) {
    if (num <= 255) {
        tag.writeByte((byte) (num + Byte.MIN_VALUE));
    } else if (num <= 65535) {
        tag.writeShort((short) (num + Short.MIN_VALUE));
    } else if (num <= 4294967295L) {
        tag.writeInt((int) (num + Integer.MIN_VALUE));
    } else {/*from   w w w.  j  av  a  2s  .  c  om*/
        tag.writeLong(num);
    }
}

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

License:Mozilla Public License

/**
 * Encode a packet to be read by other nodes.
 *//* w  w  w. j  av a2  s  .c  o m*/
static ByteBuf encodePacket(byte[] typeBytes, long id, ByteBuf payload, Compressor compressor) {
    ByteBuf body = Unpooled.buffer();
    // channel
    writeByteArray(body, typeBytes);
    // payload
    body.writeBytes(payload);

    ByteBuf compressedBody = compressor.encode(body);

    ByteBuf full = Unpooled.buffer();
    // id header
    full.writeLong(id);
    // body
    full.writeBytes(compressedBody);
    return full;
}

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

License:Apache License

private static void writeEncodedSimpleValue(ByteBuf encoded, Object o) {
    if (o == null) {
        encoded.writeByte(OPCODE_NULL_VALUE);
    } else if (o instanceof String) {
        encoded.writeByte(OPCODE_STRING_VALUE);
        writeUTF8String(encoded, (String) o);
    } else if (o instanceof Integer) {
        encoded.writeByte(OPCODE_INT_VALUE);
        encoded.writeInt((Integer) o);
    } else if (o instanceof Long) {
        encoded.writeByte(OPCODE_LONG_VALUE);
        encoded.writeLong((Long) o);
    } else if (o instanceof Set) {
        Set set = (Set) o;
        encoded.writeByte(OPCODE_SET_VALUE);
        encoded.writeInt(set.size());/*from ww  w. ja v a 2  s. c  o m*/
        for (Object o2 : set) {
            writeEncodedSimpleValue(encoded, o2);
        }
    } else if (o instanceof List) {
        List set = (List) o;
        encoded.writeByte(OPCODE_LIST_VALUE);
        encoded.writeInt(set.size());
        for (Object o2 : set) {
            writeEncodedSimpleValue(encoded, o2);
        }

    } else if (o instanceof byte[]) {
        byte[] set = (byte[]) o;
        encoded.writeByte(OPCODE_BYTEARRAY_VALUE);
        encoded.writeInt(set.length);
        encoded.writeBytes(set);
    } else if (o instanceof Map) {
        Map set = (Map) o;
        encoded.writeByte(OPCODE_MAP_VALUE);
        encoded.writeInt(set.size());
        for (Map.Entry entry : (Iterable<Entry>) set.entrySet()) {
            writeEncodedSimpleValue(encoded, entry.getKey());
            writeEncodedSimpleValue(encoded, entry.getValue());
        }
    } else {
        throw new RuntimeException("unsupported class " + o.getClass());
    }
}

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

License:Apache License

private static void writeEncodedSimpleValue(ByteBuf encoded, Object o) {
    if (o == null) {
        encoded.writeByte(OPCODE_NULL_VALUE);
    } else if (o instanceof String) {
        encoded.writeByte(OPCODE_STRING_VALUE);
        writeUTF8String(encoded, (String) o);
    } else if (o instanceof RawString) {
        encoded.writeByte(OPCODE_STRING_VALUE);
        writeUTF8String(encoded, ((RawString) o).toString());
    } else if (o instanceof Integer) {
        encoded.writeByte(OPCODE_INT_VALUE);
        encoded.writeInt((Integer) o);
    } else if (o instanceof Long) {
        encoded.writeByte(OPCODE_LONG_VALUE);
        encoded.writeLong((Long) o);
    } else if (o instanceof Set) {
        Set set = (Set) o;
        encoded.writeByte(OPCODE_SET_VALUE);
        encoded.writeInt(set.size());/*from  w ww . j  ava2s.  co m*/
        for (Object o2 : set) {
            writeEncodedSimpleValue(encoded, o2);
        }
    } else if (o instanceof List) {
        List set = (List) o;
        encoded.writeByte(OPCODE_LIST_VALUE);
        encoded.writeInt(set.size());
        for (Object o2 : set) {
            writeEncodedSimpleValue(encoded, o2);
        }

    } else if (o instanceof byte[]) {
        byte[] set = (byte[]) o;
        encoded.writeByte(OPCODE_BYTEARRAY_VALUE);
        encoded.writeInt(set.length);
        encoded.writeBytes(set);
    } else if (o instanceof Map) {
        Map set = (Map) o;
        encoded.writeByte(OPCODE_MAP_VALUE);
        encoded.writeInt(set.size());
        for (Map.Entry entry : (Iterable<Entry>) set.entrySet()) {
            writeEncodedSimpleValue(encoded, entry.getKey());
            writeEncodedSimpleValue(encoded, entry.getValue());
        }
    } else {
        throw new RuntimeException("unsupported class " + o.getClass());
    }
}