Example usage for io.netty.buffer ByteBuf writeChar

List of usage examples for io.netty.buffer ByteBuf writeChar

Introduction

In this page you can find the example usage for io.netty.buffer ByteBuf writeChar.

Prototype

public abstract ByteBuf writeChar(int value);

Source Link

Document

Sets the specified 2-byte UTF-16 character at the current writerIndex and increases the writerIndex by 2 in this buffer.

Usage

From source file:buildcraft.core.network.RPCHandler.java

License:Minecraft Mod Public

private void writeParameters(String method, ByteBuf data, Object... actuals)
        throws IOException, IllegalArgumentException, IllegalAccessException {
    if (!methodsMap.containsKey(method)) {
        throw new RuntimeException(method + " is not a callable method of " + getClass().getName());
    }//from   ww w  .  j  a v  a2s  . c o m

    int methodIndex = methodsMap.get(method);
    MethodMapping m = methods[methodIndex];
    Class[] formals = m.parameters;

    int expectedParameters = m.hasInfo ? formals.length - 1 : formals.length;

    if (expectedParameters != actuals.length) {
        // We accept formals + 1 as an argument, in order to support the
        // special last argument RPCMessageInfo

        throw new RuntimeException(getClass().getName() + "." + method + " expects " + m.parameters.length
                + " parameters, not " + actuals.length);
    }

    data.writeShort(methodIndex);

    SerializationContext context = new SerializationContext();

    for (int i = 0; i < actuals.length; ++i) {
        if (int.class.equals(formals[i])) {
            data.writeInt((Integer) actuals[i]);
        } else if (float.class.equals(formals[i])) {
            data.writeFloat((Float) actuals[i]);
        } else if (char.class.equals(formals[i])) {
            data.writeChar((Character) actuals[i]);
        } else {
            m.mappings[i].write(data, actuals[i], context);
        }
    }
}

From source file:buildcraftAdditions.networking.MessageKEBT1.java

License:GNU General Public License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(x);//from  ww  w .  j a  v a2 s .co  m
    buf.writeInt(y);
    buf.writeInt(z);
    buf.writeInt(energy);
    for (int teller = 0; teller < 6; teller++)
        buf.writeInt(configuration[teller]);
    buf.writeInt(length);
    char[] letters = owner.toCharArray();
    for (char letter : letters) {
        buf.writeChar(letter);
    }
}

From source file:buildcraftAdditions.networking.MessageKEBT2.java

License:GNU General Public License

@Override
public void toBytes(ByteBuf buf) {
    buf.writeInt(x);/*from  www .  j av  a 2 s .  c  o  m*/
    buf.writeInt(y);
    buf.writeInt(z);
    for (int teller = 0; teller < 6; teller++)
        buf.writeInt(configuration[teller]);
    buf.writeBoolean(partOfMultiBlock);
    buf.writeBoolean(isMaster);
    buf.writeInt(energy);
    buf.writeInt(masterX);
    buf.writeInt(masterY);
    buf.writeInt(masterZ);
    buf.writeInt(energyState);
    buf.writeInt(length);
    char[] letters = owner.toCharArray();
    for (char letter : letters) {
        buf.writeChar(letter);
    }

}

From source file:buildcraftAdditions.utils.PlayerUtils.java

License:GNU General Public License

public static void writeToByteBuff(ByteBuf buf, UUID uuid) {
    String s = getUUIDString(uuid);
    buf.writeInt(s.length());/*w w  w .  j a v  a  2s.co m*/
    for (int i = 0; i < s.length(); i++)
        buf.writeChar(s.charAt(i));
}

From source file:com.agrn.senqm.network.connection.Connection.java

License:Open Source License

public void sendMessage(String message) {
    Channel channel = channelFuture.channel();

    ByteBuf buffer = channel.alloc().buffer(message.length());
    for (char character : message.toCharArray())
        buffer.writeChar(character);

    channel.writeAndFlush(buffer);/*from  w  ww  .j ava  2 s.c  om*/
}

From source file:com.crowsofwar.gorecore.util.GoreCoreByteBufUtil.java

License:Open Source License

public static void writeString(ByteBuf buf, String str) {
    char[] chs = str.toCharArray();
    buf.writeInt(chs.length);/*  w  w  w  .j  a  v  a 2  s.  c  o  m*/
    for (int i = 0; i < chs.length; i++) {
        buf.writeChar(chs[i]);
    }
}

From source file:com.grandhunterman.dnvm.common.Message.java

License:Creative Commons License

private static void writeChar(char c, ByteBuf buf) {
    buf.writeChar(c);
}

From source file:com.ogarproject.ogar.server.net.packet.Packet.java

License:Open Source License

public static String readUTF16(ByteBuf in) {
    in = in.order(ByteOrder.BIG_ENDIAN);
    ByteBuf buffer = in.alloc().buffer();
    char chr;//  w  w  w  .j  a  v  a 2  s  .  c  o  m
    while (in.readableBytes() > 1 && (chr = in.readChar()) != 0) {
        buffer.writeChar(chr);
    }

    return buffer.toString(Charsets.UTF_16LE);
}

From source file:com.ogarproject.ogar.server.net.packet.Packet.java

License:Open Source License

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:com.theoriginalbit.moarperipherals.common.network.message.MessageGeneric.java

License:Apache License

@Override
public void toBytes(ByteBuf buf) {
    // Write any string data
    if (stringData != null) {
        buf.writeInt(stringData.length);
        for (String str : stringData) {
            ByteBufUtils.writeUTF8String(buf, str);
        }//from  w  w  w .j a  va 2  s . c om
    } else {
        buf.writeInt(0);
    }

    // Write any integer data
    if (intData != null) {
        buf.writeInt(intData.length);
        for (int i : intData) {
            buf.writeInt(i);
        }
    } else {
        buf.writeInt(0);
    }

    // Write any byte data
    if (byteData != null) {
        buf.writeInt(byteData.length);
        buf.writeBytes(byteData);
    } else {
        buf.writeInt(0);
    }

    // Write any char data
    if (charData != null) {
        buf.writeInt(charData.length);
        for (char c : charData) {
            buf.writeChar(c);
        }
    } else {
        buf.writeInt(0);
    }

    // Write any float data
    if (floatData != null) {
        buf.writeInt(floatData.length);
        for (float f : floatData) {
            buf.writeFloat(f);
        }
    } else {
        buf.writeInt(0);
    }

    // Write any double data
    if (doubleData != null) {
        buf.writeInt(doubleData.length);
        for (double d : doubleData) {
            buf.writeDouble(d);
        }
    } else {
        buf.writeInt(0);
    }

    // Write any NBT data
    if (nbtData != null) {
        buf.writeBoolean(true);
        ByteBufUtils.writeTag(buf, nbtData);
    } else {
        buf.writeBoolean(false);
    }
}