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

The following are Jave code examples for showing how to use writeDouble() 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: FullPartitionAggrResult.java   Source Code and License Vote up 6 votes
@Override
public void serialize(ByteBuf buf) {
  int rows = result.length;
  int cols = result[0].length;

  buf.writeInt(rows);
  buf.writeInt(cols);
  for (int i = 0; i < rows; i++) {
    for (int j = 0; j < cols; j++) {
      buf.writeDouble(result[i][j]);
    }
  }

  buf.writeInt(partInfo.length);
  for (int i = 0; i < partInfo.length; i++) {
    buf.writeInt(partInfo[i]);
  }
}
 
Example 2
Project: angel   File: ServerSparseDoubleRowTest.java   Source Code and License Vote up 6 votes
@Test
public void testUpdate() throws Exception {
  serverSparseDoubleRow = new ServerSparseDoubleRow(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) + serverSparseDoubleRow.getData().get(0);
  double newValue1 = buf.getDouble(8) + serverSparseDoubleRow.getData().get(1);
  serverSparseDoubleRow.update(RowType.T_DOUBLE_DENSE, buf, 3);
  assertEquals(serverSparseDoubleRow.getData().get(0), newValue0, 0.000);
  assertEquals(serverSparseDoubleRow.getData().get(1), newValue1, 0.000);
  assertEquals(serverSparseDoubleRow.getData().get(2), -1, 0.000);

  serverSparseDoubleRow = new ServerSparseDoubleRow(rowId, startCol, endCol);
  buf = Unpooled.buffer(0);
  LOG.info(buf);
  buf.writeInt(0);
  buf.writeDouble(1.00);
  buf.writeInt(2);
  buf.writeDouble(-2.00);
  serverSparseDoubleRow.update(RowType.T_DOUBLE_SPARSE, buf, 2);
  assertEquals(serverSparseDoubleRow.getData().get(0), 1, 0.000);
  assertEquals(serverSparseDoubleRow.getData().get(1), 0, 0.000);
  assertEquals(serverSparseDoubleRow.getData().get(2), -2, 0.000);
}
 
Example 3
Project: angel   File: DefaultRowUpdaterTest.java   Source Code and License Vote up 6 votes
@Test
public void testUpdateDoubleSparseToDoubleSparse() throws Exception {
  ServerSparseDoubleRow serverSparseDoubleRow =
      new ServerSparseDoubleRow(rowId, startCol, endCol);
  ByteBuf buf = Unpooled.buffer(16);
  buf.writeInt(0);
  buf.writeDouble(0.00);
  buf.writeInt(1);
  buf.writeDouble(1.00);
  buf.writeInt(2);
  buf.writeDouble(2.00);
  rowUpdater.updateDoubleSparseToDoubleSparse(3, buf, serverSparseDoubleRow);
  Int2DoubleOpenHashMap hashMap = new Int2DoubleOpenHashMap();
  hashMap.addTo(0, 0.00);
  hashMap.addTo(1, 1.00);
  hashMap.addTo(2, 2.00);
  assertEquals(serverSparseDoubleRow.getData(), hashMap);
}
 
Example 4
Project: angel   File: ServerSparseDoubleLongKeyRow.java   Source Code and License Vote up 6 votes
@Override
public void serialize(ByteBuf buf) {
  try {
    lock.readLock().lock();
    super.serialize(buf);
    buf.writeInt(index2ValueMap.size());

    ObjectIterator<Long2DoubleMap.Entry> iter = index2ValueMap.long2DoubleEntrySet().fastIterator();
    Long2DoubleMap.Entry entry = null;
    while (iter.hasNext()) {
      entry = iter.next();
      buf.writeLong(entry.getLongKey());
      buf.writeDouble(entry.getDoubleValue());
    }
  } finally {
    lock.readLock().unlock();
  }
}
 
Example 5
Project: angel   File: ServerDenseDoubleRowTest.java   Source Code and License Vote up 6 votes
@Test
public void testDeserialize() throws Exception {
  ByteBuf buf = Unpooled.buffer(16);
  buf.writeInt(0);
  buf.writeInt(1);
  buf.writeLong(2);
  buf.writeLong(3);
  buf.writeInt(4);
  buf.writeInt(3);
  buf.writeDouble(-1.0);
  buf.writeDouble(-2.0);
  buf.writeDouble(-3.0);
  serverDenseDoubleRow.deserialize(buf);
  assertEquals(serverDenseDoubleRow.getRowId(), 0);
  assertEquals(serverDenseDoubleRow.getClock(), 1);
  assertEquals(serverDenseDoubleRow.getStartCol(), 2);
  assertEquals(serverDenseDoubleRow.getEndCol(), 3);
  assertEquals(serverDenseDoubleRow.getRowVersion(), 4);
  assertEquals(serverDenseDoubleRow.getData().get(0), -1, 0.0);
  assertEquals(serverDenseDoubleRow.getData().get(1), -2, 0.0);
  assertEquals(serverDenseDoubleRow.getData().get(2), -3, 0.0);
}
 
