List of usage examples for io.netty.buffer ByteBuf writeShort
public abstract ByteBuf writeShort(int value);
From source file:at.yawk.accordion.codec.unsafe.EnumCodec.java
License:Mozilla Public License
@Override public void encode(ByteBuf target, E message) { target.writeShort(message.ordinal()); }
From source file:at.yawk.accordion.distributed.AbstractCollectionSynchronizer.java
License:Mozilla Public License
/** * Encode a set of entries into a bytebuf. *///from w ww . ja v a 2 s . co m private ByteBuf encode(Set<T> added) { ByteBuf message = Unpooled.buffer(); // ushort length message.writeShort(added.size()); // individual entries written sequentially added.forEach(entry -> serializer.encode(message, entry)); return message; }
From source file:at.yawk.accordion.netty.Framer.java
License:Mozilla Public License
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, ByteBuf out) throws Exception { // length of this message int length = msg.readableBytes(); if (length > MAXIMUM_MESSAGE_LENGTH) { throw new IOException("Message too long: " + length + " bytes"); }//from w ww .j a v a2s. c om out.ensureWritable(2 + length); // write out.writeShort(length); msg.readBytes(out, length); }
From source file:buildcraft.builders.TileArchitect.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf stream) { box.writeData(stream);/*from w w w . java2 s . co m*/ Utils.writeUTF(stream, name); readConfiguration.writeData(stream); stream.writeShort(subLasers.size()); for (LaserData ld : subLasers) { ld.writeData(stream); } }
From source file:buildcraft.builders.TileBlueprintLibrary.java
License:Minecraft Mod Public
@Override public void receiveCommand(String command, Side side, Object sender, ByteBuf stream) { if (side.isClient()) { if ("requestSelectedBlueprint".equals(command)) { if (isOutputConsistent()) { if (selected > -1 && selected < currentPage.size()) { // Work around 32k max limit on client->server final BlueprintBase bpt = BuildCraftBuilders.clientDB.load(currentPage.get(selected)); final byte[] bptData = bpt.getData(); final int chunks = (bptData.length + CHUNK_SIZE - 1) / CHUNK_SIZE; BuildCraftCore.instance .sendToServer(new PacketCommand(this, "uploadServerBegin", new CommandWriter() { public void write(ByteBuf data) { bpt.id.writeData(data); data.writeShort(chunks); }// w w w . j a v a 2 s . c om })); for (int i = 0; i < chunks; i++) { final int chunk = i; final int start = CHUNK_SIZE * chunk; final int length = Math.min(CHUNK_SIZE, bptData.length - start); BuildCraftCore.instance .sendToServer(new PacketCommand(this, "uploadServerChunk", new CommandWriter() { public void write(ByteBuf data) { data.writeShort(chunk); data.writeShort(length); data.writeBytes(bptData, start, length); } })); } BuildCraftCore.instance.sendToServer(new PacketCommand(this, "uploadServerEnd", null)); } else { BuildCraftCore.instance .sendToServer(new PacketCommand(this, "uploadNothingToServer", null)); } } } else if ("downloadBlueprintToClient".equals(command)) { BlueprintId id = new BlueprintId(); id.readData(stream); byte[] data = Utils.readByteArray(stream); try { NBTTagCompound nbt = CompressedStreamTools.func_152457_a(data, NBTSizeTracker.field_152451_a); BlueprintBase bpt = BlueprintBase.loadBluePrint(nbt); bpt.setData(data); bpt.id = id; BuildCraftBuilders.clientDB.add(bpt); setCurrentPage(BuildCraftBuilders.clientDB.getPage(pageId)); } catch (IOException e) { e.printStackTrace(); } } } else if (side.isServer()) { if ("uploadNothingToServer".equals(command)) { setInventorySlotContents(3, getStackInSlot(2)); setInventorySlotContents(2, null); downloadingPlayer = null; } else if ("uploadServerBegin".equals(command)) { blueprintDownloadId = new BlueprintId(); blueprintDownloadId.readData(stream); blueprintDownload = new byte[CHUNK_SIZE * stream.readUnsignedShort()]; } else if ("uploadServerChunk".equals(command)) { int start = stream.readUnsignedShort() * CHUNK_SIZE; int length = stream.readUnsignedShort(); if (blueprintDownload != null) { stream.readBytes(blueprintDownload, start, length); } else { stream.skipBytes(length); } } else if ("uploadServerEnd".equals(command)) { try { NBTTagCompound nbt = CompressedStreamTools.func_152457_a(blueprintDownload, NBTSizeTracker.field_152451_a); BlueprintBase bpt = BlueprintBase.loadBluePrint(nbt); bpt.setData(blueprintDownload); bpt.id = blueprintDownloadId; BuildCraftBuilders.serverDB.add(bpt); setInventorySlotContents(3, bpt.getStack()); setInventorySlotContents(2, null); } catch (IOException e) { e.printStackTrace(); } blueprintDownloadId = null; blueprintDownload = null; downloadingPlayer = null; } } }
From source file:buildcraft.builders.TileBuilder.java
License:Minecraft Mod Public
private BuildCraftPacket getItemRequirementsPacket(final ArrayList<ItemStack> items) { if (items != null) { return new PacketCommand(this, "setItemRequirements", new CommandWriter() { public void write(ByteBuf data) { data.writeShort(items.size()); if (items != null) { for (ItemStack rb : items) { Utils.writeStack(data, rb); data.writeShort(rb.stackSize); }/*from w w w.ja v a 2s. c om*/ } } }); } else { return new PacketCommand(this, "clearItemRequirements", null); } }
From source file:buildcraft.builders.TileQuarry.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf stream) { super.writeData(stream); box.writeData(stream);//from ww w . j ava2 s.c om stream.writeInt(targetX); stream.writeShort(targetY); stream.writeInt(targetZ); stream.writeDouble(headPosX); stream.writeDouble(headPosY); stream.writeDouble(headPosZ); stream.writeFloat((float) speed); stream.writeFloat(headTrajectory); int flags = stage.ordinal(); flags |= movingHorizontally ? 0x10 : 0; flags |= movingVertically ? 0x20 : 0; stream.writeByte(flags); ledState = (hasWork() && mode != Mode.Off && getTicksSinceEnergyReceived() < 12 ? 16 : 0) | (getBattery().getEnergyStored() * 15 / getBattery().getMaxEnergyStored()); stream.writeByte(ledState); }
From source file:buildcraft.builders.urbanism.AnchoredBox.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf stream) { box.writeData(stream); stream.writeInt(x1); stream.writeShort(y1); stream.writeInt(z1); }
From source file:buildcraft.builders.urbanism.TileUrbanist.java
License:Minecraft Mod Public
private BuildCraftPacket createXYZPacket(String name, final int x, final int y, final int z) { return new PacketCommand(this, name, new CommandWriter() { public void write(ByteBuf data) { data.writeInt(x);//from ww w .j av a2 s. c o m data.writeShort(y); data.writeInt(z); } }); }
From source file:buildcraft.builders.urbanism.TileUrbanist.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf stream) { stream.writeShort(frames.size()); for (AnchoredBox b : frames) { b.writeData(stream);/* ww w .ja v a 2s . c om*/ } }