List of usage examples for io.netty.buffer ByteBuf writeByte
public abstract ByteBuf writeByte(int value);
From source file:com.flowpowered.engine.network.codec.ChunkDataCodec.java
License:MIT License
@Override public ByteBuf encode(ByteBuf buffer, ChunkDataMessage message) throws IOException { if (message.isUnload()) { buffer.writeByte(ISUNLOAD); // we're unloading buffer.writeInt(message.getX()); buffer.writeInt(message.getY()); buffer.writeInt(message.getZ()); } else {/*from www .ja v a 2 s . c om*/ int dataSize = INTIAL_DATA_SIZE; byte[] uncompressedData = new byte[dataSize]; byte[] compressedData = new byte[dataSize]; int index = 0; for (int i : message.getBlocks()) { uncompressedData[index++] = (byte) i; uncompressedData[index++] = (byte) (i >> 8); uncompressedData[index++] = (byte) (i >> 16); uncompressedData[index++] = (byte) (i >> 24); } Deflater deflater = new Deflater(); deflater.setInput(uncompressedData); deflater.finish(); int compressedSize = deflater.deflate(compressedData); deflater.end(); if (compressedSize == 0) { throw new IOException("Not all data compressed!"); } buffer.writeByte(0); // Not unload buffer.writeInt(message.getX()); buffer.writeInt(message.getY()); buffer.writeInt(message.getZ()); buffer.writeInt(compressedSize); buffer.writeBytes(compressedData, 0, compressedSize); } return buffer; }
From source file:com.flowpowered.engine.network.codec.InputSnapshotCodec.java
License:MIT License
@Override public ByteBuf encode(ByteBuf buf, InputSnapshotMessage message) throws IOException { buf.writeInt(message.getKeyEvents().size()); for (KeyboardEvent e : message.getKeyEvents()) { buf.writeByte(e.getKeyId()); buf.writeBoolean(e.wasPressedDown()); }/*from w w w. j a v a 2 s . c o m*/ buf.writeInt(message.getMouseEvents().size()); for (MouseEvent e : message.getMouseEvents()) { buf.writeInt(e.getX()); buf.writeInt(e.getY()); buf.writeInt(e.getDX()); buf.writeInt(e.getDY()); buf.writeInt(e.getDWheel()); buf.writeInt(e.getButton()); buf.writeBoolean(e.wasPressedDown()); } buf.writeFloat(message.getDt()); buf.writeBoolean(message.isMouseGrabbed()); return buf; }
From source file:com.flowpowered.engine.network.codec.UpdateEntityCodec.java
License:MIT License
@Override public ByteBuf encode(ByteBuf buf, UpdateEntityMessage message) { buf.writeByte(message.getAction().ordinal()); buf.writeInt(message.getEntityId()); switch (message.getAction()) { case REMOVE:/*from w w w . j a va2 s . c om*/ break; case ADD: case TRANSFORM: FlowByteBufUtils.writeTransform(buf, message.getTransform()); break; case POSITION: throw new UnsupportedOperationException("Position is unimplemented!"); default: throw new IllegalArgumentException("Unknown UpdateAction!"); } return buf; }
From source file:com.flowpowered.engine.network.FlowProtocol.java
License:MIT License
@Override public ByteBuf writeHeader(ByteBuf header, Codec.CodecRegistration codec, ByteBuf data) { return header.writeByte(codec.getOpcode()); }
From source file:com.flowpowered.network.util.ByteBufUtils.java
License:MIT License
/** * Writes an integer into the byte buffer using the least possible amount of bits. * * @param buf The byte buffer to write too * @param value The integer value to write */// w ww . j a v a 2s . c om public static void writeVarInt(ByteBuf buf, int value) { byte part; while (true) { part = (byte) (value & 0x7F); value >>>= 7; if (value != 0) { part |= 0x80; } buf.writeByte(part); if (value == 0) { break; } } }
From source file:com.flowpowered.network.util.ByteBufUtils.java
License:MIT License
/** * Writes an integer into the byte buffer using the least possible amount of bits. * * @param buf The byte buffer to write too * @param value The long value to write/*from www .j ava 2 s . c om*/ */ public static void writeVarLong(ByteBuf buf, long value) { byte part; while (true) { part = (byte) (value & 0x7F); value >>>= 7; if (value != 0) { part |= 0x80; } buf.writeByte(part); if (value == 0) { break; } } }
From source file:com.flowpowered.networking.util.ByteBufUtils.java
License:MIT License
/** * Writes an integer into the byte buffer using the least possible amount of bits. * * @param buf The byte buffer to write too * @param value The integer value to write *//* w w w .ja va2 s. c om*/ public static void writeVarInt(ByteBuf buf, int value) { int part; while (true) { part = value & 0x7F; value >>>= 7; if (value != 0) { part |= 0x80; } buf.writeByte(part); if (value == 0) { break; } } }
From source file:com.flysoloing.learning.network.netty.udt.echo.message.MsgEchoClientHandler.java
License:Apache License
public MsgEchoClientHandler() { super(false); final ByteBuf byteBuf = Unpooled.buffer(MsgEchoClient.SIZE); for (int i = 0; i < byteBuf.capacity(); i++) { byteBuf.writeByte((byte) i); }//from w w w. j a v a2s.c o m message = new UdtMessage(byteBuf); }
From source file:com.flysoloing.learning.network.netty.udt.echo.rendezvous.MsgEchoPeerHandler.java
License:Apache License
public MsgEchoPeerHandler(final int messageSize) { super(false); final ByteBuf byteBuf = Unpooled.buffer(messageSize); for (int i = 0; i < byteBuf.capacity(); i++) { byteBuf.writeByte((byte) i); }/*from ww w .ja va 2s . c o m*/ message = new UdtMessage(byteBuf); }
From source file:com.forgetutorials.lib.network.SubPacketTileEntityChild.java
License:LGPL
public ByteBuf populate() { ByteBuf buf = Unpooled.buffer(); try {/* w ww. j ava 2 s . c o m*/ buf.writeByte(this.packetType.ordinal()); writeData(buf); } catch (IOException e) { e.printStackTrace(System.err); } return buf; }