List of usage examples for io.netty.buffer ByteBuf writeInt
public abstract ByteBuf writeInt(int value);
From source file:com.addthis.meshy.ChannelState.java
License:Apache License
public ByteBuf allocateSendBuffer(int type, int session, int length) { ByteBuf sendBuffer = channel.alloc().buffer(MESHY_BYTE_OVERHEAD + length); sendBuffer.writeInt(type); sendBuffer.writeInt(session);//from w ww . ja v a2s . c o m sendBuffer.writeInt(length); return sendBuffer; }
From source file:com.addthis.meshy.ChannelState.java
License:Apache License
public ByteBuf allocateSendBuffer(int type, int session, ByteBuf from, int length) { ByteBuf sendBuffer = channel.alloc().buffer(MESHY_BYTE_OVERHEAD + length); sendBuffer.writeInt(type); sendBuffer.writeInt(session);/*from ww w . j av a 2s . c om*/ sendBuffer.writeInt(length); sendBuffer.writeBytes(from, length); return sendBuffer; }
From source file:com.addthis.meshy.SourceHandler.java
License:Apache License
private static ByteBuf allocateSendBuffer(ByteBufAllocator alloc, int type, int session, byte[] data) { ByteBuf sendBuffer = alloc.buffer(MESHY_BYTE_OVERHEAD + data.length); sendBuffer.writeInt(type); sendBuffer.writeInt(session);/*from w w w . j a v a2s .co m*/ sendBuffer.writeInt(data.length); sendBuffer.writeBytes(data); return sendBuffer; }
From source file:com.addthis.muxy.MuxStreamDirectory.java
License:Apache License
protected long writeStreamsToBlock() throws IOException { long writtenBytes = 0; openWritesLock.lock();/*w ww. jav a 2 s . c om*/ try { /* yes, this could be optimized for concurrency by writing after lock is released, etc */ if (openWriteBytes.get() == 0) { return 0; } List<TempData> streamsWithData = new ArrayList<>(openStreamWrites.size()); for (StreamOut out : openStreamWrites.values()) { synchronized (out) { StreamOut pendingOut = pendingStreamCloses.get(out.meta.streamId); if (pendingOut != null) { pendingOut.outputBuffer.writeBytes(out.outputBuffer); assert out.outputBuffer.readableBytes() == 0; out.outputBuffer.discardSomeReadBytes(); } else if (out.output.buffer().readableBytes() > 0) { streamsWithData.add(new TempData(out)); out.outputBuffer.retain(); } } } for (StreamOut out : pendingStreamCloses.values()) { // guarded by openStreamWrites streamsWithData.add(new TempData(out)); } pendingStreamCloses.clear(); if (streamsWithData.isEmpty()) { return 0; } for (TempData td : streamsWithData) { writtenBytes += td.snapshotLength; } int streams = streamsWithData.size(); publishEvent(MuxyStreamEvent.BLOCK_FILE_WRITE, streams); int currentFileOffset = (int) openWriteFile.size(); /* write out IDs in this block */ ByteBuf metaBuffer = PooledByteBufAllocator.DEFAULT.directBuffer(2 + 4 * streams + 4 + 8 * streams); metaBuffer.writeShort(streams); int bodyOutputSize = 0; for (TempData out : streamsWithData) { metaBuffer.writeInt(out.meta.streamId); /* (4) chunk body offset (4) chunk length (n) chunk bytes */ bodyOutputSize += 8 + out.snapshotLength; } /* write remainder size for rest of block data so that readers can skip if desired ID isn't present */ metaBuffer.writeInt(bodyOutputSize); /* write offsets and lengths for each stream id */ int bodyOffset = streamsWithData.size() * 8; for (TempData out : streamsWithData) { metaBuffer.writeInt(bodyOffset); //TODO - reconsider how frequently this shortcut is placed on disk metaBuffer.writeInt(out.snapshotLength); bodyOffset += out.snapshotLength; } while (metaBuffer.readableBytes() > 0) { metaBuffer.readBytes(openWriteFile, metaBuffer.readableBytes()); } metaBuffer.release(); /* write bytes for each stream id */ for (TempData out : streamsWithData) { synchronized (out.stream) { // need less confusing variable names for concurrency int toWrite = out.snapshotLength; while (toWrite > 0) { int numBytesRead = out.data.readBytes(openWriteFile, toWrite); assert numBytesRead > 0; toWrite -= numBytesRead; } openWriteBytes.addAndGet((long) -out.snapshotLength); eventListener.reportWrite((long) -out.snapshotLength); out.meta.endFile = streamDirectoryConfig.currentFile.get(); out.meta.endFileBlockOffset = currentFileOffset; if (out.meta.startFile == 0) { out.meta.startFile = out.meta.endFile; out.meta.startFileBlockOffset = out.meta.endFileBlockOffset; } if (!out.data.release()) { // release the pending writes that did not get an extra retain out.data.discardSomeReadBytes(); } } } /* check for rolling current file on size threshold */ if (openWriteFile.size() > streamDirectoryConfig.maxFileSize) { openWriteFile.close(); openWriteFile = FileChannel.open(getFileByID(bumpCurrentFile()), APPEND, CREATE); publishEvent(MuxyStreamEvent.BLOCK_FILE_WRITE_ROLL, streamDirectoryConfig.currentFile); } } finally { openWritesLock.unlock(); } return writtenBytes; }
From source file:com.almuradev.guide.client.network.play.C00PageInformation.java
License:MIT License
@Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, identifier); buf.writeInt(index); ByteBufUtils.writeUTF8String(buf, title); ByteBufUtils.writeUTF8String(buf, contents); }
From source file:com.almuradev.guide.server.network.play.S00PageInformation.java
License:MIT License
@Override public void toBytes(ByteBuf buf) { ByteBufUtils.writeUTF8String(buf, identifier); buf.writeInt(index); ByteBufUtils.writeUTF8String(buf, title); buf.writeLong(created.getTime());//from w w w. j a v a2s.c om ByteBufUtils.writeUTF8String(buf, author); buf.writeLong(lastModified.getTime()); ByteBufUtils.writeUTF8String(buf, lastContributor); ByteBufUtils.writeUTF8String(buf, contents); }
From source file:com.basho.riak.client.core.netty.RiakMessageCodec.java
License:Apache License
@Override protected void encode(ChannelHandlerContext ctx, RiakMessage msg, ByteBuf out) throws Exception { int length = msg.getData().length + 1; out.writeInt(length); out.writeByte(msg.getCode());//from w ww. j a va 2 s . c o m out.writeBytes(msg.getData()); }
From source file:com.blogspot.jabelarminecraft.blocksmith.proxy.CommonProxy.java
License:Open Source License
public void convertItemStackListToPayload(ByteBuf parBuffer) { Iterator theIterator = itemStackRegistry.iterator(); while (theIterator.hasNext()) { ItemStack theStack = (ItemStack) theIterator.next(); // write item id and metadata parBuffer.writeInt(Item.getIdFromItem(theStack.getItem())); parBuffer.writeInt(theStack.getMetadata()); // // DEBUG // System.out.println(Item.getIdFromItem(theStack.getItem())+" "+theStack.getMetadata()); boolean hasNBT = theStack.hasTagCompound(); parBuffer.writeBoolean(hasNBT);/* w w w. j a v a2 s . c o m*/ if (hasNBT) { // DEBUG System.out.println( "The stack " + theStack.toString() + " has NBT = " + theStack.getTagCompound().toString()); ByteBufUtils.writeTag(parBuffer, theStack.getTagCompound()); } theIterator.remove(); // avoids a ConcurrentModificationException } return; }
From source file:com.bluepowermod.network.message.LocationIntPacket.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { buf.writeInt(x); buf.writeInt(y); buf.writeInt(z); }
From source file:com.bluepowermod.network.message.MessageGuiUpdate.java
License:Open Source License
@Override public void toBytes(ByteBuf buf) { super.toBytes(buf); buf.writeInt(messageId); buf.writeInt(partId);//from w ww. j ava 2 s . c om buf.writeInt(value); buf.writeInt(icId); }