List of usage examples for io.netty.buffer ByteBuf writeChar
public abstract ByteBuf writeChar(int value);
From source file:com.vethrfolnir.network.WritePacket.java
License:Open Source License
/** * This is only for LS <-> GS Communication, do not use it for clients! * @param buff//w w w.jav a2s . c o m * @param value */ public void writeS(ByteBuf buff, String value) { if (value == null) throw new RuntimeException("Value is null!"); try { for (int i = 0; i < value.length(); i++) { buff.writeChar(value.charAt(i)); } buff.writeChar('\000'); } catch (Exception e) { log.warn("Failed writing string!", e); } }
From source file:de.ellpeck.actuallyadditions.mod.network.gui.PacketGuiString.java
@Override public void toBytes(ByteBuf buf) { buf.writeInt(this.tileX); buf.writeInt(this.tileY); buf.writeInt(this.tileZ); buf.writeInt(this.worldID); buf.writeInt(this.text.length()); for (int i = 0; i < this.text.length(); i++) { buf.writeChar(this.text.charAt(i)); }//from www. j a va 2s . c om buf.writeInt(this.textID); buf.writeInt(this.playerID); }
From source file:gps.GpsPacket.java
License:Open Source License
private void writePlayerData(PlayerData data, ByteBuf buf) { buf.writeByte(data.username.length()); for (int i = 0; i < data.username.length(); i++) { buf.writeChar(data.username.charAt(i)); }//from w ww.j av a 2 s. c om buf.writeInt(data.pos.getX()); buf.writeInt(data.pos.getY()); buf.writeInt(data.pos.getZ()); buf.writeInt(data.dimension); }
From source file:matteroverdrive.network.packet.client.PacketUpdateMatterRegistry.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { int size = entries.size(); buf.writeInt(size);/*from w ww .ja va 2 s . c o m*/ for (Map.Entry<String, MatterEntry> entry : entries.entrySet()) { int keySize = entry.getKey().length(); buf.writeInt(keySize); char[] keyChars = entry.getKey().toCharArray(); for (int c = 0; c < keySize; c++) { buf.writeChar(keyChars[c]); } buf.writeInt(entry.getValue().getMatter()); buf.writeByte(entry.getValue().getType()); } }
From source file:net.jamcraft.chowtime.core.network.NetworkUtils.java
License:Open Source License
public static void writeString(ByteBuf buff, String string) { if (string != null) { int size = string.length(); buff.writeInt(size);/*from w w w . j a v a2 s .c o m*/ for (int i = 0; i < size; i++) { buff.writeChar(string.toCharArray()[i]); } } else { ChowTime.logger.error("Trying to write a null string", new Throwable()); } }
From source file:nova.core.wrapper.mc.forge.v17.wrapper.entity.forward.FWEntity.java
License:Open Source License
@Override public void writeSpawnData(ByteBuf buffer) { //Write the ID of the entity to client String id = wrapped.getID();//from w w w . j av a 2 s . c o m char[] chars = id.toCharArray(); buffer.writeInt(chars.length); for (char c : chars) buffer.writeChar(c); }
From source file:org.beaconmc.network.socket.pipeline.PacketLegacy.java
License:Open Source License
private ByteBuf toArray(String pingstring) { ByteBuf byteBuf = Unpooled.buffer(); byteBuf.writeByte(255);// ww w . j av a 2 s . co m char[] chars = pingstring.toCharArray(); byteBuf.writeShort(chars.length); for (char charpart : chars) { byteBuf.writeChar(charpart); } return byteBuf; }
From source file:org.clitherproject.clither.server.net.packet.Packet.java
License:Open Source License
@SuppressWarnings("deprecation") public static String readUTF16(ByteBuf in) { in = in.order(ByteOrder.BIG_ENDIAN); ByteBuf buffer = in.alloc().buffer(); char chr;//from ww w .j a v a 2 s . co m while (in.readableBytes() > 1 && (chr = in.readChar()) != 0) { buffer.writeChar(chr); } return buffer.toString(Charsets.UTF_16LE); }
From source file:org.clitherproject.clither.server.net.packet.Packet.java
License:Open Source License
@SuppressWarnings("deprecation") public static void writeUTF16(ByteBuf out, String s) { out.order(ByteOrder.BIG_ENDIAN).writeBytes(s.getBytes(Charsets.UTF_16LE)); out.writeChar(0); }
From source file:org.spout.vanilla.protocol.VanillaByteBufUtils.java
License:Open Source License
/** * Writes a string to the buffer./*from ww w . j ava2 s . c o m*/ * * @param buf The buffer. * @param str The string. * @throws IllegalArgumentException if the string is too long <em>after</em> it is encoded. */ public static void writeString(ByteBuf buf, String str) { int len = str.length(); if (len >= 65536) { throw new IllegalArgumentException("String too long."); } buf.writeShort(len); for (int i = 0; i < len; ++i) { buf.writeChar(str.charAt(i)); } }