List of usage examples for io.netty.buffer ByteBuf writeInt
public abstract ByteBuf writeInt(int value);
From source file:books.netty.protocol.netty.codec.NettyMessageEncoder.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, NettyMessage msg, ByteBuf sendBuf) throws Exception { if (msg == null || msg.getHeader() == null) throw new Exception("The encode message is null"); sendBuf.writeInt((msg.getHeader().getCrcCode())); sendBuf.writeInt((msg.getHeader().getLength())); sendBuf.writeLong((msg.getHeader().getSessionID())); sendBuf.writeByte((msg.getHeader().getType())); sendBuf.writeByte((msg.getHeader().getPriority())); sendBuf.writeInt((msg.getHeader().getAttachment().size())); String key = null;//from w w w . j av a 2s. c o m byte[] keyArray = null; Object value = null; for (Map.Entry<String, Object> param : msg.getHeader().getAttachment().entrySet()) { key = param.getKey(); keyArray = key.getBytes("UTF-8"); sendBuf.writeInt(keyArray.length); sendBuf.writeBytes(keyArray); value = param.getValue(); marshallingEncoder.encode(value, sendBuf); } key = null; keyArray = null; value = null; if (msg.getBody() != null) { marshallingEncoder.encode(msg.getBody(), sendBuf); } else sendBuf.writeInt(0); sendBuf.setInt(4, sendBuf.readableBytes() - 8); }
From source file:books.netty.protocol.netty.codec.TestCodeC.java
License:Apache License
public ByteBuf encode(NettyMessage msg) throws Exception { ByteBuf sendBuf = Unpooled.buffer(); sendBuf.writeInt((msg.getHeader().getCrcCode())); sendBuf.writeInt((msg.getHeader().getLength())); sendBuf.writeLong((msg.getHeader().getSessionID())); sendBuf.writeByte((msg.getHeader().getType())); sendBuf.writeByte((msg.getHeader().getPriority())); sendBuf.writeInt((msg.getHeader().getAttachment().size())); String key = null;/*ww w. j a v a 2s. c om*/ byte[] keyArray = null; Object value = null; for (Map.Entry<String, Object> param : msg.getHeader().getAttachment().entrySet()) { key = param.getKey(); keyArray = key.getBytes("UTF-8"); sendBuf.writeInt(keyArray.length); sendBuf.writeBytes(keyArray); value = param.getValue(); marshallingEncoder.encode(value, sendBuf); } key = null; keyArray = null; value = null; if (msg.getBody() != null) { marshallingEncoder.encode(msg.getBody(), sendBuf); } else sendBuf.writeInt(0); sendBuf.setInt(4, sendBuf.readableBytes()); return sendBuf; }
From source file:buildcraft.builders.network.PacketLibraryAction.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf data) { data.writeInt(actionId); super.writeData(data); }
From source file:buildcraft.builders.TileQuarry.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf stream) { super.writeData(stream); box.writeData(stream);/* www .j a v a 2 s.c om*/ stream.writeInt(targetX); stream.writeShort(targetY); stream.writeInt(targetZ); stream.writeDouble(headPosX); stream.writeDouble(headPosY); stream.writeDouble(headPosZ); stream.writeFloat((float) speed); stream.writeFloat(headTrajectory); int flags = stage.ordinal(); flags |= movingHorizontally ? 0x10 : 0; flags |= movingVertically ? 0x20 : 0; stream.writeByte(flags); ledState = (hasWork() && mode != Mode.Off && getTicksSinceEnergyReceived() < 12 ? 16 : 0) | (getBattery().getEnergyStored() * 15 / getBattery().getMaxEnergyStored()); stream.writeByte(ledState); }
From source file:buildcraft.builders.urbanism.AnchoredBox.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf stream) { box.writeData(stream); stream.writeInt(x1); stream.writeShort(y1); stream.writeInt(z1); }
From source file:buildcraft.builders.urbanism.TileUrbanist.java
License:Minecraft Mod Public
private BuildCraftPacket createXYZPacket(String name, final int x, final int y, final int z) { return new PacketCommand(this, name, new CommandWriter() { public void write(ByteBuf data) { data.writeInt(x); data.writeShort(y);//w w w.j a va 2s . co m data.writeInt(z); } }); }
From source file:buildcraft.commander.GuiZonePlan.java
License:Minecraft Mod Public
private void uploadMap() { BuildCraftCore.instance.sendToServer(new PacketCommand(getContainer(), "computeMap", new CommandWriter() { public void write(ByteBuf data) { data.writeInt(cx); data.writeInt(cz);//from w w w. ja v a 2s. c o m data.writeShort(getContainer().mapTexture.width); data.writeShort(getContainer().mapTexture.height); data.writeByte(zoomLevel); } })); }
From source file:buildcraft.core.Box.java
License:Minecraft Mod Public
public void writeToStream(ByteBuf stream) { stream.writeBoolean(initialized);//from www .ja va 2s . c om stream.writeInt(xMin); stream.writeInt(yMin); stream.writeInt(zMin); stream.writeInt(xMax); stream.writeInt(yMax); stream.writeInt(zMax); }
From source file:buildcraft.core.ChunkIndex.java
License:Minecraft Mod Public
@Override public void writeData(ByteBuf stream) { stream.writeInt(x); stream.writeInt(z); }
From source file:buildcraft.core.EntityRobot.java
License:Minecraft Mod Public
@Override public void writeSpawnData(ByteBuf data) { if (box == null) { box = new Box(); }//from w w w. j ava2s . c o m data.writeInt(box.xMin); data.writeInt(box.yMin); data.writeInt(box.zMin); data.writeInt(box.xMax); data.writeInt(box.yMax); data.writeInt(box.zMax); }