Example usage for io.netty.buffer ByteBufOutputStream writeInt

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

Introduction

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

Prototype

@Override
    public void writeInt(int v) throws IOException 

Source Link

Usage

From source file:de.sanandrew.mods.turretmod.network.packet.PacketSendTransmitterExpTime.java

License:Creative Commons License

@Override
public void writeData(ByteBufOutputStream stream, Tuple data) throws IOException {
    stream.writeInt((Integer) data.getValue(0)); //xCoord
    stream.writeInt((Integer) data.getValue(1)); //yCoord
    stream.writeInt((Integer) data.getValue(2)); //zCoord
    stream.writeInt((Integer) data.getValue(3)); //timeout
}

From source file:de.sanandrew.mods.turretmod.network.packet.PacketTargetList.java

License:Creative Commons License

@Override
@SuppressWarnings("unchecked")
public void writeData(ByteBufOutputStream outStream, Tuple data) throws IOException {
    List<Class<? extends EntityLiving>> applicableTargets = (List<Class<? extends EntityLiving>>) data
            .getValue(1);//from   ww w . j  a v a2s .c om
    outStream.writeInt((Integer) data.getValue(0));
    outStream.writeInt(applicableTargets.size());
    for (Class targetCls : applicableTargets) {
        outStream.writeUTF((String) EntityList.classToStringMapping.get(targetCls));
    }
}

From source file:de.sanandrew.mods.turretmod.network.packet.PacketTargetListRequest.java

License:Creative Commons License

@Override
@SuppressWarnings("unchecked")
public void writeData(ByteBufOutputStream outStream, Tuple data) throws IOException {
    outStream.writeInt((Integer) data.getValue(0));
}

From source file:de.sanandrew.mods.turretmod.network.packet.PacketUpgradeList.java

License:Creative Commons License

@Override
@SuppressWarnings("unchecked")
public void writeData(ByteBufOutputStream outStream, Tuple data) throws IOException {
    List<TurretUpgrade> upgrades = (List<TurretUpgrade>) data.getValue(1);
    outStream.writeInt((Integer) data.getValue(0));
    outStream.writeInt(upgrades.size());
    for (TurretUpgrade upg : upgrades) {
        outStream.writeUTF(TurretUpgradeRegistry.getRegistrationName(upg));
    }//from w ww .  j a  v a  2s. c  o  m
}

From source file:io.pravega.shared.protocol.netty.CommandEncoder.java

License:Open Source License

@SneakyThrows(IOException.class)
private void writeMessage(AppendBlock block, ByteBuf out) {
    int startIdx = out.writerIndex();
    ByteBufOutputStream bout = new ByteBufOutputStream(out);
    bout.writeInt(block.getType().getCode());
    bout.write(LENGTH_PLACEHOLDER);//from   w  w w  .j a v  a  2s.c o  m
    block.writeFields(bout);
    bout.flush();
    bout.close();
    int endIdx = out.writerIndex();
    int fieldsSize = endIdx - startIdx - TYPE_PLUS_LENGTH_SIZE;
    out.setInt(startIdx + TYPE_SIZE, fieldsSize + currentBlockSize);
}

From source file:io.pravega.shared.protocol.netty.CommandEncoder.java

License:Open Source License

@SneakyThrows(IOException.class)
private int writeMessage(WireCommand msg, ByteBuf out) {
    int startIdx = out.writerIndex();
    ByteBufOutputStream bout = new ByteBufOutputStream(out);
    bout.writeInt(msg.getType().getCode());
    bout.write(LENGTH_PLACEHOLDER);/* w w w.j  a v  a2 s. co  m*/
    msg.writeFields(bout);
    bout.flush();
    bout.close();
    int endIdx = out.writerIndex();
    int fieldsSize = endIdx - startIdx - TYPE_PLUS_LENGTH_SIZE;
    out.setInt(startIdx + TYPE_SIZE, fieldsSize);
    return endIdx - startIdx;
}

From source file:net.mcsproject.daemon.network.packets.PacketAuthResponse.java

License:Open Source License

@Override
public void write(ByteBufOutputStream byteBuf) throws IOException {
    byteBuf.writeBoolean(this.ok);
    byteBuf.writeInt(this.minPort);
    byteBuf.writeInt(this.maxPort);
    byteBuf.writeUTF(this.resources);
}

From source file:net.mcsproject.daemon.network.packets.PacketServerStarted.java

License:Open Source License

@Override
public void write(ByteBufOutputStream byteBuf) throws IOException {
    byteBuf.writeUTF(this.serverType);
    byteBuf.writeInt(this.port);
}

From source file:net.mcsproject.daemon.network.packets.PacketServerStatus.java

License:Open Source License

@Override
public void write(ByteBufOutputStream byteBuf) throws IOException {
    byteBuf.writeInt(this.cpuUsage);
    byteBuf.writeInt(this.ramUsage);
    byteBuf.writeInt(this.ramMax);
}

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());
    }//from  w  w w . j  ava2 s. c o 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);
}