Example usage for io.netty.buffer ByteBuf writeFloat

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

Introduction

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

Prototype

public abstract ByteBuf writeFloat(float value);

Source Link

Document

Sets the specified 32-bit floating point number at the current writerIndex and increases the writerIndex by 4 in this buffer.

Usage

From source file:org.spout.vanilla.protocol.VanillaByteBufUtils.java

License:Open Source License

/**
 * Writes a list of parameters (e.g. mob metadata) to the buffer.
 *
 * @param buf The buffer./* w w w.  ja va  2 s .c o  m*/
 * @param parameters The parameters.
 */
@SuppressWarnings("unchecked")
public static void writeParameters(ByteBuf buf, List<Parameter<?>> parameters) {
    for (Parameter<?> parameter : parameters) {
        int type = parameter.getType();
        int index = parameter.getIndex();
        if (index > 0x1F) {
            throw new IllegalArgumentException("Index has a maximum of 0x1F!");
        }

        buf.writeByte(type << 5 | index & 0x1F);

        switch (type) {
        case Parameter.TYPE_BYTE:
            buf.writeByte(((Parameter<Byte>) parameter).getValue());
            break;
        case Parameter.TYPE_SHORT:
            buf.writeShort(((Parameter<Short>) parameter).getValue());
            break;
        case Parameter.TYPE_INT:
            buf.writeInt(((Parameter<Integer>) parameter).getValue());
            break;
        case Parameter.TYPE_FLOAT:
            buf.writeFloat(((Parameter<Float>) parameter).getValue());
            break;
        case Parameter.TYPE_STRING:
            writeString(buf, ((Parameter<String>) parameter).getValue());
            break;
        case Parameter.TYPE_ITEM:
            ItemStack item = ((Parameter<ItemStack>) parameter).getValue();
            writeItemStack(buf, item);
            break;
        }
    }

    buf.writeByte(127);
}

From source file:org.spoutcraft.client.network.codec.play.PositionLookCodec.java

License:MIT License

@Override
public ByteBuf encode(ByteBuf buf, PositionLookMessage message) throws IOException {
    buf.writeDouble(message.getX());/*  w  w  w.  j a  va2  s . c o  m*/
    buf.writeDouble(message.getStance());
    buf.writeDouble(message.getY());
    buf.writeDouble(message.getZ());
    buf.writeFloat(message.getYaw());
    buf.writeFloat(message.getPitch());
    buf.writeBoolean(message.isOnGround());
    return buf;
}

From source file:org.starmod.net.object.field.type.NetworkFloat.java

License:MIT License

@Override
public void encode(ByteBuf buf) {
    buf.writeFloat(getValue());
}

From source file:org.starnub.starbounddata.types.damage.DamageNotification.java

License:Open Source License

@Override
public void write(ByteBuf out) {
    sourceEntityId.write(out);//from   www  . j  a  v a  2  s.c om
    targetEntityId.write(out);
    position.write(out);
    out.writeFloat(damage);
    writeStringVLQ(out, damageSourceKind);
    writeStringVLQ(out, targetMaterialKind);
    out.writeBoolean(killed);
}

From source file:org.starnub.starbounddata.types.damage.DamageRequest.java

License:Open Source License

@Override
public void write(ByteBuf out) {
    out.writeByte(hitType.ordinal());//from  ww w.ja v a2 s .  c om
    out.writeByte(damageType.ordinal());
    out.writeFloat(damage);
    this.knockbackMomentum.write(out);
    this.sourceEntityId.write(out);
    writeStringVLQ(out, damageSourceKind);
    this.statusEffects.write(out);
}

From source file:org.starnub.starbounddata.types.damage.EphemeralStatusEffect.java

License:Open Source License

@Override
public void write(ByteBuf out) {
    writeStringVLQ(out, uniqueStatusEffect);
    if (duration == 0) {
        out.writeBoolean(false);/*from  ww  w.ja v  a2 s .  c o m*/
    } else {
        out.writeBoolean(true);
        out.writeFloat(duration);
    }
}

From source file:org.starnub.starbounddata.types.tile.TileDamage.java

License:Open Source License

@Override
public void write(ByteBuf out) {
    out.writeByte(tileDamageType.ordinal());
    out.writeFloat(amount);
    out.writeInt(harvestLevel);
}

From source file:org.starnub.starbounddata.types.vectors.Vec2F.java

License:Open Source License

@Override
public void write(ByteBuf out) {
    out.writeFloat(this.x);
    out.writeFloat(this.y);
}

From source file:org.wso2.carbon.tcp.transport.util.BinaryMessageConverterUtil.java

License:Open Source License

public static void assignData(Object data, ByteBuf eventDataBuffer) throws IOException {
    if (data instanceof String) {
        eventDataBuffer.writeInt(((String) data).length());
        eventDataBuffer.writeBytes((((String) data).getBytes(BinaryMessageConstants.DEFAULT_CHARSET)));
    } else if (data instanceof Integer) {
        eventDataBuffer.writeInt((Integer) data);
    } else if (data instanceof Long) {
        eventDataBuffer.writeLong((Long) data);
    } else if (data instanceof Float) {
        eventDataBuffer.writeFloat((Float) data);
    } else if (data instanceof Double) {
        eventDataBuffer.writeDouble((Double) data);
    } else if (data instanceof Boolean) {
        eventDataBuffer.writeByte((byte) (((Boolean) data) ? 1 : 0));
    } else {/*from  www  .  j  a  v  a  2  s.  c om*/
        eventDataBuffer.writeInt(0);
    }

}

From source file:org.wso2.siddhi.tcp.transport.utils.BinaryMessageConverterUtil.java

License:Open Source License

public static void assignData(Object data, ByteBuf eventDataBuffer) throws IOException {
    if (data instanceof String) {
        eventDataBuffer.writeInt(((String) data).length());
        eventDataBuffer.writeBytes((((String) data).getBytes(Constant.DEFAULT_CHARSET)));
    } else if (data instanceof Integer) {
        eventDataBuffer.writeInt((Integer) data);
    } else if (data instanceof Long) {
        eventDataBuffer.writeLong((Long) data);
    } else if (data instanceof Float) {
        eventDataBuffer.writeFloat((Float) data);
    } else if (data instanceof Double) {
        eventDataBuffer.writeDouble((Double) data);
    } else if (data instanceof Boolean) {
        eventDataBuffer.writeByte((byte) (((Boolean) data) ? 1 : 0));
    } else {//from w w  w .  java 2s  .c  om
        eventDataBuffer.writeInt(0);
    }

}