Example 6
Project: angel   File: ServerDenseDoubleRowTest.java   Source Code and License Vote up 6 votes
@Test
public void testWriteTo() throws Exception {
  ByteBuf buf = Unpooled.buffer(16);
  buf.writeDouble(0.00);
  buf.writeDouble(1.00);
  buf.writeDouble(2.00);
  serverDenseDoubleRow.update(RowType.T_DOUBLE_DENSE, buf, 3);
  DataOutputStream out = new DataOutputStream(new FileOutputStream("data"));
  serverDenseDoubleRow.writeTo(out);
  out.close();
  DataInputStream in = new DataInputStream(new FileInputStream("data"));
  assertEquals(in.readDouble(), 0, 0.00);
  assertEquals(in.readDouble(), 1, 0.00);
  assertEquals(in.readDouble(), 2, 0.00);
  in.close();
}
 
Example 7
Project: angel   File: ServerDenseDoubleRowTest.java   Source Code and License Vote up 6 votes
@Test
public void testReadFrom() throws Exception {
  ByteBuf buf = Unpooled.buffer(16);
  buf.writeDouble(10.00);
  buf.writeDouble(11.00);
  buf.writeDouble(12.00);
  serverDenseDoubleRow.update(RowType.T_DOUBLE_DENSE, buf, 3);
  DataOutputStream out = new DataOutputStream(new FileOutputStream("data"));
  serverDenseDoubleRow.writeTo(out);
  out.close();
  DataInputStream in = new DataInputStream(new FileInputStream("data"));
  ServerDenseDoubleRow newServerDenseDoubleRow =
      new ServerDenseDoubleRow(rowId, startCol, endCol);
  newServerDenseDoubleRow.readFrom(in);
  in.close();
  assertEquals(newServerDenseDoubleRow.getData().get(0), serverDenseDoubleRow.getData().get(0),
      0.00);
  assertEquals(newServerDenseDoubleRow.getData().get(1), serverDenseDoubleRow.getData().get(1),
      0.00);
  assertEquals(newServerDenseDoubleRow.getData().get(2), serverDenseDoubleRow.getData().get(2),
      0.00);
}
 
Example 8
Project: FlexMC   File: MessageS00SpawnObject.java   Source Code and License Vote up 5 votes
@Override
public void write( ByteBuf buf ) throws IOException {
    writeVarInt( entityId, buf );
    writeUUID( uuid, buf );
    buf.writeByte( type );
    buf.writeDouble( x );
    buf.writeDouble( y );
    buf.writeDouble( z );
    buf.writeByte( toAngle( yaw ) );
    buf.writeByte( toAngle( pitch ) );
    buf.writeInt( 1 );
    buf.writeShort( 1 );
    buf.writeShort( 1 );
    buf.writeShort( 1 );
}
 
Example 9
Project: angel   File: FullUpdateParam.java   Source Code and License Vote up 5 votes
@Override
public void serialize(ByteBuf buf) {
  super.serialize(buf);
  buf.writeInt(values.length);
  for (double value : values) {
    buf.writeDouble(value);
  }
}
 
Example 10
Project: Proyecto-DASI   File: AbsoluteMovementCommandsImplementation.java   Source Code and License Vote up 5 votes
@Override
public void toBytes(ByteBuf buf)
{
    buf.writeDouble(this.x);
    buf.writeDouble(this.y);
    buf.writeDouble(this.z);
    buf.writeFloat(this.yaw);
    buf.writeFloat(this.pitch);

    buf.writeBoolean(this.setX);
    buf.writeBoolean(this.setY);
    buf.writeBoolean(this.setZ);
    buf.writeBoolean(this.setYaw);
    buf.writeBoolean(this.setPitch);
}
 
Example 11
Project: minecraft-quiverbow   File: EnderAccelerator.java   Source Code and License Vote up 5 votes
@Override
public void writeSpawnData(ByteBuf buffer) 			// save extra data on the server
   {
	buffer.writeDouble(this.ownerX);
	buffer.writeDouble(this.ownerY);
	buffer.writeDouble(this.ownerZ);
   }
 
Example 12
Project: angel   File: ServerSparseDoubleRowTest.java   Source Code and License Vote up 5 votes
@Test
public void testBufferLen() throws Exception {
  ByteBuf buf = Unpooled.buffer(16);
  serverSparseDoubleRow.setClock(8);
  buf.writeDouble(0.00);
  buf.writeDouble(1.00);
  buf.writeDouble(-1.00);
  serverSparseDoubleRow.update(RowType.T_DOUBLE_DENSE, buf, 3);
  assertEquals(serverSparseDoubleRow.bufferLen(), 20 + 4 + 3 * 12);
}
 
