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:org.rhq.metrics.netty.collectd.packet.PacketDecodingTest.java

License:Apache License

static ByteBuf createValuesPartBuffer(Values values) {
    Number[] data = values.getData();
    DataType[] dataTypes = values.getDataTypes();
    ByteBuf payloadBuffer = Unpooled.buffer();
    for (int i = 0; i < data.length; i++) {
        payloadBuffer.writeByte(dataTypes[i].getId());
    }//from  w w w.  j  a  va  2  s.  com
    for (int i = 0; i < data.length; i++) {
        DataType dataType = dataTypes[i];
        switch (dataType) {
        case COUNTER:
        case ABSOLUTE:
            BigInteger bigInteger = (BigInteger) data[i];
            payloadBuffer.writeBytes(bigInteger.toByteArray());
            break;
        case DERIVE:
            payloadBuffer.writeLong((Long) data[i]);
            break;
        case GAUGE:
            payloadBuffer.writeLong(ByteBufUtil.swapLong(Double.doubleToLongBits((Double) data[i])));
            break;
        default:
            fail("Unknown data type: " + dataType);
        }
    }

    ByteBuf headerBuffer = Unpooled.buffer();
    headerBuffer.writeShort(VALUES.getId());
    headerBuffer.writeShort(6 + payloadBuffer.writerIndex());
    headerBuffer.writeShort(data.length);

    ByteBuf buffer = Unpooled.buffer();
    buffer.writeBytes(headerBuffer.duplicate()).writeBytes(payloadBuffer.duplicate());
    return buffer;
}

From source file:org.spongepowered.clean.network.packet.play.clientbound.ChunkDataPacket.java

License:MIT License

@Override
public void write(ByteBuf buffer) {
    buffer.writeInt(this.chunk.getBlockMin().getX() >> 4);
    buffer.writeInt(this.chunk.getBlockMin().getZ() >> 4);
    buffer.writeBoolean(this.full);
    if (this.full) {
        this.mask = 0;
        for (int i = 0; i < 16; i++) {
            if (this.chunk.getSections()[i] != null) {
                this.mask |= (1 << i);
            }//from  ww w  .j a  v a  2 s  . c o  m
        }
    } else {
        for (int i = 0; i < 16; i++) {
            if (this.chunk.getSections()[i] == null) {
                this.mask &= ~(1 << i);
            }
        }
    }
    ByteBufUtil.writeVarInt(buffer, this.mask);
    ByteBuf chunkdata = Unpooled.buffer();
    for (int i = 0; i < 16; i++) {
        if (((this.mask >> i) & 1) != 0) {
            ChunkSection section = this.chunk.getSections()[i];
            chunkdata.writeByte(section.getBitsPerBlock());
            if (section.getPalette() == GlobalPalette.instance) {
                ByteBufUtil.writeVarInt(chunkdata, 0);
            } else {
                ByteBufUtil.writeVarInt(chunkdata, section.getPalette().getHighestId() + 1);
                for (int p = 0; p <= section.getPalette().getHighestId(); p++) {
                    BlockState block = section.getPalette().get(p).get();
                    ByteBufUtil.writeVarInt(chunkdata, GlobalPalette.instance.getOrAssign(block));
                }
            }
            long[] data = section.getData();
            ByteBufUtil.writeVarInt(chunkdata, data.length);
            for (int l = 0; l < data.length; l++) {
                chunkdata.writeLong(data[l]);
            }
            // block light
            long[] light = section.getBlockLightData();
            for (int l = 0; l < light.length; l++) {
                chunkdata.writeLong(light[l]);
            }
            if (this.chunk.getWorld().getDimension().getType() == DimensionTypes.OVERWORLD) {
                // sky light
                long[] sky = section.getSkyLightData();
                for (int l = 0; l < sky.length; l++) {
                    chunkdata.writeLong(sky[l]);
                }
            }
        }
    }
    int size = chunkdata.readableBytes();
    if (this.full) {
        size += 256;
    }
    ByteBufUtil.writeVarInt(buffer, size);
    buffer.writeBytes(chunkdata);
    if (this.full) {
        buffer.writeBytes(this.chunk.getBiomeArray());
    }
    ByteBufUtil.writeVarInt(buffer, this.chunk.getTileEntities().size());
    for (TileEntity te : this.chunk.getTileEntities()) {
        DataContainer data = te.toContainer();
        ByteBufUtil.writeNBT(buffer, data);
    }
}

From source file:org.spongepowered.clean.network.packet.play.clientbound.SpawnMobPacket.java

License:MIT License

