Java Code Examples for io.netty.buffer.ByteBuf.writeInt()

The following are Jave code examples for showing how to use writeInt() of the io.netty.buffer.ByteBuf class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: angel   File: DefaultRowUpdaterTest.java   Source Code and License Vote up 6 votes
@Test
public void testUpdateIntSparseToIntSparse() throws Exception {
  ServerSparseIntRow serverSparseIntRow = new ServerSparseIntRow(rowId, startCol, endCol);
  ByteBuf buf = Unpooled.buffer(16);
  buf.writeInt(0);
  buf.writeInt(0);
  buf.writeInt(1);
  buf.writeInt(1);
  buf.writeInt(2);
  buf.writeInt(2);
  rowUpdater.updateIntSparseToIntSparse(3, buf, serverSparseIntRow);
  Int2IntOpenHashMap hashMap = new Int2IntOpenHashMap();
  hashMap.addTo(0, 0);
  hashMap.addTo(1, 1);
  hashMap.addTo(2, 2);
  assertEquals(serverSparseIntRow.getData(), hashMap);
}
 
Example 2
Project: angel   File: SparseIntRowUpdateSplit.java   Source Code and License Vote up 5 votes
@Override
public void serialize(ByteBuf buf) {
  super.serialize(buf);
  buf.writeInt(end - start);
  LOG.debug("int size = " + (end - start));
  for (int i = start; i < end; i++) {
    buf.writeInt(offsets[i]);
    buf.writeInt(values[i]);
  }
}
 
Example 3
Project: angel   File: ServerDenseDoubleRowTest.java   Source Code and License Vote up 5 votes
@Test
public void testUpdate() throws Exception {
  serverDenseDoubleRow = new ServerDenseDoubleRow(rowId, startCol, endCol);
  ByteBuf buf = Unpooled.buffer(16);
  buf.writeDouble(0.00);
  buf.writeDouble(1.00);
  buf.writeDouble(-1.00);

  double newValue0 = buf.getDouble(0) + serverDenseDoubleRow.getData().get(0);
  double newValue1 = buf.getDouble(8) + serverDenseDoubleRow.getData().get(1);
  serverDenseDoubleRow.update(RowType.T_DOUBLE_DENSE, buf, 3);
  assertEquals(serverDenseDoubleRow.getData().get(0), newValue0, 0.000);
  assertEquals(serverDenseDoubleRow.getData().get(1), newValue1, 0.000);
  assertEquals(serverDenseDoubleRow.getData().get(2), -1, 0.000);

  serverDenseDoubleRow = new ServerDenseDoubleRow(rowId, startCol, endCol);
  buf = Unpooled.buffer(0);
  LOG.info(buf);
  buf.writeInt(0);
  buf.writeDouble(1.00);
  buf.writeInt(2);
  buf.writeDouble(-2.00);
  serverDenseDoubleRow.update(RowType.T_DOUBLE_SPARSE, buf, 2);
  assertEquals(serverDenseDoubleRow.getData().get(0), 1, 0.000);
  assertEquals(serverDenseDoubleRow.getData().get(1), 0, 0.000);
  assertEquals(serverDenseDoubleRow.getData().get(2), -2, 0.000);

}
 
Example 4
Project: MeeCreeps   File: PacketMakePortals.java   Source Code and License Vote up 5 votes
@Override
public void toBytes(ByteBuf buf) {
    buf.writeLong(selectedBlock.toLong());
    buf.writeByte(selectedSide.ordinal());
    NetworkTools.writeStringUTF8(buf, destination.getName());
    buf.writeInt(destination.getDimension());
    buf.writeLong(destination.getPos().toLong());
    buf.writeByte(destination.getSide().ordinal());
}
 
Example 5
Project: uniquecrops   File: PacketUCEffect.java   Source Code and License Vote up 5 votes
@Override
public void toBytes(ByteBuf buf) {
	
	buf.writeShort(type.ordinal());
	buf.writeDouble(x);
	buf.writeDouble(y);
	buf.writeDouble(z);
	buf.writeInt(loopSize);
}
 
Example 6
Project: connor41-etfuturum2   File: ArmourStandInteractMessage.java   Source Code and License Vote up 5 votes
@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(dimID);
	buf.writeInt(standID);
	buf.writeInt(playerID);
	buf.writeDouble(hitPos.xCoord);
	buf.writeDouble(hitPos.yCoord);
	buf.writeDouble(hitPos.zCoord);
}
 
Example 7
Project: Machines-and-Stuff   File: MessageMachineBase.java   Source Code and License Vote up 5 votes
@Override
public void toBytes(ByteBuf buf) {
    
    buf.writeInt(this.x);
    buf.writeInt(this.y);
    buf.writeInt(this.z);
    
    buf.writeByte(this.state);
    
    buf.writeInt(this.needCycleTime);
    buf.writeInt(this.itemCycleTime);
    buf.writeInt(this.deviceCycleTime);
    buf.writeLong(this.energy);
}
 