Example 13
Project: genera   File: EntityFaerie.java   Source Code and License Vote up 5 votes
@Override
public void writeSpawnData(ByteBuf buffer) {
    buffer.writeDouble(faerieInformation.getMaxHealth());
    buffer.writeFloat(faerieInformation.getSize());
    buffer.writeInt(faerieInformation.getType());
    buffer.writeInt(faerieInformation.getLevel());
    buffer.writeInt(faerieInformation.getCurrentExp());
}
 
Example 14
Project: FlexMC   File: MessageS4CEntityTeleport.java   Source Code and License Vote up 5 votes
@Override
public void write( ByteBuf buf ) throws IOException {
    writeVarInt( entityId, buf );
    buf.writeDouble( x );
    buf.writeDouble( y );
    buf.writeDouble( z );
    buf.writeByte( toAngle( yaw ) );
    buf.writeByte( toAngle( pitch ) );
    buf.writeBoolean( onGround );
}
 
Example 15
Project: angel   File: DefaultRowUpdaterTest.java   Source Code and License Vote up 5 votes
@Test
public void testUpdateDoubleDenseToDoubleDense() throws Exception {
  ServerDenseDoubleRow serverDenseDoubleRow = new ServerDenseDoubleRow(rowId, startCol, endCol);
  ByteBuf buf = Unpooled.buffer(16);
  buf.writeDouble(0.00);
  buf.writeDouble(1.00);
  buf.writeDouble(-1.00);
  rowUpdater.updateDoubleDenseToDoubleDense(3, buf, serverDenseDoubleRow);
  assertEquals(serverDenseDoubleRow.getData().get(0), 0, 0.00);
  assertEquals(serverDenseDoubleRow.getData().get(1), 1, 0.00);
  assertEquals(serverDenseDoubleRow.getData().get(2), -1, 0.00);
}
 
Example 16
Project: harshencastle   File: MessagePacketPlayerTeleportEffects.java   Source Code and License Vote up 4 votes
@Override
public void toBytes(ByteBuf buf) {		
	buf.writeDouble(position.x);
	buf.writeDouble(position.y);
	buf.writeDouble(position.z);
}
 
Example 17
Project: angel   File: Zip3MapWithIndexFuncTest.java   Source Code and License Vote up 4 votes
@Override
public void serialize(ByteBuf buf) {
  buf.writeDouble(multiplier);
}
 
Example 18
Project: angel   File: MapFuncTest.java   Source Code and License Vote up 4 votes
@Override
public void serialize(ByteBuf buf) {
  buf.writeDouble(multiplier);
}
 
Example 19
Project: angel   File: Zip2MapWithIndexFuncTest.java   Source Code and License Vote up 4 votes
@Override
public void serialize(ByteBuf buf) {
  buf.writeDouble(multiplier);
}
 
Example 20
Project: hekate   File: NettyMessageTest.java   Source Code and License Vote up 4 votes
@Test
public void testPreview() throws Exception {
    ByteBuf buf = Unpooled.buffer();

    buf.writeByte(10);
    buf.writeBoolean(true);
    buf.writeInt(100);
    buf.writeLong(1000);
    buf.writeDouble(1.01);

    NettyMessage msg = new NettyMessage(buf, new Codec<Object>() {
        @Override
        public boolean isStateful() {
            return false;
        }

        @Override
        public Class<Object> baseType() {
            return Object.class;
        }

        @Override
        public Object decode(DataReader in) throws IOException {
            throw new AssertionError("Should not be called.");
        }

        @Override
        public void encode(Object obj, DataWriter out) throws IOException {
            throw new AssertionError("Should not be called.");
        }
    });

    assertEquals((byte)10, (byte)msg.preview(DataInput::readByte));
    assertEquals(0, buf.readerIndex());

    assertTrue(msg.previewBoolean(m -> {
        m.skipBytes(1);

        return m.readBoolean();
    }));
    assertEquals(0, buf.readerIndex());

    assertEquals(100, msg.previewInt(m -> {
        m.skipBytes(2);

        return m.readInt();
    }));
    assertEquals(0, buf.readerIndex());

    assertEquals(1000, msg.previewLong(m -> {
        m.skipBytes(6);

        return m.readLong();
    }));
    assertEquals(0, buf.readerIndex());

    assertEquals(1.01, msg.previewDouble(m -> {
        m.skipBytes(14);

        return m.readDouble();
    }), 1000);
    assertEquals(0, buf.readerIndex());

    assertEquals(1, buf.refCnt());

    msg.release();

    assertEquals(0, buf.refCnt());
}