Example usage for io.netty.buffer ByteBuf readInt

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

Introduction

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

Prototype

public abstract int readInt();

Source Link

Document

Gets a 32-bit integer at the current readerIndex and increases the readerIndex by 4 in this buffer.

Usage

From source file:buildcraft.core.network.PacketPayloadArrays.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    intPayload = new int[data.readInt()];
    floatPayload = new float[data.readInt()];
    stringPayload = new String[data.readInt()];

    for (int i = 0; i < intPayload.length; i++) {
        intPayload[i] = data.readInt();//from   ww  w  .  ja va2  s.  co  m
    }
    for (int i = 0; i < floatPayload.length; i++) {
        floatPayload[i] = data.readFloat();
    }
    for (int i = 0; i < stringPayload.length; i++) {
        stringPayload[i] = Utils.readUTF(data);
    }
}

From source file:buildcraft.core.network.PacketRPC.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    id = data.readInt();
    int length = data.readInt();
    contents = Unpooled.buffer(length);//from   ww  w.  j a v a  2s  .  c o m
    data.readBytes(contents, length);
}

From source file:buildcraft.core.network.PacketRPCEntity.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    super.readData(data);

    entityId = data.readInt();
}

From source file:buildcraft.core.network.PacketRPCTile.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    dimId = data.readShort();/*from   w ww  . j  ava2 s  . c o  m*/

    x = data.readInt();
    y = data.readInt();
    z = data.readInt();
    id = data.readInt();
    moreDataToCome = data.readBoolean();
    contents = new byte[data.readableBytes()];
    data.readBytes(contents);
}

From source file:buildcraft.core.network.PacketSlotChange.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    super.readData(data);

    this.slot = data.readInt();
    stack = Utils.readStack(data);//from   w w  w.j a v  a2s . com
}

From source file:buildcraft.core.network.PacketTileState.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    super.readData(data);

    state = Unpooled.buffer();/*from ww  w.  j  a  va2 s  .  c o m*/
    int length = data.readInt();
    state.writeBytes(data.readBytes(length));
}

From source file:buildcraft.core.network.PacketUpdate.java

License:Minecraft Mod Public

@Override
public void readData(ByteBuf data) {
    packetId = data.readByte();//www .  j  a  va 2 s  . c  o  m
    posX = data.readInt();
    posY = data.readInt();
    posZ = data.readInt();

    payload = new PacketPayload();

    if (payload != null) {
        payload.readData(data);
    }
}

From source file:buildcraft.core.network.RPCHandler.java

License:Minecraft Mod Public

private void internalRpcReceive(Object o, RPCMessageInfo info, ByteBuf data) {
    try {//  w w  w  . j a va2 s .c  o m
        short methodIndex = data.readShort();

        MethodMapping m = methods[methodIndex];
        Class[] formals = m.parameters;

        Object[] actuals = new Object[formals.length];

        int expectedParameters = m.hasInfo ? formals.length - 1 : formals.length;

        SerializationContext context = new SerializationContext();

        for (int i = 0; i < expectedParameters; ++i) {
            if (int.class.equals(formals[i])) {
                actuals[i] = data.readInt();
            } else if (float.class.equals(formals[i])) {
                actuals[i] = data.readFloat();
            } else if (char.class.equals(formals[i])) {
                actuals[i] = data.readChar();
            } else {
                actuals[i] = m.mappings[i].read(data, actuals[i], context);
            }
        }

        if (m.hasInfo) {
            actuals[actuals.length - 1] = info;
        }

        m.method.invoke(o, actuals);
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (InvocationTargetException e) {
        e.printStackTrace();
    } catch (InstantiationException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }

}

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  a va2 s  .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.ClassMapping.java

License:Minecraft Mod Public

private Object readArray(Object objI, ByteBuf data, SerializationContext context)
        throws IllegalArgumentException, IllegalAccessException, InstantiationException,
        ClassNotFoundException {//from ww w .  j av  a2s  .c  om
    Object obj = objI;

    Class<? extends Object> cpt = mappedClass.getComponentType();

    int size = data.readInt();

    switch (cptType) {
    case Byte: {
        byte[] arr;

        if (obj == null) {
            arr = new byte[size];
        } else {
            arr = (byte[]) obj;
        }

        data.readBytes(arr);

        obj = arr;

        break;
    }
    case Float: {
        float[] arr;

        if (obj == null) {
            arr = new float[size];
        } else {
            arr = (float[]) obj;
        }

        for (int i = 0; i < arr.length; ++i) {
            arr[i] = data.readFloat();
        }

        obj = arr;

        break;
    }
    case Double: {
        double[] arr;

        if (obj == null) {
            arr = new double[size];
        } else {
            arr = (double[]) obj;
        }

        for (int i = 0; i < arr.length; ++i) {
            arr[i] = data.readDouble();
        }

        obj = arr;

        break;
    }
    case Short: {
        short[] arr;

        if (obj == null) {
            arr = new short[size];
        } else {
            arr = (short[]) obj;
        }

        for (int i = 0; i < arr.length; ++i) {
            arr[i] = data.readShort();
        }

        obj = arr;

        break;
    }
    case Int: {
        int[] arr;

        if (obj == null) {
            arr = new int[size];
        } else {
            arr = (int[]) obj;
        }

        for (int i = 0; i < arr.length; ++i) {
            arr[i] = data.readInt();
        }

        obj = arr;

        break;
    }
    case Boolean: {
        boolean[] arr;

        if (obj == null) {
            arr = new boolean[size];
        } else {
            arr = (boolean[]) obj;
        }

        for (int i = 0; i < arr.length; ++i) {
            arr[i] = data.readBoolean();
        }

        obj = arr;

        break;
    }
    case Object: {
        Object[] arr;

        if (obj == null) {
            arr = (Object[]) Array.newInstance(cpt, size);
        } else {
            arr = (Object[]) obj;
        }

        for (int i = 0; i < arr.length; ++i) {
            arr[i] = cptMapping.read(data, arr[i], context);
        }

        obj = arr;

        break;
    }
    }

    return obj;
}