Example 8
Project: Solar   File: ServerToClientPacket.java   Source Code and License Vote up 5 votes
@Override
public void toBytes(ByteBuf buf) {
	PacketBuffer beef = new PacketBuffer(buf);
	try {
		buf.writeInt(PacketHandler.HANDLERS.indexOf(handler));
		beef.writeCompoundTag(data);
	} catch(Exception e) {
		Solar.LOG.error("[Packet] Failed to send packet");
		e.printStackTrace();
	}
}
 
Example 9
Project: needtobreath   File: PacketIntegersFromServer.java   Source Code and License Vote up 5 votes
@Override
public void toBytes(ByteBuf buf) {
    NetworkTools.writePos(buf, pos);
    buf.writeInt(integers.length);
    for (int i : integers) {
        buf.writeInt(i);
    }
}
 
Example 10
Project: angel   File: PartitionRequest.java   Source Code and License Vote up 5 votes
@Override
public void serialize(ByteBuf buf) {
  super.serialize(buf);
  buf.writeBoolean(comeFromPs);
  buf.writeInt(clock);
  partKey.serialize(buf);
  //if(comeFromPs) {
  //  buf.writeInt(psId.getIndex());
  //  byte[] data = location.getIp().getBytes();
  //  buf.writeInt(data.length);
  //  buf.writeBytes(data);
  //  buf.writeInt(location.getPort());
  //}
}
 
Example 11
Project: CustomWorldGen   File: ForgeMessage.java   Source Code and License Vote up 5 votes
@Override
void toBytes(ByteBuf bytes)
{
    bytes.writeInt(this.dimensionId);
    byte[] data = this.providerId.getBytes(Charsets.UTF_8);
    bytes.writeShort(data.length);
    bytes.writeBytes(data);
}
 
Example 12
Project: pnc-repressurized   File: PacketSetGlobalVariable.java   Source Code and License Vote up 5 votes
@Override
public void toBytes(ByteBuf buf) {
    ByteBufUtils.writeUTF8String(buf, varName);
    buf.writeInt(value.getX());
    buf.writeInt(value.getY());
    buf.writeInt(value.getZ());
}
 
Example 13
Project: BaseClient   File: TileEntityCommandBlock.java   Source Code and License Vote up 4 votes
public void func_145757_a(ByteBuf p_145757_1_)
{
    p_145757_1_.writeInt(TileEntityCommandBlock.this.pos.getX());
    p_145757_1_.writeInt(TileEntityCommandBlock.this.pos.getY());
    p_145757_1_.writeInt(TileEntityCommandBlock.this.pos.getZ());
}
 
Example 14
Project: DankNull   File: PacketSetSelectedItem.java   Source Code and License Vote up 4 votes
@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(index);
}
 
Example 15
Project: MineCamera   File: MessageFailLoadImage.java   Source Code and License Vote up 4 votes
@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(type.ordinal());
	buf.writeInt(imagename.length());
	buf.writeBytes(imagename.getBytes());
}
 
Example 16
Project: Never-Enough-Currency   File: MessageSyncAdd.java   Source Code and License Vote up 4 votes
@Override
public void toBytes(ByteBuf buf) {
	buf.writeInt(this.entityId);
	buf.writeFloat(amount);
}
 
Example 17
Project: pnc-repressurized   File: PacketOpenTubeModuleGui.java   Source Code and License Vote up 4 votes
@Override
public void toBytes(ByteBuf buf) {
    super.toBytes(buf);
    buf.writeInt(guiID);
}
 
Example 18
Project: message-broker   File: LongString.java   Source Code and License Vote up 4 votes
@Override
public void write(ByteBuf buf) {
    buf.writeInt((int) length);
    buf.writeBytes(content);
}
 
Example 19
Project: athena   File: MessageEncoder.java   Source Code and License Vote up 4 votes
@Override
protected void encode(
        ChannelHandlerContext context,
        InternalMessage message,
        ByteBuf out) throws Exception {

    out.writeInt(this.preamble);

    // write message id
    out.writeLong(message.id());

    Endpoint sender = message.sender();

    IpAddress senderIp = sender.host();
    if (senderIp.version() == Version.INET) {
        out.writeByte(0);
    } else {
        out.writeByte(1);
    }
    out.writeBytes(senderIp.toOctets());

    // write sender port
    out.writeInt(sender.port());

    byte[] messageTypeBytes = message.type().getBytes(Charsets.UTF_8);

    // write length of message type
    out.writeInt(messageTypeBytes.length);

    // write message type bytes
    out.writeBytes(messageTypeBytes);

    // write message status value
    out.writeInt(message.status().ordinal());

    byte[] payload = message.payload();

    // write payload length
    out.writeInt(payload.length);

    // write payload.
    out.writeBytes(payload);
}
 
Example 20
Project: MineDonate   File: Utils.java   Source Code and License Vote up 2 votes
public static void netWriteString ( ByteBuf buf, String str ) throws UnsupportedEncodingException {
	
    buf . writeInt ( str . getBytes ( "UTF-8" ) . length ) ;
    buf . writeBytes ( str . getBytes ( "UTF-8" ) ) ;
    
}