List of usage examples for io.netty.buffer Unpooled buffer
public static ByteBuf buffer()
From source file:appeng.core.sync.packets.PacketTransitionEffect.java
License:Open Source License
public PacketTransitionEffect(final double x, final double y, final double z, final AEPartLocation dir, final boolean wasBlock) { this.x = x;/* w ww. ja va 2 s. c om*/ this.y = y; this.z = z; this.d = dir; this.mode = wasBlock; final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeFloat((float) x); data.writeFloat((float) y); data.writeFloat((float) z); data.writeByte(this.d.ordinal()); data.writeBoolean(wasBlock); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketValueConfig.java
License:Open Source License
public PacketValueConfig(final String name, final String value) throws IOException { this.Name = name; this.Value = value; final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(bos); dos.writeUTF(name);//from w w w. j a v a 2 s. co m dos.writeUTF(value); // dos.close(); data.writeBytes(bos.toByteArray()); this.configureWrite(data); }
From source file:appeng.fmp.CableBusPart.java
License:Open Source License
@Override public void writeDesc(final MCDataOutput packet) { final ByteBuf stream = Unpooled.buffer(); try {//from ww w . ja v a 2s. c o m this.getCableBus().writeToStream(stream); packet.writeInt(stream.readableBytes()); stream.capacity(stream.readableBytes()); packet.writeByteArray(stream.array()); } catch (final IOException e) { AELog.error(e); } }
From source file:appeng.tile.AEBaseTile.java
License:Open Source License
/** * This builds a tag with the actual data that should be sent to the client for update syncs. * If the tile entity doesn't need update syncs, it returns null. *//*from w w w. ja v a2 s .c o m*/ private NBTTagCompound writeUpdateData() { final NBTTagCompound data = new NBTTagCompound(); final ByteBuf stream = Unpooled.buffer(); try { this.writeToStream(stream); if (stream.readableBytes() == 0) { return null; } } catch (final Throwable t) { AELog.debug(t); } stream.capacity(stream.readableBytes()); data.setByteArray("X", stream.array()); return data; }
From source file:appeng.tile.misc.TilePaint.java
License:Open Source License
@TileEvent(TileEventType.WORLD_NBT_WRITE) public void writeToNBT_TilePaint(final NBTTagCompound data) { final ByteBuf myDat = Unpooled.buffer(); this.writeBuffer(myDat); if (myDat.hasArray()) { data.setByteArray("dots", myDat.array()); }//www .j a v a2 s.c o m }
From source file:arekkuusu.grimoireOfAlice.client.gui.GuiScreenYoukaiBook.java
License:Open Source License
private void sendBookToServer(boolean p_146462_1_) { if (bookIsUnsigned && field_146481_r) { if (bookPages != null) { String s;/*from ww w .ja v a2 s . com*/ while (bookPages.tagCount() > 1) { s = bookPages.getStringTagAt(bookPages.tagCount() - 1); if (s.length() != 0) { break; } bookPages.removeTag(bookPages.tagCount() - 1); } if (bookObj.hasTagCompound()) { NBTTagCompound nbttagcompound = bookObj.getTagCompound(); nbttagcompound.setTag("pages", bookPages); } else { bookObj.setTagInfo("pages", bookPages); } s = "MC|BEdit"; if (p_146462_1_) { s = "MC|BSign"; bookObj.setTagInfo("author", new NBTTagString(editingPlayer.getCommandSenderName())); bookObj.setTagInfo("title", new NBTTagString(bookTitle.trim().replace("k", "").substring(2))); bookObj.func_150996_a(GOAItem.enchantedBook); } ByteBuf bytebuf = Unpooled.buffer(); try { new PacketBuffer(bytebuf).writeItemStackToBuffer(bookObj); mc.getNetHandler().addToSendQueue(new C17PacketCustomPayload(s, bytebuf)); } catch (Exception exception) { LOGGER.error("Couldn\'t send book info", exception); } finally { bytebuf.release(); } } } }
From source file:at.yawk.accordion.codec.AbstractObjectChannel.java
License:Mozilla Public License
@SuppressWarnings({ "rawtypes", "unchecked" }) @Override/*from w w w . j a va 2 s . com*/ public void publish(T message) { // get the channel name Class<? extends T> clazz = (Class) message.getClass(); String channel = channelNameFactory.apply(clazz); // write packet to empty buffer ByteBuf payload = Unpooled.buffer(); write(message, payload); // send buffer to channel of this packet type messenger.getChannel(channel).publish(payload); // send to our subscribers to follow PacketChannel contract subscribers.getOrDefault(clazz, Collections.emptySet()) .forEach((Consumer subscriber) -> subscriber.accept(message)); }
From source file:at.yawk.accordion.codec.ByteCodec.java
License:Mozilla Public License
@Override default ByteBuf encode(U message) { ByteBuf buf = Unpooled.buffer(); encode(buf, message); return buf; }
From source file:at.yawk.accordion.compression.SnappyCompressorTest.java
License:Mozilla Public License
private void testCompressDecompress(byte[] payload) { ByteBuf unc = Unpooled.buffer(); unc.writeBytes(payload);/*from w w w.java 2 s. co m*/ ByteBuf comp = SnappyCompressor.getInstance().encode(unc); ByteBuf unc2 = SnappyCompressor.getInstance().decode(comp); unc.resetReaderIndex(); unc2.resetReaderIndex(); assertEquals(unc, unc2); }
From source file:at.yawk.accordion.distributed.AbstractCollectionSynchronizer.java
License:Mozilla Public License
/** * Encode a set of entries into a bytebuf. *///w w w .j a v a 2s . c o 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; }