List of usage examples for io.netty.buffer ByteBuf writeInt
public abstract ByteBuf writeInt(int value);
From source file:com.kaijin.AdvPowerMan.tileentities.TEStorageMonitor.java
License:Open Source License
@Override protected void addUniqueDescriptionData(ByteBuf data) throws IOException { data.writeInt(chargeLevel); data.writeBoolean(isPowering);/*from w w w . j a v a2 s . c om*/ data.writeBoolean(blockState); }
From source file:com.kegare.caveworld.network.BuffMessage.java
License:Minecraft Mod Public
@Override public void toBytes(ByteBuf buffer) { buffer.writeInt(effect.getPotionID()); buffer.writeInt(effect.getDuration()); buffer.writeInt(effect.getAmplifier()); }
From source file:com.kegare.caveworld.network.CaveAchievementMessage.java
License:Minecraft Mod Public
@Override public void toBytes(ByteBuf buffer) { buffer.writeInt(index); }
From source file:com.kegare.caveworld.network.DimSyncMessage.java
License:Minecraft Mod Public
@Override public void toBytes(ByteBuf buffer) { buffer.writeInt(dimensionId); ByteBufUtils.writeTag(buffer, data); }
From source file:com.kegare.frozenland.core.Config.java
License:Minecraft Mod Public
@Override public void toBytes(ByteBuf buf) { buf.writeInt(dimensionFrozenland); buf.writeInt(biomeFrozenland);/* www. j a v a 2s .c om*/ buf.writeBoolean(generateCaves); buf.writeBoolean(generateRavine); buf.writeBoolean(generateMineshaft); buf.writeBoolean(generateVillage); buf.writeBoolean(generateDungeons); }
From source file:com.kixeye.kixmpp.p2p.serialization.ProtostuffEncoder.java
License:Apache License
/** * Expose serializer for sharing serialization and unit testing. * * @param registry//from w w w . j a v a 2 s. com * @param buf * @return * @throws IOException */ @SuppressWarnings({ "rawtypes", "unchecked" }) public static ByteBuf serializeToByteBuf(MessageRegistry registry, ByteBuf buf, Object msg) throws IOException { // write class id int classIdx = registry.getIdFromClass(msg.getClass()); buf.writeInt(classIdx); // write serialized object Schema schema = RuntimeSchema.getSchema(msg.getClass()); LinkedBuffer linkedBuffer = LinkedBuffer.allocate(1024); ProtostuffIOUtil.writeTo(new ByteBufOutputStream(buf), msg, schema, linkedBuffer); return buf; }
From source file:com.ldp.nettydemo.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;// w w w. j a va 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(); sendBuf.writeBytes(ByteObjConverter.ObjectToByte(value)); // marshallingEncoder.encode(value, sendBuf); } key = null; keyArray = null; value = null; if (msg.getBody() != null) { sendBuf.writeBytes(ByteObjConverter.ObjectToByte(msg.getBody())); // marshallingEncoder.encode(msg.getBody(), sendBuf); } else sendBuf.writeInt(0); sendBuf.setInt(4, sendBuf.readableBytes() - 8); }
From source file:com.linecorp.armeria.internal.grpc.ArmeriaMessageFramer.java
License:Apache License
private ByteBuf write(ByteBuf message, boolean compressed) { try {/*from w w w . j av a 2 s.c o m*/ final int messageLength = message.readableBytes(); if (maxOutboundMessageSize >= 0 && messageLength > maxOutboundMessageSize) { throw Status.RESOURCE_EXHAUSTED .withDescription( String.format("message too large %d > %d", messageLength, maxOutboundMessageSize)) .asRuntimeException(); } final ByteBuf buf = alloc.buffer(HEADER_LENGTH + messageLength); buf.writeByte(compressed ? COMPRESSED : UNCOMPRESSED); buf.writeInt(messageLength); buf.writeBytes(message); return buf; } finally { message.release(); } }
From source file:com.linecorp.armeria.internal.grpc.GrpcTestUtil.java
License:Apache License
public static byte[] uncompressedFrame(ByteBuf proto) { ByteBuf buf = Unpooled.buffer(); buf.writeByte(0);/*from ww w .j ava 2 s .c om*/ buf.writeInt(proto.readableBytes()); buf.writeBytes(proto); proto.release(); byte[] result = ByteBufUtil.getBytes(buf); buf.release(); return result; }
From source file:com.linecorp.armeria.internal.grpc.GrpcTestUtil.java
License:Apache License
public static byte[] compressedFrame(ByteBuf uncompressed) { ByteBuf compressed = Unpooled.buffer(); try (ByteBufInputStream is = new ByteBufInputStream(uncompressed, true); GZIPOutputStream os = new GZIPOutputStream(new ByteBufOutputStream(compressed))) { ByteStreams.copy(is, os);//from w ww . ja va 2s . co m } catch (IOException e) { throw new UncheckedIOException(e); } ByteBuf buf = Unpooled.buffer(); buf.writeByte(1); buf.writeInt(compressed.readableBytes()); buf.writeBytes(compressed); compressed.release(); byte[] result = ByteBufUtil.getBytes(buf); buf.release(); return result; }