List of usage examples for io.netty.buffer ByteBuf writeDouble
public abstract ByteBuf writeDouble(double value);
From source file:io.github.vastframework.codecs.primitives.EncodingPrimitiveSupport.java
License:Apache License
default void encodeDouble(ByteBuf buffer, double value) { buffer.writeDouble(value); }
From source file:io.hekate.network.netty.NettyMessageTest.java
License:Apache License
@Test public void testPreview() throws Exception { ByteBuf buf = Unpooled.buffer(); buf.writeByte(10);/* w w w. j a v a 2 s .com*/ 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()); }
From source file:io.hydramq.core.type.converters.MessagePropertiesConverter.java
License:Open Source License
@Override public void write(final ConversionContext context, final MessageProperties properties, final ByteBuf buffer) { int flags = 0; if (properties.getStringKeys().size() > 0) { flags = flags | HAS_STRING_PROPERTIES; }/* w ww . ja va 2s . c om*/ if (properties.getBooleanKeys().size() > 0) { flags = flags | HAS_BOOLEAN_PROPERTIES; } if (properties.getIntegerKeys().size() > 0) { flags = flags | HAS_INTEGER_PROPERTIES; } if (properties.getLongKeys().size() > 0) { flags = flags | HAS_LONG_PROPERTIES; } if (properties.getFloatKeys().size() > 0) { flags = flags | HAS_FLOAT_PROPERTIES; } if (properties.getDoubleKeys().size() > 0) { flags = flags | HAS_DOUBLE_PROPERTIES; } if (properties.getBytesKeys().size() > 0) { flags = flags | HAS_BYTES_PROPERTIES; } if (properties.getShortKeys().size() > 0) { flags = flags | HAS_SHORT_PROPERTIES; } if (properties.getByteKeys().size() > 0) { flags = flags | HAS_BYTE_PROPERTIES; } buffer.writeInt(flags); if (properties.getStringKeys().size() > 0) { buffer.writeInt(properties.getStringKeys().size()); for (String key : properties.getStringKeys()) { context.write(String.class, key, buffer); context.write(String.class, properties.getString(key), buffer); } } if (properties.getBooleanKeys().size() > 0) { buffer.writeInt(properties.getBooleanKeys().size()); for (String key : properties.getBooleanKeys()) { context.write(String.class, key, buffer); buffer.writeBoolean(properties.getBoolean(key)); } } if (properties.getIntegerKeys().size() > 0) { buffer.writeInt(properties.getIntegerKeys().size()); for (String key : properties.getIntegerKeys()) { context.write(String.class, key, buffer); buffer.writeInt(properties.getInteger(key)); } } if (properties.getLongKeys().size() > 0) { buffer.writeInt(properties.getLongKeys().size()); for (String key : properties.getLongKeys()) { context.write(String.class, key, buffer); buffer.writeLong(properties.getLong(key)); } } if (properties.getFloatKeys().size() > 0) { buffer.writeInt(properties.getFloatKeys().size()); for (String key : properties.getFloatKeys()) { context.write(String.class, key, buffer); buffer.writeFloat(properties.getFloat(key)); } } if (properties.getDoubleKeys().size() > 0) { buffer.writeInt(properties.getDoubleKeys().size()); for (String key : properties.getDoubleKeys()) { context.write(String.class, key, buffer); buffer.writeDouble(properties.getDouble(key)); } } if (properties.getBytesKeys().size() > 0) { buffer.writeInt(properties.getBytesKeys().size()); for (String key : properties.getBytesKeys()) { context.write(String.class, key, buffer); context.write(byte[].class, properties.getBytes(key), buffer); } } if (properties.getShortKeys().size() > 0) { buffer.writeInt(properties.getShortKeys().size()); for (String key : properties.getShortKeys()) { context.write(String.class, key, buffer); buffer.writeShort(properties.getShort(key)); } } if (properties.getByteKeys().size() > 0) { buffer.writeInt(properties.getByteKeys().size()); for (String key : properties.getByteKeys()) { context.write(String.class, key, buffer); buffer.writeByte(properties.getByte(key)); } } }
From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java
License:Apache License
private static void binaryEncodeFLOAT8(Number value, ByteBuf buff) { buff.writeDouble(value.doubleValue()); }
From source file:ivorius.ivtoolkit.network.IvPacketHelper.java
License:Apache License
public static void writeNumber(ByteBuf buffer, Number number) { if (number instanceof Byte) { buffer.writeByte((Byte) number); } else if (number instanceof Double) { buffer.writeDouble((Double) number); } else if (number instanceof Float) { buffer.writeFloat((Float) number); } else if (number instanceof Integer) { buffer.writeInt((Integer) number); } else if (number instanceof Long) { buffer.writeLong((Long) number); } else if (number instanceof Short) { buffer.writeShort((Short) number); } else {/* www. j a va2 s . c o m*/ throw new IllegalArgumentException(); } }
From source file:k4unl.minecraft.Hydraulicraft.network.LocationDoublePacket.java
License:LGPL
@Override public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { buffer.writeDouble(x); buffer.writeDouble(y); buffer.writeDouble(z); }
From source file:makeo.gadomancy.common.network.packets.PacketTCWispyLine.java
License:LGPL
@Override public void toBytes(ByteBuf buf) { buf.writeInt(dimId);/*from w ww .j a v a 2 s.c o m*/ buf.writeDouble(pedestalX); buf.writeDouble(pedestalY); buf.writeDouble(pedestalZ); buf.writeDouble(originX); buf.writeDouble(originY); buf.writeDouble(originZ); buf.writeInt(tickCap); buf.writeInt(colorAsInt); }
From source file:mal.carbonization.network.FuelConversionBenchMessageServer.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { buf.writeInt(xpos);//from w ww . j a v a 2 s . c o m buf.writeInt(ypos); buf.writeInt(zpos); buf.writeBoolean(fuelState); buf.writeInt(currentIndex); buf.writeInt(craftingCooldown); buf.writeInt(maxCooldown); buf.writeDouble(bonusYield); buf.writeBoolean(voidUpgrade); buf.writeInt(ejectSide); buf.writeInt(maxFuel); buf.writeInt(fuelStack); buf.writeBoolean(inventory); if (inventory) { byte[] i = ItemStacktoByteArray(inventoryStacks); buf.writeInt(i.length); buf.writeInt(inventoryStacks.length); buf.writeBytes(i); byte[] o = ItemStacktoByteArray(upgradeStacks); buf.writeInt(o.length); buf.writeInt(upgradeStacks.length); buf.writeBytes(o); } }
From source file:mal.carbonization.network.FurnacesMessage.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { buf.writeInt(xpos);/* w w w . j a v a2s .com*/ buf.writeInt(ypos); buf.writeInt(zpos); buf.writeByte(facing); buf.writeInt(metadata); buf.writeBoolean(usesExtraTime); buf.writeBoolean(isActive); buf.writeDouble(furnaceCookTimeMultiplyer); buf.writeInt(furnaceMaxCookTime); buf.writeInt(tier); buf.writeInt(furnaceBurnTime); buf.writeInt(currentItemBurnTime); buf.writeInt(furnaceCookTime); byte[] b = ItemStacktoByteArray(inventory); buf.writeInt(b.length); buf.writeInt(inventory.length); buf.writeBytes(b); }
From source file:mal.carbonization.network.MultiblockFurnaceMessageServer.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { buf.writeInt(xpos);//from w w w .jav a 2 s.co m buf.writeInt(ypos); buf.writeInt(zpos); buf.writeInt(xsize); buf.writeInt(ysize); buf.writeInt(zsize); buf.writeBoolean(useInventory); buf.writeByte(offset.length); for (int i = 0; i < offset.length; i++) buf.writeInt(offset[i]); buf.writeBoolean(properlyActivated); buf.writeInt(oreCapacity); buf.writeInt(slagTank); buf.writeByte(componentTiers.length); for (int i = 0; i < componentTiers.length; i++) buf.writeDouble(componentTiers[i]); if (useInventory) { byte[] b = ItemStacktoByteArray(inputStacks); buf.writeInt(b.length); buf.writeInt(inputStacks.length); buf.writeBytes(b); byte[] bb = ItemStacktoByteArray(outputStacks); buf.writeInt(bb.length); buf.writeInt(outputStacks.length); buf.writeBytes(bb); } buf.writeInt(fuelStack); buf.writeInt(numQueueJobs); buf.writeInt(grossCookTime); buf.writeInt(grossMaxCookTime); buf.writeInt(maxFuelCapacity); buf.writeBoolean(passFuel); buf.writeInt(queue.size()); for (MultiblockWorkQueueItem item : queue) { byte[] qb = queueItemtoBytes(item); buf.writeInt(qb.length); buf.writeBytes(qb); } try { ByteArrayOutputStream byteOut = new ByteArrayOutputStream(); ObjectOutputStream out = new ObjectOutputStream(byteOut); out.writeObject(oreSlagInQueue); byte[] ob = byteOut.toByteArray(); buf.writeInt(ob.length); buf.writeBytes(ob); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }