List of usage examples for io.netty.buffer ByteBuf readInt
public abstract int readInt();
From source file:appeng.tile.storage.TileChest.java
License:Open Source License
@TileEvent(TileEventType.NETWORK_READ) public boolean readFromStream_TileChest(final ByteBuf data) { final int oldState = this.state; final ItemStack oldType = this.storageType; this.state = data.readByte(); final AEColor oldPaintedColor = this.paintedColor; this.paintedColor = AEColor.values()[data.readByte()]; final int item = data.readInt(); if (item == 0) { this.storageType = null; } else {//from w w w . j a v a2 s . c o m this.storageType = new ItemStack(Item.getItemById(item & 0xffff), 1, item >> Platform.DEF_OFFSET); } this.lastStateChange = this.worldObj.getTotalWorldTime(); return oldPaintedColor != this.paintedColor || (this.state & 0xDB6DB6DB) != (oldState & 0xDB6DB6DB) || !Platform.itemComparisons().isSameItem(oldType, this.storageType); }
From source file:appeng.tile.storage.TileDrive.java
License:Open Source License
@TileEvent(TileEventType.NETWORK_READ) public boolean readFromStream_TileDrive(final ByteBuf data) { final int oldState = this.state; this.state = data.readInt(); return (this.state & BIT_STATE_MASK) != (oldState & BIT_STATE_MASK); }
From source file:appeng.util.item.AEFluidStack.java
License:Open Source License
public static IAEFluidStack loadFluidStackFromPacket(final ByteBuf data) throws IOException { final byte mask = data.readByte(); // byte PriorityType = (byte) (mask & 0x03); final byte stackType = (byte) ((mask & 0x0C) >> 2); final byte countReqType = (byte) ((mask & 0x30) >> 4); final boolean isCraftable = (mask & 0x40) > 0; final boolean hasTagCompound = (mask & 0x80) > 0; // don't send this... final NBTTagCompound d = new NBTTagCompound(); final byte len2 = data.readByte(); final byte[] name = new byte[len2]; data.readBytes(name, 0, len2);//from w ww. ja v a2 s . co m d.setString("FluidName", new String(name, "UTF-8")); d.setByte("Count", (byte) 0); if (hasTagCompound) { final int len = data.readInt(); final byte[] bd = new byte[len]; data.readBytes(bd); final DataInputStream di = new DataInputStream(new ByteArrayInputStream(bd)); d.setTag("tag", CompressedStreamTools.read(di)); } // long priority = getPacketValue( PriorityType, data ); final long stackSize = getPacketValue(stackType, data); final long countRequestable = getPacketValue(countReqType, data); final FluidStack fluidStack = FluidStack.loadFluidStackFromNBT(d); if (fluidStack == null) { return null; } final AEFluidStack fluid = AEFluidStack.create(fluidStack); // fluid.priority = (int) priority; fluid.setStackSize(stackSize); fluid.setCountRequestable(countRequestable); fluid.setCraftable(isCraftable); return fluid; }
From source file:appeng.util.item.AEItemStack.java
License:Open Source License
public static IAEItemStack loadItemStackFromPacket(final ByteBuf data) throws IOException { final byte mask = data.readByte(); // byte PriorityType = (byte) (mask & 0x03); final byte stackType = (byte) ((mask & 0x0C) >> 2); final byte countReqType = (byte) ((mask & 0x30) >> 4); final boolean isCraftable = (mask & 0x40) > 0; final boolean hasTagCompound = (mask & 0x80) > 0; // don't send this... final NBTTagCompound d = new NBTTagCompound(); // For some insane reason, Vanilla can only parse numeric item ids if they are strings short itemNumericId = data.readShort(); d.setString("id", String.valueOf(itemNumericId)); d.setShort("Damage", data.readShort()); d.setByte("Count", (byte) 0); if (hasTagCompound) { final int len = data.readInt(); final byte[] bd = new byte[len]; data.readBytes(bd);// www. j a v a2s . c o m final ByteArrayInputStream di = new ByteArrayInputStream(bd); d.setTag("tag", CompressedStreamTools.read(new DataInputStream(di))); } // long priority = getPacketValue( PriorityType, data ); final long stackSize = getPacketValue(stackType, data); final long countRequestable = getPacketValue(countReqType, data); final ItemStack itemstack = ItemStack.loadItemStackFromNBT(d); if (itemstack == null) { return null; } final AEItemStack item = AEItemStack.create(itemstack); // item.priority = (int) priority; item.setStackSize(stackSize); item.setCountRequestable(countRequestable); item.setCraftable(isCraftable); return item; }
From source file:appeng.util.item.AEStack.java
License:Open Source License
static long getPacketValue(final byte type, final ByteBuf tag) { if (type == 0) { long l = tag.readByte(); l -= Byte.MIN_VALUE;//from ww w . j a va 2 s . c o m return l; } else if (type == 1) { long l = tag.readShort(); l -= Short.MIN_VALUE; return l; } else if (type == 2) { long l = tag.readInt(); l -= Integer.MIN_VALUE; return l; } return tag.readLong(); }
From source file:at.yawk.accordion.codec.unsafe.ArrayCodec.java
License:Mozilla Public License
@Override public Object decode(ByteBuf encoded) { int length = encoded.readInt(); Object array = Array.newInstance(componentType, length); long offset = baseOffset; for (int i = 0; i < length; i++) { componentCodec.read(encoded, array, offset); offset += indexScale;/*from w w w . ja v a 2s . c o m*/ } return array; }
From source file:at.yawk.accordion.codec.unsafe.CollectionCodecSupplier.java
License:Mozilla Public License
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/*from ww w . java 2 s. c om*/ 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/* w w w . java2 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; } }; }
From source file:at.yawk.accordion.distributed.Node.java
License:Mozilla Public License
/** * Deserialize a node from a stream.//ww w . j a va2 s . c o m */ static Node read(ByteBuf from) { // port int port = from.readInt(); // IP byte[] address = InternalProtocol.readByteArray(from); // tier int tier = from.readInt(); try { // build return new Node(new InetSocketAddress(InetAddress.getByAddress(address), port), tier); } catch (UnknownHostException e) { // illegal length IP should never happen if written by #write throw new Error("Invalid address " + Arrays.toString(address), e); } }
From source file:at.yawk.accordion.minecraft.example.AbstractPingPacket.java
License:Mozilla Public License
@Override public void read(ByteBuf source) { payload = source.readInt(); }