Example usage for io.netty.buffer ByteBuf writeInt

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

Introduction

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

Prototype

public abstract ByteBuf writeInt(int value);

Source Link

Document

Sets the specified 32-bit integer at the current writerIndex and increases the writerIndex by 4 in this buffer.

Usage

From source file:appeng.parts.p2p.PartP2PLight.java

License:Open Source License

@Override
public void writeToStream(final ByteBuf data) throws IOException {
    super.writeToStream(data);
    data.writeInt(this.isOutput() ? this.lastValue : 0);
}

From source file:appeng.tile.grindstone.TileCrank.java

License:Open Source License

@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileCrank(final ByteBuf data) {
    data.writeInt(this.rotation);
}

From source file:appeng.tile.storage.TileChest.java

License:Open Source License

@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileChest(final ByteBuf data) {
    if (this.worldObj.getTotalWorldTime() - this.lastStateChange > 8) {
        this.state = 0;
    } else {//from  ww  w .  j  ava  2s  . c om
        this.state &= 0x24924924; // just keep the blinks...
    }

    for (int x = 0; x < this.getCellCount(); x++) {
        this.state |= (this.getCellStatus(x) << (3 * x));
    }

    if (this.isPowered()) {
        this.state |= 0x40;
    } else {
        this.state &= ~0x40;
    }

    data.writeByte(this.state);
    data.writeByte(this.paintedColor.ordinal());

    final ItemStack is = this.inv.getStackInSlot(1);

    if (is == null) {
        data.writeInt(0);
    } else {
        data.writeInt((is.getItemDamage() << Platform.DEF_OFFSET) | Item.getIdFromItem(is.getItem()));
    }
}

From source file:appeng.tile.storage.TileDrive.java

License:Open Source License

@TileEvent(TileEventType.NETWORK_WRITE)
public void writeToStream_TileDrive(final ByteBuf data) {
    int newState = 0;

    if (this.getProxy().isActive()) {
        newState |= BIT_POWER_MASK;/*from  w w  w. j  a v  a 2  s.c  om*/
    }

    for (int x = 0; x < this.getCellCount(); x++) {
        newState |= (this.getCellStatus(x) << (3 * x));
    }

    data.writeInt(newState);
}

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

License:Open Source License

@Override
void readNBT(final ByteBuf i) throws IOException {
    if (this.hasTagCompound()) {
        final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        final DataOutputStream data = new DataOutputStream(bytes);

        CompressedStreamTools.write((NBTTagCompound) this.tagCompound, data);

        final byte[] tagBytes = bytes.toByteArray();
        final int size = tagBytes.length;

        i.writeInt(size);
        i.writeBytes(tagBytes);//from  w w w. j  a v  a2 s  . c o  m
    }
}

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

License:Open Source License

@Override
void readNBT(final ByteBuf i) throws IOException {
    if (this.hasTagCompound()) {
        final ByteArrayOutputStream bytes = new ByteArrayOutputStream();
        final DataOutputStream data = new DataOutputStream(bytes);

        CompressedStreamTools.write((NBTTagCompound) this.getTagCompound(), data);

        final byte[] tagBytes = bytes.toByteArray();
        final int size = tagBytes.length;

        i.writeInt(size);
        i.writeBytes(tagBytes);//  w  w w.j ava  2  s .com
    }
}

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  a  v a2  s .  c om*/
        tag.writeLong(num);
    }
}

From source file:at.yawk.accordion.codec.unsafe.ArrayCodec.java

License:Mozilla Public License

@Override
public void encode(ByteBuf target, Object message) {
    int length = Array.getLength(message);
    target.writeInt(length);
    long offset = baseOffset;
    for (int i = 0; i < length; i++) {
        componentCodec.write(target, message, offset);
        offset += indexScale;//w  w w .j  av  a  2 s.co  m
    }
}

From source file:at.yawk.accordion.codec.unsafe.CollectionCodecSupplier.java

License:Mozilla Public License

@SuppressWarnings({ "rawtypes", "unchecked" })
@Override/*  w w w. j a v  a  2 s  .  com*/
protected ByteCodec<C> createCodec(CodecSupplier registry, FieldWrapper field) {
    FieldWrapper componentType = field.genericTypeOrThrow(0);
    ByteCodec componentCodec = registry.getCodecOrThrow(componentType).toByteCodec();

    return new ByteCodec<C>() {
        @Override
        public void encode(ByteBuf target, C message) {
            target.writeInt(message.size());
            for (Object o : message) {
                componentCodec.encode(target, o);
            }
        }

        @Override
        public C decode(ByteBuf encoded) {
            int size = encoded.readInt();
            Collection collection = factory.apply(size);
            for (int i = 0; i < size; i++) {
                collection.add(componentCodec.decode(encoded));
            }
            return (C) collection;
        }
    };
}

From source file:at.yawk.accordion.codec.unsafe.MapCodec.java

License:Mozilla Public License

@Override
protected ByteCodec<M> createCodec(CodecSupplier registry, FieldWrapper field) {
    FieldWrapper keyType = field.genericTypeOrThrow(0);
    ByteCodec keyCodec = registry.getCodecOrThrow(keyType).toByteCodec();
    FieldWrapper valueType = field.genericTypeOrThrow(1);
    ByteCodec valueCodec = registry.getCodecOrThrow(valueType).toByteCodec();

    return new ByteCodec<M>() {
        @Override//from   www . ja va 2 s  .  co  m
        public void encode(ByteBuf target, M message) {
            target.writeInt(message.size());
            for (Map.Entry o : message.entrySet()) {
                keyCodec.encode(target, o.getKey());
                valueCodec.encode(target, o.getValue());
            }
        }

        @Override
        public M decode(ByteBuf encoded) {
            int size = encoded.readInt();
            Map map = factory.apply(size);
            for (int i = 0; i < size; i++) {
                Object k = keyCodec.decode(encoded);
                Object v = valueCodec.decode(encoded);
                map.put(k, v);
            }
            return (M) map;
        }
    };
}