Example usage for io.netty.buffer ByteBuf readByte

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

Introduction

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

Prototype

public abstract byte readByte();

Source Link

Document

Gets a byte at the current readerIndex and increases the readerIndex by 1 in this buffer.

Usage

From source file:buildcraft.core.network.serializers.ClassMapping.java

License:Minecraft Mod Public

@SuppressWarnings("rawtypes")
Object readClass(Object objI, ByteBuf data, SerializationContext context) throws IllegalArgumentException,
        IllegalAccessException, InstantiationException, ClassNotFoundException {

    Object obj = objI;//  ww w  . j av  a 2s  . co m

    // The data layout for an object is the following:
    // [boolean] does the object exist (e.g. non-null)
    // {false} exit
    // [int] what is the object real class?
    // {0} the same as the declared class
    // {1-x} a different one
    // [string] if the number is not yet registered, the name of the
    // class
    // [bytes] the actual contents

    int index = data.readByte();

    if (index != 0) {
        ClassMapping delegateMapping;

        if (context.idToClass.size() < index) {
            String className = Utils.readUTF(data);

            Class cls = Class.forName(className);

            delegateMapping = (ClassMapping) get(cls);

            context.idToClass.add(get(cls));
        } else {
            delegateMapping = (ClassMapping) context.idToClass.get(index - 1);
        }

        return delegateMapping.readClass(obj, data, context);
    }

    if (obj == null) {
        obj = mappedClass.newInstance();
    }

    for (Field f : shortFields) {
        f.setShort(obj, data.readShort());
    }

    for (Field f : intFields) {
        f.setInt(obj, data.readInt());
    }

    for (Field f : booleanFields) {
        f.setBoolean(obj, data.readBoolean());
    }

    for (Field f : enumFields) {
        f.set(obj, ((Class) f.getGenericType()).getEnumConstants()[data.readByte()]);
    }

    for (Field f : floatFields) {
        f.setFloat(obj, data.readFloat());
    }

    for (Field f : doubleFields) {
        f.setDouble(obj, data.readDouble());
    }

    for (FieldObject f : objectFields) {
        f.field.set(obj, f.mapping.read(data, f.field.get(obj), context));
    }

    return obj;
}

From source file:buildcraft.core.network.serializers.SerializerObject.java

License:Minecraft Mod Public

@Override
public Object read(ByteBuf data, Object o, SerializationContext context) throws IllegalArgumentException,
        IllegalAccessException, InstantiationException, ClassNotFoundException {

    if (!data.readBoolean()) {
        return null;
    } else {// w w  w  .  j a  va 2 s.c  o m
        int index = data.readByte();

        ClassSerializer delegateMapping;

        if (context.idToClass.size() < index) {
            String className = Utils.readUTF(data);

            Class cls = Class.forName(className);
            delegateMapping = ClassMapping.get(cls);

            context.idToClass.add(ClassMapping.get(cls));
        } else {
            delegateMapping = context.idToClass.get(index - 1);
        }

        if (delegateMapping instanceof ClassMapping) {
            return ((ClassMapping) delegateMapping).readClass(o, data, context);
        } else {
            return delegateMapping.read(data, o, context);
        }
    }
}

From source file:buildcraft.factory.network.PacketHandlerFactory.java

License:Minecraft Mod Public

private void onRefinerySelect(EntityPlayer playerEntity, PacketUpdate packet) throws IOException {

    TileRefinery tile = getRefinery(playerEntity.worldObj, packet.posX, packet.posY, packet.posZ);
    if (tile == null || packet.payload == null) {
        return;//from ww  w  .ja  v a 2  s.c  o  m
    }

    ByteBuf stream = packet.payload.stream;

    tile.setFilter(stream.readByte(), FluidRegistry.getFluid(stream.readShort()));
}

From source file:buildcraft.factory.TileFloodGate.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf stream) {
    byte flags = stream.readByte();
    for (int i = 0; i < 6; i++) {
        blockedSides[i] = (flags & (1 << i)) != 0;
    }/*from w w  w  .j a  va2 s . co m*/
}

From source file:buildcraft.silicon.TileIntegrationTable.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf buf) {
    maxExpCountClient = buf.readByte();
    clientOutputInv.setInventorySlotContents(0, NetworkUtils.readStack(buf));
}

From source file:buildcraft.transport.network.PacketGateExpansionMap.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    int numEntries = data.readByte();
    BiMap<Byte, String> map = HashBiMap.create(numEntries);
    for (int i = 0; i < numEntries; i++) {
        byte id = data.readByte();
        String identifier = Utils.readUTF(data);
        map.put(id, identifier);//from  w  w  w  . ja  v  a  2s .  c  o  m
    }
    GateExpansions.setClientMap(map);
}

From source file:buildcraft.transport.network.PacketPipeTransportTraveler.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    this.itemX = data.readFloat();
    this.itemY = data.readFloat();
    this.itemZ = data.readFloat();

    posX = MathHelper.floor_float(itemX);
    posY = MathHelper.floor_float(itemY);
    posZ = MathHelper.floor_float(itemZ);

    this.entityId = data.readShort();

    this.input = ForgeDirection.getOrientation(data.readByte());
    this.output = ForgeDirection.getOrientation(data.readByte());

    byte c = data.readByte();
    if (c != -1) {
        this.color = EnumColor.fromId(c);
    }/* ww w  .j a  v  a  2s  . c om*/

    this.speed = data.readFloat();

    this.forceStackRefresh = data.readBoolean();
}

From source file:buildcraft.transport.network.PacketPowerUpdate.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    super.readData(data);
    displayPower = new short[] { 0, 0, 0, 0, 0, 0 };
    overload = data.readBoolean();//  w  ww . j  a  va2 s.com
    for (int i = 0; i < displayPower.length; i++) {
        displayPower[i] = data.readByte();
    }
}

From source file:buildcraft.transport.pipes.PipeItemsDaizuli.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    color = data.readByte();
}

From source file:buildcraft.transport.pipes.PipeItemsEmerald.java

License:Minecraft Mod Public

@Override
public void readGuiData(ByteBuf data, EntityPlayer sender) {
    settings.setFilterMode(FilterMode.values()[data.readByte()]);
}