Example usage for io.netty.buffer ByteBufOutputStream writeByte

List of usage examples for io.netty.buffer ByteBufOutputStream writeByte

Introduction

In this page you can find the example usage for io.netty.buffer ByteBufOutputStream writeByte.

Prototype

@Override
    public void writeByte(int v) throws IOException 

Source Link

Usage

From source file:de.sanandrew.mods.claysoldiers.network.packet.PacketParticleFX.java

License:Creative Commons License

@Override
public void writeData(ByteBufOutputStream stream, Tuple dataTuple) throws IOException {
    EnumParticleFx fxType = (EnumParticleFx) dataTuple.getValue(0);
    stream.writeByte(fxType.ordinalByte());
    switch (fxType) {
    case FX_BREAK: // FALL_THROUGH
    case FX_SOLDIER_DEATH: // FALL_THROUGH
    case FX_DIGGING:
        stream.writeDouble((double) dataTuple.getValue(1));
        stream.writeDouble((double) dataTuple.getValue(2));
        stream.writeDouble((double) dataTuple.getValue(3));
        stream.writeUTF((String) dataTuple.getValue(4));
        break;/*from w w  w.j a  va  2  s .  com*/
    case FX_CRIT: // FALL_THROUGH
    case FX_SHOCKWAVE: // FALL_THROUGH
    case FX_MAGMAFUSE:
        stream.writeDouble((double) dataTuple.getValue(1));
        stream.writeDouble((double) dataTuple.getValue(2));
        stream.writeDouble((double) dataTuple.getValue(3));
        break;
    case FX_HORSE_DEATH: // FALL_THROUGH
    case FX_BUNNY_DEATH: // FALL_THROUGH
    case FX_TURTLE_DEATH:
        stream.writeDouble((double) dataTuple.getValue(1));
        stream.writeDouble((double) dataTuple.getValue(2));
        stream.writeDouble((double) dataTuple.getValue(3));
        stream.writeByte((byte) dataTuple.getValue(4));
        break;
    case FX_SPELL:
        stream.writeDouble((double) dataTuple.getValue(1));
        stream.writeDouble((double) dataTuple.getValue(2));
        stream.writeDouble((double) dataTuple.getValue(3));
        stream.writeDouble((double) dataTuple.getValue(4));
        stream.writeDouble((double) dataTuple.getValue(5));
        stream.writeDouble((double) dataTuple.getValue(6));
        break;
    }
}

From source file:de.sanandrew.mods.claysoldiers.network.packet.PacketSendEffectNBT.java

License:Creative Commons License

@Override
public void writeData(ByteBufOutputStream stream, Tuple dataTuple) throws IOException {
    @SuppressWarnings("unchecked")
    Triplet<Integer, Byte, NBTTagCompound> data = (Triplet) dataTuple;

    stream.writeInt(data.getValue0());//from   w w w .  j a  v  a 2s. co  m
    stream.writeByte(data.getValue1());
    ByteBufUtils.writeTag(stream.buffer(), data.getValue2());
}

From source file:de.sanandrew.mods.enderstuffp.network.packet.PacketBiomeChangerActions.java

License:Creative Commons License

@Override
public void writeData(ByteBufOutputStream stream, Tuple dataTuple) throws IOException {
    EnumAction action = (EnumAction) dataTuple.getValue(0);
    TileEntityBiomeChanger biomeChangerTile = (TileEntityBiomeChanger) dataTuple.getValue(1);

    stream.writeByte(action.ordinal());
    stream.writeInt(biomeChangerTile.xCoord);
    stream.writeInt(biomeChangerTile.yCoord);
    stream.writeInt(biomeChangerTile.zCoord);

    switch (action) {
    case CHANGE_BIOME:
        stream.writeByte(biomeChangerTile.getCurrRange());
        break;//from  w  ww .j  a  va 2  s  .  c o m
    case REPLACE_BLOCKS:
        stream.writeBoolean(biomeChangerTile.isReplacingBlocks());
        break;
    case CHNG_MAX_RANGE:
        stream.writeShort(biomeChangerTile.getMaxRange());
        break;
    case CHNG_PERIM_FORM:
        stream.writeByte(biomeChangerTile.perimForm.ordinal());
    }
}

From source file:de.sanandrew.mods.enderstuffp.network.packet.PacketBiomeChangerModify.java

License:Creative Commons License

@Override
public void writeData(ByteBufOutputStream stream, Tuple dataTuple) throws IOException {
    stream.writeInt((int) dataTuple.getValue(0)); // x
    stream.writeInt((int) dataTuple.getValue(1)); // z

    stream.writeByte((byte) dataTuple.getValue(2)); // biomeId
}

From source file:de.sanandrew.mods.enderstuffp.network.packet.PacketEnderPetGuiAction.java

License:Creative Commons License

@Override
public void writeData(ByteBufOutputStream stream, Tuple dataTuple) throws IOException {
    stream.writeInt((int) dataTuple.getValue(0));
    stream.writeByte((byte) dataTuple.getValue(1));

    if (dataTuple.getSize() == 3) {
        stream.writeUTF((String) dataTuple.getValue(2));
    }//from w  w w .  ja  v  a  2 s .c om
}

From source file:de.sanandrew.mods.enderstuffp.network.packet.PacketParticleFX.java

License:Creative Commons License

