Refine search
/** * Return a buffer from HTTP/2 codec that Vert.x can use: * * - if it's a direct buffer (coming likely from OpenSSL) : we get a heap buffer version * - if it's a composite buffer we do the same * - otherwise we increase the ref count */ static ByteBuf safeBuffer(ByteBuf buf, ByteBufAllocator allocator) { if (buf == Unpooled.EMPTY_BUFFER) { return buf; } if (buf.isDirect() || buf instanceof CompositeByteBuf) { if (buf.isReadable()) { ByteBuf buffer = allocator.heapBuffer(buf.readableBytes()); buffer.writeBytes(buf); return buffer; } else { return Unpooled.EMPTY_BUFFER; } } return buf.retain(); }
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { int length = msg.readableBytes() + lengthAdjustment; if (lengthIncludesLengthFieldLength) { length += lengthFieldLength; "length does not fit into a byte: " + length); out.add(ctx.alloc().buffer(1).order(byteOrder).writeByte((byte) length)); break; case 2: "length does not fit into a short integer: " + length); out.add(ctx.alloc().buffer(2).order(byteOrder).writeShort((short) length)); break; case 3: "length does not fit into a medium integer: " + length); out.add(ctx.alloc().buffer(3).order(byteOrder).writeMedium(length)); break; case 4: throw new Error("should not reach here"); out.add(msg.retain());
@Override protected void decode(ChannelHandlerContext chc, BinaryWebSocketFrame frame, List<Object> out) throws Exception { // convert the frame to a ByteBuf ByteBuf bb = frame.content(); // System.out.println("WebSocketFrameToByteBufDecoder decode - " + // ByteBufUtil.hexDump(bb)); bb.retain(); out.add(bb); } }
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.readableBytes() < 4) { return; } in.markReaderIndex(); int length = in.order(ByteOrder.LITTLE_ENDIAN).readInt(); if (in.readableBytes() < length) { in.resetReaderIndex(); return; } ByteBuf buf = ctx.alloc().buffer(length); in.readBytes(buf, length); out.add(buf.retain()); } }
private static ByteBuf encodeContent(StompContentSubframe content, ChannelHandlerContext ctx) { if (content instanceof LastStompContentSubframe) { ByteBuf buf = ctx.alloc().buffer(content.content().readableBytes() + 1); buf.writeBytes(content.content()); buf.writeByte(StompConstants.NUL); return buf; } else { return content.content().retain(); } }
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { int length = msg.readableBytes() + lengthAdjustment; if (lengthIncludesLengthFieldLength) { length += lengthFieldLength; "length does not fit into a byte: " + length); out.add(ctx.alloc().buffer(1).order(byteOrder).writeByte((byte) length)); break; case 2: "length does not fit into a short integer: " + length); out.add(ctx.alloc().buffer(2).order(byteOrder).writeShort((short) length)); break; case 3: "length does not fit into a medium integer: " + length); out.add(ctx.alloc().buffer(3).order(byteOrder).writeMedium(length)); break; case 4: throw new Error("should not reach here"); out.add(msg.retain());
public static OpAddEntry create(ManagedLedgerImpl ml, ByteBuf data, AddEntryCallback callback, Object ctx) { OpAddEntry op = RECYCLER.get(); op.ml = ml; op.ledger = null; op.data = data.retain(); op.dataLength = data.readableBytes(); op.callback = callback; op.ctx = ctx; op.closeWhenDone = false; op.entryId = -1; op.startTime = System.nanoTime(); op.completed = FALSE; ml.mbean.addAddEntrySample(op.dataLength); if (log.isDebugEnabled()) { log.debug("Created new OpAddEntry {}", op); } return op; }
@Override protected void decode(ChannelHandlerContext ctx, SctpMessage msg, List<Object> out) throws Exception { if (!msg.isComplete()) { throw new CodecException(String.format("Received SctpMessage is not complete, please add %s in the " + "pipeline before this handler", SctpMessageCompletionHandler.class.getSimpleName())); } out.add(msg.content().retain()); } }
private boolean decodeBulkStringContent(ByteBuf in, List<Object> out) throws Exception { final int readableBytes = in.readableBytes(); if (readableBytes == 0 || remainingBulkLength == 0 && readableBytes < RedisConstants.EOL_LENGTH) { return false; } // if this is last frame. if (readableBytes >= remainingBulkLength + RedisConstants.EOL_LENGTH) { ByteBuf content = in.readSlice(remainingBulkLength); readEndOfLine(in); // Only call retain after readEndOfLine(...) as the method may throw an exception. out.add(new DefaultLastBulkStringRedisContent(content.retain())); resetDecoder(); return true; } // chunked write. int toRead = Math.min(remainingBulkLength, readableBytes); remainingBulkLength -= toRead; out.add(new DefaultBulkStringRedisContent(in.readSlice(toRead).retain())); return true; }
@Override protected void doWrite(ChannelOutboundBuffer in) throws Exception { ByteBuf chunk; while (!stream.isNotWritable() && (chunk = (ByteBuf) in.current()) != null) { bytesWritten += chunk.readableBytes(); stream.writeData(chunk.retain(), false); stream.handlerContext.flush(); in.remove(); } }
@Override protected void decode(ChannelHandlerContext ctx, WebSocketFrame frame, List<Object> out) throws Exception { if (frame instanceof PingWebSocketFrame) { frame.content().retain(); ctx.channel().writeAndFlush(new PongWebSocketFrame(frame.content())); return; } if (frame instanceof PongWebSocketFrame && dropPongFrames) { return; } out.add(frame.retain()); }
int numChunks = (int) Math.ceil((double) msg.readableBytes() / chunkSize); int currentChunkLen = min(msg.readableBytes(), chunkSize); chunkBuf.retain(); cbb.addComponent(chunkBuf); cbbWriteIndex += currentChunkLen; msg.skipBytes(currentChunkLen); --numChunks; currentChunkLen = min(msg.readableBytes(), chunkSize); out.add(cbb);
final int readableBytes = buf.readableBytes(); if (readableBytes == 0) { ReferenceCountUtil.safeRelease(holder); buf.retain(); ReferenceCountUtil.safeRelease(holder);
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (in.getByte(in.readerIndex()) != UpdateOpcodes.ENCRYPTION) { ctx.fireChannelRead(in.retain()); return; } in.readByte(); byte xorKey = in.readByte(); in.readShort(); // always 0 EncryptionPacket encryptionPacket = new EncryptionPacket(); encryptionPacket.setKey(xorKey); out.add(encryptionPacket); } }
@Override protected void encode(ChannelHandlerContext ctx, ByteBuf msg, List<Object> out) throws Exception { int length = msg.readableBytes() + lengthAdjustment; if (lengthIncludesLengthFieldLength) { length += lengthFieldLength; "length does not fit into a byte: " + length); out.add(ctx.alloc().buffer(1).order(byteOrder).writeByte((byte) length)); break; case 2: "length does not fit into a short integer: " + length); out.add(ctx.alloc().buffer(2).order(byteOrder).writeShort((short) length)); break; case 3: "length does not fit into a medium integer: " + length); out.add(ctx.alloc().buffer(3).order(byteOrder).writeMedium(length)); break; case 4: throw new Error("should not reach here"); out.add(msg.retain());
@Override protected Object decode( ChannelHandlerContext ctx, Channel channel, ByteBuf buf) throws Exception { if (buf.readableBytes() < KEEP_ALIVE_LENGTH) { return null; } if (buf.getUnsignedByte(buf.readerIndex()) == 0xD0) { // Send response ByteBuf frame = buf.readRetainedSlice(KEEP_ALIVE_LENGTH); if (channel != null) { frame.retain(); channel.writeAndFlush(new NetworkMessage(frame, channel.remoteAddress())); } return frame; } else { int index = BufferUtil.indexOf("\r\n", buf); if (index != -1) { ByteBuf frame = buf.readRetainedSlice(index - buf.readerIndex()); buf.skipBytes(2); return frame; } } return null; }