@Override
public void write(ByteBuf buffer) {
    ByteBufUtil.writeVarInt(buffer, this.entityid);
    buffer.writeLong(this.uid.getMostSignificantBits());
    buffer.writeLong(this.uid.getLeastSignificantBits());
    buffer.writeByte(((SEntityType) this.type).getEntityId());
    buffer.writeDouble(this.x);
    buffer.writeDouble(this.y);
    buffer.writeDouble(this.z);
    buffer.writeByte((byte) Math.floor((this.pitch / 2 * Math.PI) * 256));
    buffer.writeByte((byte) Math.floor((this.yaw / 2 * Math.PI) * 256));
    buffer.writeByte((byte) Math.floor((this.head_pitch / 2 * Math.PI) * 256));
    buffer.writeShort((short) Math.floor(this.vx * 8000));
    buffer.writeShort((short) Math.floor(this.vy * 8000));
    buffer.writeShort((short) Math.floor(this.vz * 8000));
    buffer.writeByte(0xFF);//  w  w w.j a v  a2s. c  om
}

From source file:org.spongepowered.clean.network.packet.play.clientbound.SpawnObjectPacket.java

License:MIT License

@Override
public void write(ByteBuf buffer) {
    ByteBufUtil.writeVarInt(buffer, this.entityid);
    buffer.writeLong(this.uid.getMostSignificantBits());
    buffer.writeLong(this.uid.getLeastSignificantBits());
    buffer.writeByte(((SEntityType) this.type).getEntityId());
    buffer.writeDouble(this.x);
    buffer.writeDouble(this.y);
    buffer.writeDouble(this.z);
    buffer.writeByte((byte) Math.floor((this.pitch / 2 * Math.PI) * 256));
    buffer.writeByte((byte) Math.floor((this.yaw / 2 * Math.PI) * 256));
    buffer.writeInt(this.data);
    buffer.writeShort((short) Math.floor(this.vx * 8000));
    buffer.writeShort((short) Math.floor(this.vy * 8000));
    buffer.writeShort((short) Math.floor(this.vz * 8000));
}

From source file:org.spongepowered.clean.network.packet.play.clientbound.SpawnPaintingPacket.java

License:MIT License

@Override
public void write(ByteBuf buffer) {
    ByteBufUtil.writeVarInt(buffer, this.entityid);
    buffer.writeLong(this.uid.getMostSignificantBits());
    buffer.writeLong(this.uid.getLeastSignificantBits());
    ByteBufUtil.writeString(buffer, this.title);
    ByteBufUtil.writePosition(buffer, this.location);
    ByteBufUtil.writeDirection(buffer, this.direction);
}

From source file:org.spongepowered.clean.network.packet.play.clientbound.SpawnPlayerPacket.java

License:MIT License

@Override
public void write(ByteBuf buffer) {
    ByteBufUtil.writeVarInt(buffer, this.entityid);
    buffer.writeLong(this.uid.getMostSignificantBits());
    buffer.writeLong(this.uid.getLeastSignificantBits());
    buffer.writeDouble(this.x);
    buffer.writeDouble(this.y);
    buffer.writeDouble(this.z);
    buffer.writeByte((byte) Math.floor((this.pitch / 2 * Math.PI) * 256));
    buffer.writeByte((byte) Math.floor((this.yaw / 2 * Math.PI) * 256));
    buffer.writeByte(0xFF);// w  w w. j  a  v  a  2 s. co m
}

From source file:org.spongepowered.clean.network.packet.play.clientbound.TimeUpdatePacket.java

License:MIT License

@Override
public void write(ByteBuf buffer) {
    buffer.writeLong(this.totalTicks);
    buffer.writeLong(this.time);
}

From source file:org.spongepowered.clean.network.packet.status.PongPacket.java

License:MIT License

@Override
public void write(ByteBuf buffer) {
    buffer.writeLong(this.nonce);
}

From source file:org.spongepowered.clean.util.ByteBufUtil.java

License:MIT License

public static void writePosition(ByteBuf buffer, Vector3i location) {
    int x = location.getX();
    int y = location.getY();
    int z = location.getZ();
    buffer.writeLong(((x & 0x3FFFFFF) << 38) | ((y & 0xFFF) << 26) | (z & 0x3FFFFFF));
}

From source file:org.spongepowered.clean.util.ByteBufUtil.java

License:MIT License

public static void writePosition(ByteBuf buffer, int x, int y, int z) {
    buffer.writeLong(((x & 0x3FFFFFF) << 38) | ((y & 0xFFF) << 26) | (z & 0x3FFFFFF));
}