List of usage examples for io.netty.buffer ByteBuf writeInt
public abstract ByteBuf writeInt(int value);
From source file:com.bluepowermod.network.message.MessageSendClientServerTemplates.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { buf.writeInt(stacks.size()); for (ItemStack stack : stacks) ByteBufUtils.writeItemStack(buf, stack); }
From source file:com.bluepowermod.network.message.MessageUpdateTextfield.java
License:Open Source License
@Override public void toBytes(ByteBuf buffer) { super.toBytes(buffer); buffer.writeInt(textFieldID); ByteBufUtils.writeUTF8String(buffer, text); }
From source file:com.book.netty5.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 a va2s . 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:com.bosscs.spark.commons.extractor.client.codecs.ActionEncoder.java
License:Apache License
protected void encode(ChannelHandlerContext ctx, Action action, ByteBuf out) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput outObj = null;/*w ww. ja v a 2 s .c o m*/ try { outObj = new ObjectOutputStream(bos); outObj.writeObject(action); } catch (IOException e) { LOG.error(e.getMessage()); } finally { try { if (outObj != null) { outObj.close(); } } catch (IOException ex) { // ignore close exception } try { bos.close(); } catch (IOException ex) { // ignore close exception } } byte[] encodedObj = bos.toByteArray(); int dataLength = encodedObj.length; out.writeInt(dataLength); out.writeBytes(encodedObj); }
From source file:com.bosscs.spark.commons.extractor.client.codecs.ResponseEncoder.java
License:Apache License
protected void encode(ChannelHandlerContext ctx, Response response, ByteBuf out) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput outObj = null;// w ww.j ava 2 s . c o m try { outObj = new ObjectOutputStream(bos); outObj.writeObject(response); } catch (IOException e) { LOG.error(e.getMessage()); } finally { try { if (outObj != null) { outObj.close(); } } catch (IOException ex) { // ignore close exception } try { bos.close(); } catch (IOException ex) { // ignore close exception } } byte[] encodedObj = bos.toByteArray(); int dataLength = encodedObj.length; out.writeInt(dataLength); out.writeBytes(encodedObj); }
From source file:com.builtbroken.assemblyline.content.belt.TilePipeBelt.java
@Override public void writeDescPacket(ByteBuf buf) { super.writeDescPacket(buf); buf.writeInt(type.ordinal()); buf.writeBoolean(shouldUpdateRender); buf.writeBoolean(shouldEjectItems);/* ww w . ja va2 s .c o m*/ buf.writeBoolean(pullItems); buf.writeBoolean(renderTop); writeInvPacket(buf); buf.writeBoolean(beltSideData != null); if (beltSideData != null) { NBTTagCompound tag = new NBTTagCompound(); tag.setTag("beltStates", saveBeltState()); ByteBufUtils.writeTag(buf, tag); } }
From source file:com.builtbroken.assemblyline.content.belt.TilePipeBelt.java
public void writeInvPacket(ByteBuf buf) { buf.writeInt(getInventory().getSizeInventory()); ByteBufUtils.writeTag(buf, getInventory().save(new NBTTagCompound())); }
From source file:com.builtbroken.assemblyline.content.rail.carts.EntityCart.java
@Override public void writeSpawnData(ByteBuf buffer) { buffer.writeInt(getType().ordinal()); }
From source file:com.builtbroken.assemblyline.content.rail.powered.TilePowerRail.java
@Override public void writeDescPacket(ByteBuf buf) { buf.writeInt(railType.ordinal()); buf.writeInt(getFacingDirection().ordinal()); if (isRotationRail()) { buf.writeBoolean(rotateToAngle); buf.writeBoolean(rotateClockwise); buf.writeInt(rotateYaw);//w ww.ja v a2 s . co m } else if (isStopRail()) { buf.writeBoolean(stopCarts); } else if (isLoaderRail() || isUnloadRail()) { buf.writeBoolean(rotateClockwise); } }
From source file:com.builtbroken.atomic.network.packet.client.PacketSpawnParticle.java
@Override public void encodeInto(ChannelHandlerContext ctx, ByteBuf buffer) { buffer.writeInt(dim); buffer.writeDouble(x);//from www . ja v a2 s .c om buffer.writeDouble(y); buffer.writeDouble(z); ByteBufUtils.writeUTF8String(buffer, particle); }