List of usage examples for io.netty.buffer ByteBuf writeByte
public abstract ByteBuf writeByte(int value);
From source file:alluxio.worker.netty.AbstractWriteHandlerTest.java
License:Apache License
/** * @param len length of the data buffer//from w w w . j a v a 2 s .com * @return a newly created data buffer */ protected DataBuffer newDataBuffer(int len) { ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(len); for (int i = 0; i < len; i++) { byte value = (byte) (RANDOM.nextInt() % Byte.MAX_VALUE); buf.writeByte(value); } return new DataNettyBufferV2(buf); }
From source file:alluxio.worker.netty.DataServerBlockWriteHandlerTest.java
License:Apache License
@Override protected RPCProtoMessage buildWriteRequest(long offset, int len) { Protocol.WriteRequest writeRequest = Protocol.WriteRequest.newBuilder().setId(1L).setOffset(offset) .setSessionId(1L).setType(Protocol.RequestType.ALLUXIO_BLOCK).build(); DataBuffer buffer = null;/*from w ww. j a v a 2 s. co m*/ if (len > 0) { ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(len); for (int i = 0; i < len; i++) { byte value = (byte) (mRandom.nextInt() % Byte.MAX_VALUE); buf.writeByte(value); mChecksum += BufferUtils.byteToInt(value); } buffer = new DataNettyBufferV2(buf); } if (len == EOF) { writeRequest = writeRequest.toBuilder().setEof(true).build(); } if (len == CANCEL) { writeRequest = writeRequest.toBuilder().setCancel(true).build(); } return new RPCProtoMessage(new ProtoMessage(writeRequest), buffer); }
From source file:alluxio.worker.netty.DataServerUFSFileWriteHandlerTest.java
License:Apache License
@Override protected RPCProtoMessage buildWriteRequest(long offset, int len) { Protocol.WriteRequest writeRequest = Protocol.WriteRequest.newBuilder().setId(1L).setOffset(offset) .setType(Protocol.RequestType.UFS_FILE).build(); DataBuffer buffer = null;/*from w w w .j a va 2 s.com*/ if (len > 0) { ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(len); for (int i = 0; i < len; i++) { byte value = (byte) (mRandom.nextInt() % Byte.MAX_VALUE); buf.writeByte(value); mChecksum += BufferUtils.byteToInt(value); } buffer = new DataNettyBufferV2(buf); } if (len == EOF) { writeRequest = writeRequest.toBuilder().setEof(true).build(); } if (len == CANCEL) { writeRequest = writeRequest.toBuilder().setCancel(true).build(); } return new RPCProtoMessage(new ProtoMessage(writeRequest), buffer); }
From source file:appeng.core.sync.packets.PacketAssemblerAnimation.java
License:Open Source License
public PacketAssemblerAnimation(final BlockPos pos, final byte rate, final IAEItemStack is) throws IOException { final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeInt(this.x = pos.getX()); data.writeInt(this.y = pos.getY()); data.writeInt(this.z = pos.getZ()); data.writeByte(this.rate = rate); is.writeToPacket(data);//from ww w . j a va 2 s. co m this.is = is; this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketClick.java
License:Open Source License
public PacketClick(final BlockPos pos, final EnumFacing side, final float hitX, final float hitY, final float hitZ, final EnumHand hand) { final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeInt(this.x = pos.getX()); data.writeInt(this.y = pos.getY()); data.writeInt(this.z = pos.getZ()); if (side == null) { data.writeByte(-1); } else {//w w w .jav a 2 s .co m data.writeByte(side.ordinal()); } data.writeFloat(this.hitX = hitX); data.writeFloat(this.hitY = hitY); data.writeFloat(this.hitZ = hitZ); data.writeByte(hand.ordinal()); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketMatterCannon.java
License:Open Source License
public PacketMatterCannon(final double x, final double y, final double z, final float dx, final float dy, final float dz, final byte len) { final float dl = dx * dx + dy * dy + dz * dz; final float dlz = (float) Math.sqrt(dl); this.x = x;/*from w ww. j a v a2 s .co m*/ this.y = y; this.z = z; this.dx = dx / dlz; this.dy = dy / dlz; this.dz = dz / dlz; this.len = len; final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeFloat((float) x); data.writeFloat((float) y); data.writeFloat((float) z); data.writeFloat((float) this.dx); data.writeFloat((float) this.dy); data.writeFloat((float) this.dz); data.writeByte(len); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketPaintedEntity.java
License:Open Source License
public PacketPaintedEntity(final int myEntity, final AEColor myColor, final int ticksLeft) { final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeInt(this.entityId = myEntity); data.writeByte((this.myColor = myColor).ordinal()); data.writeInt(ticksLeft);//from ww w.ja va 2 s . c o m this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketPartPlacement.java
License:Open Source License
public PacketPartPlacement(final BlockPos pos, final EnumFacing face, final float eyeHeight, final EnumHand hand) { final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeInt(pos.getX());/*w ww .jav a2 s . c o m*/ data.writeInt(pos.getY()); data.writeInt(pos.getZ()); data.writeByte(face.ordinal()); data.writeFloat(eyeHeight); data.writeByte(hand.ordinal()); this.configureWrite(data); }
From source file:appeng.core.sync.packets.PacketTransitionEffect.java
License:Open Source License
public PacketTransitionEffect(final double x, final double y, final double z, final AEPartLocation dir, final boolean wasBlock) { this.x = x;/* w w w. j a v a2 s. com*/ this.y = y; this.z = z; this.d = dir; this.mode = wasBlock; final ByteBuf data = Unpooled.buffer(); data.writeInt(this.getPacketID()); data.writeFloat((float) x); data.writeFloat((float) y); data.writeFloat((float) z); data.writeByte(this.d.ordinal()); data.writeBoolean(wasBlock); this.configureWrite(data); }
From source file:appeng.entity.EntityTinyTNTPrimed.java
License:Open Source License
@Override public void writeSpawnData(final ByteBuf data) { data.writeByte(this.getFuse()); }