@Override
public void writeData(ByteBufOutputStream stream, Tuple dataTuple) throws IOException {
    stream.writeByte((byte) dataTuple.getValue(0));
    stream.writeDouble((double) dataTuple.getValue(1));
    stream.writeDouble((double) dataTuple.getValue(2));
    stream.writeDouble((double) dataTuple.getValue(3));
    Tuple.writeToByteBufStream((Tuple) dataTuple.getValue(4), stream);
}

From source file:de.sanandrew.mods.enderstuffp.network.packet.PacketRemoteOpenGui.java

License:Creative Commons License

@Override
public void writeData(ByteBufOutputStream stream, Tuple dataTuple) throws IOException {
    stream.writeByte((byte) dataTuple.getValue(0));
    stream.writeInt((int) dataTuple.getValue(1));
    stream.writeInt((int) dataTuple.getValue(2));
    stream.writeInt((int) dataTuple.getValue(3));
}

From source file:de.sanandrew.mods.enderstuffp.network.packet.PacketSetWeather.java

License:Creative Commons License

@Override
public void writeData(ByteBufOutputStream stream, Tuple dataTuple) throws IOException {
    stream.writeInt((int) dataTuple.getValue(0));
    stream.writeInt((int) dataTuple.getValue(1));
    stream.writeInt((int) dataTuple.getValue(2));
    stream.writeByte((byte) dataTuple.getValue(3));
    stream.writeInt((int) dataTuple.getValue(4));
}

From source file:org.apache.giraph.comm.netty.handler.RequestEncoder.java

License:Apache License

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    if (!(msg instanceof WritableRequest)) {
        throw new IllegalArgumentException("encode: Got a message of type " + msg.getClass());
    }/*www  . j a  v a 2  s.co  m*/

    // Encode the request
    if (LOG.isDebugEnabled()) {
        startEncodingNanoseconds = TIME.getNanoseconds();
    }

    ByteBuf buf;
    WritableRequest request = (WritableRequest) msg;
    int requestSize = request.getSerializedSize();
    if (requestSize == WritableRequest.UNKNOWN_SIZE) {
        buf = ctx.alloc().buffer(bufferStartingSize);
    } else {
        requestSize += SIZE_OF_INT + SIZE_OF_BYTE;
        buf = ctx.alloc().buffer(requestSize);
    }
    ByteBufOutputStream output = new ByteBufOutputStream(buf);

    // This will later be filled with the correct size of serialized request
    output.writeInt(0);
    output.writeByte(request.getType().ordinal());
    try {
        request.write(output);
    } catch (IndexOutOfBoundsException e) {
        LOG.error("write: Most likely the size of request was not properly "
                + "specified (this buffer is too small) - see getSerializedSize() " + "in "
                + request.getType().getRequestClass());
        throw new IllegalStateException(e);
    }
    output.flush();
    output.close();

    // Set the correct size at the end
    buf.setInt(0, buf.writerIndex() - SIZE_OF_INT);
    if (LOG.isDebugEnabled()) {
        LOG.debug("write: Client " + request.getClientId() + ", " + "requestId " + request.getRequestId()
                + ", size = " + buf.readableBytes() + ", " + request.getType() + " took "
                + Times.getNanosSince(TIME, startEncodingNanoseconds) + " ns");
    }
    ctx.write(buf, promise);
}

From source file:org.apache.giraph.comm.netty.handler.ResponseEncoder.java

License:Apache License

@Override
public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
    if (LOG.isDebugEnabled()) {
        LOG.debug("write(" + ctx + "," + msg);
    }//from w  ww .  j a v  a2  s .  co  m

    if (!(msg instanceof WritableRequest)) {
        throw new IllegalArgumentException("encode: cannot encode message of type " + msg.getClass()
                + " since it is not an instance of an implementation of " + " WritableRequest.");
    }
    @SuppressWarnings("unchecked")
    WritableRequest writableRequest = (WritableRequest) msg;

    ByteBuf buf = ctx.alloc().buffer(10);
    ByteBufOutputStream output = new ByteBufOutputStream(buf);

    if (LOG.isDebugEnabled()) {
        LOG.debug("encode: Encoding a message of type " + msg.getClass());
    }

    // Space is reserved now to be filled later by the serialize request size
    output.writeInt(0);
    // write type of object.
    output.writeByte(writableRequest.getType().ordinal());
    // write the object itself.
    writableRequest.write(output);

    output.flush();
    output.close();

    // Set the correct size at the end.
    buf.setInt(0, buf.writerIndex() - SIZE_OF_INT);

    if (LOG.isDebugEnabled()) {
        LOG.debug("encode: Encoding a message of type " + msg.getClass());
    }
    ctx.write(buf, promise);
    /*if[HADOOP_NON_SECURE]
    else[HADOOP_NON_SECURE]*/
    if (writableRequest.getType() == RequestType.SASL_COMPLETE_REQUEST) {
        // We are sending to the client a SASL_COMPLETE response (created by
        // the SaslServer handler). The SaslServer handler has removed itself
        // from the pipeline after creating this response, and now it's time for
        // the ResponseEncoder to remove itself also.
        if (LOG.isDebugEnabled()) {
            LOG.debug("encode: Removing RequestEncoder handler: no longer needed," + " since client: "
                    + ctx.channel().remoteAddress() + " has " + "completed authenticating.");
        }
        ctx.pipeline().remove(this);
    }
    /*end[HADOOP_NON_SECURE]*/
    ctx.write(buf, promise);
}