List of usage examples for io.netty.buffer ByteBuf writeBoolean
public abstract ByteBuf writeBoolean(boolean value);
From source file:hellfirepvp.astralsorcery.common.util.ByteBufUtils.java
License:Open Source License
public static void writeFluidStack(ByteBuf byteBuf, @Nullable FluidStack stack) { boolean defined = stack != null; byteBuf.writeBoolean(defined); if (defined) { NBTTagCompound tag = new NBTTagCompound(); stack.writeToNBT(tag);//from w w w.j a va2 s . c o m writeNBTTag(byteBuf, tag); } }
From source file:herddb.proto.PduCodec.java
License:Apache License
private static void writeObject(ByteBuf byteBuf, Object v) { if (v == null) { byteBuf.writeByte(TYPE_NULL);//from www. j av a2s . c o m } else if (v instanceof RawString) { byteBuf.writeByte(TYPE_STRING); ByteBufUtils.writeRawString(byteBuf, (RawString) v); } else if (v instanceof String) { byteBuf.writeByte(TYPE_STRING); ByteBufUtils.writeString(byteBuf, (String) v); } else if (v instanceof Long) { byteBuf.writeByte(TYPE_LONG); byteBuf.writeLong((Long) v); } else if (v instanceof Integer) { byteBuf.writeByte(TYPE_INTEGER); byteBuf.writeInt((Integer) v); } else if (v instanceof Boolean) { byteBuf.writeByte(TYPE_BOOLEAN); byteBuf.writeBoolean((Boolean) v); } else if (v instanceof java.util.Date) { byteBuf.writeByte(TYPE_TIMESTAMP); byteBuf.writeLong(((java.util.Date) v).getTime()); } else if (v instanceof Double) { byteBuf.writeByte(TYPE_DOUBLE); byteBuf.writeDouble((Double) v); } else if (v instanceof Float) { byteBuf.writeByte(TYPE_DOUBLE); byteBuf.writeDouble((Float) v); } else if (v instanceof Short) { byteBuf.writeByte(TYPE_SHORT); byteBuf.writeLong((Short) v); } else if (v instanceof byte[]) { byteBuf.writeByte(TYPE_BYTEARRAY); ByteBufUtils.writeArray(byteBuf, (byte[]) v); } else if (v instanceof Byte) { byteBuf.writeByte(TYPE_BYTE); byteBuf.writeByte((Byte) v); } else { throw new IllegalArgumentException("bad data type " + v.getClass()); } }
From source file:hivemall.mix.MixMessageEncoder.java
License:Open Source License
@Override protected void encode(ChannelHandlerContext ctx, MixMessage msg, ByteBuf out) throws Exception { int startIdx = out.writerIndex(); out.writeBytes(LENGTH_PLACEHOLDER);/*from w w w . ja va2 s . c o m*/ MixEventName event = msg.getEvent(); byte b = event.getID(); out.writeByte(b); Object feature = msg.getFeature(); encodeObject(feature, out); float weight = msg.getWeight(); out.writeFloat(weight); float covariance = msg.getCovariance(); out.writeFloat(covariance); short clock = msg.getClock(); out.writeShort(clock); int deltaUpdates = msg.getDeltaUpdates(); out.writeInt(deltaUpdates); boolean cancelRequest = msg.isCancelRequest(); out.writeBoolean(cancelRequest); String groupId = msg.getGroupID(); writeString(groupId, out); int endIdx = out.writerIndex(); out.setInt(startIdx, endIdx - startIdx - 4); }
From source file:io.github.vastframework.codecs.primitives.EncodingPrimitiveSupport.java
License:Apache License
default void encodeBoolean(ByteBuf buffer, boolean value) { buffer.writeBoolean(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);//from w w w . ja v a2s. c o m 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; }/*ww w. java2 s . c o m*/ 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.lunamc.plugins.example.netty.ExamplePlayHandler.java
License:Apache License
private void writeJoinGame(ChannelHandlerContext ctx) { ByteBuf out = ctx.alloc().buffer(); // Write packet id of join game (0x23) ProtocolUtils.writeVarInt(out, 0x23); // Write entity id out.writeInt(42);/*from w ww.j a va 2 s .com*/ // Write game mode (0 = survival) out.writeByte(0); // Write dimension (0 = overworld) out.writeInt(0); // Write difficulty (0 = peaceful) out.writeByte(0); // Write max players out.writeByte(1); // Write level type ProtocolUtils.writeString(out, "default"); // Write reduced debug info out.writeBoolean(false); // Send it to the client ctx.writeAndFlush(out, ctx.voidPromise()); }
From source file:io.reactiverse.pgclient.impl.codec.DataTypeCodec.java
License:Apache License
private static void binaryEncodeBOOL(Boolean value, ByteBuf buff) { buff.writeBoolean(value); }
From source file:it.kytech.smartccraft.network.message.MessageTileChargeStation.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { buf.writeInt(x);//from w w w . ja v a 2 s .c o m buf.writeInt(y); buf.writeInt(z); buf.writeByte(orientation); buf.writeByte(state); buf.writeInt(customName.length()); buf.writeBytes(customName.getBytes()); if (ownerUUID != null) { buf.writeBoolean(true); buf.writeLong(ownerUUID.getMostSignificantBits()); buf.writeLong(ownerUUID.getLeastSignificantBits()); } else { buf.writeBoolean(false); } buf.writeByte(status); }
From source file:it.kytech.smartccraft.network.message.MessageTileEntitySCC.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { buf.writeInt(x);/*from w w w.jav a 2 s .c om*/ buf.writeInt(y); buf.writeInt(z); buf.writeByte(orientation); buf.writeByte(state); buf.writeInt(customName.length()); buf.writeBytes(customName.getBytes()); if (ownerUUID != null) { buf.writeBoolean(true); buf.writeLong(ownerUUID.getMostSignificantBits()); buf.writeLong(ownerUUID.getLeastSignificantBits()); } else { buf.writeBoolean(false); } toBytesChild(buf); }