List of usage examples for io.netty.buffer ByteBuf readBytes
public abstract ByteBuf readBytes(ByteBuffer dst);
From source file:buildcraft.core.network.PacketRPCTile.java
License:Minecraft Mod Public
@Override public void readData(ByteBuf data) { dimId = data.readShort();/*from w w w.j av a2 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.PacketTileState.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { super.writeData(data); ByteBuf tmpState = Unpooled.buffer(); tmpState.writeByte(stateList.size()); for (StateWithId stateWithId : stateList) { tmpState.writeByte(stateWithId.stateId); stateWithId.state.writeData(tmpState); }//from w ww .jav a 2 s . c om data.writeInt(tmpState.readableBytes()); data.writeBytes(tmpState.readBytes(tmpState.readableBytes())); }
From source file:buildcraft.core.network.PacketTileState.java
License:Minecraft Mod Public
@Override public void readData(ByteBuf data) { super.readData(data); state = Unpooled.buffer();/*w w w . ja va 2 s . co m*/ int length = data.readInt(); state.writeBytes(data.readBytes(length)); }
From source file:buildcraft.core.network.RPCHandler.java
License:Minecraft Mod Public
private PacketRPCPipe createRCPPacket(Pipe pipe, String method, Object... actuals) { ByteBuf data = Unpooled.buffer(); try {//from w w w .j a v a 2 s. c om TileEntity tile = pipe.container; // In order to save space on message, we assuming dimensions ids // small. Maybe worth using a varint instead data.writeShort(tile.getWorldObj().provider.dimensionId); data.writeInt(tile.xCoord); data.writeInt(tile.yCoord); data.writeInt(tile.zCoord); writeParameters(method, data, actuals); } catch (IOException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } byte[] bytes = new byte[data.readableBytes()]; data.readBytes(bytes); return new PacketRPCPipe(bytes); }
From source file:buildcraft.core.network.RPCHandler.java
License:Minecraft Mod Public
private PacketRPCTile createRCPPacket(TileEntity tile, String method, Object... actuals) { ByteBuf data = Unpooled.buffer(); try {/* w w w . j a va2 s . c o m*/ writeParameters(method, data, actuals); } catch (IOException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } byte[] bytes = new byte[data.readableBytes()]; data.readBytes(bytes); return new PacketRPCTile(tile, bytes); }
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 a v a 2 s .c o m 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; }
From source file:buildcraft.core.network.serializers.SerializerBitSet.java
License:Minecraft Mod Public
@Override public Object read(ByteBuf data, Object o, SerializationContext context) { if (!data.readBoolean()) { return null; }/*from w w w . j a v a2 s. c o m*/ int actualSize = data.readInt(); byte[] bytes = new byte[actualSize]; data.readBytes(bytes); BitSet set = BitSetUtils.fromByteArray(bytes); return set; }
From source file:buildcraft.core.utils.Utils.java
License:Minecraft Mod Public
public static String readUTF(ByteBuf data) { try {//from w ww.j a va2s. c om int len = data.readInt(); byte[] b = new byte[len]; data.readBytes(b); return new String(b, "UTF-8"); } catch (UnsupportedEncodingException e) { e.printStackTrace(); return null; } }
From source file:buildcraft.core.utils.Utils.java
License:Minecraft Mod Public
public static NBTTagCompound readNBT(ByteBuf data) { try {//w ww . j a va 2 s.c o m int length = data.readInt(); byte[] compressed = new byte[length]; data.readBytes(compressed); return CompressedStreamTools.func_152457_a(compressed, NBTSizeTracker.field_152451_a); } catch (IOException e) { e.printStackTrace(); return null; } }
From source file:buildcraft.lib.tile.TileBC_Neptune.java
License:Mozilla Public License
@Override public NBTTagCompound getUpdateTag() { ByteBuf buf = Unpooled.buffer(); buf.writeShort(NET_RENDER_DATA);//from w w w . j a v a 2s. co m writePayload(NET_RENDER_DATA, new PacketBufferBC(buf), world.isRemote ? Side.CLIENT : Side.SERVER); byte[] bytes = new byte[buf.readableBytes()]; buf.readBytes(bytes); NBTTagCompound nbt = super.getUpdateTag(); nbt.setByteArray("d", bytes); return nbt; }