@Override public void flush(ChannelHandlerContext ctx) throws Exception { if (cBuf.isReadable()) { byte[] b = new byte[cBuf.readableBytes()]; cBuf.readBytes(b); cBuf.discardReadComponents(); byte[] wrapped = saslClient.wrap(b, 0, b.length); ByteBuf buf = ctx.alloc().ioBuffer(4 + wrapped.length); buf.writeInt(wrapped.length); buf.writeBytes(wrapped); ctx.write(buf); } ctx.flush(); }
/** * Allocate a {@link ByteBuf} which will be used for constructing a datagram packet. * Sub-classes may override this method to return a {@link ByteBuf} with a perfect matching initial capacity. */ protected ByteBuf allocateBuffer( ChannelHandlerContext ctx, @SuppressWarnings("unused") AddressedEnvelope<DnsResponse, InetSocketAddress> msg) throws Exception { return ctx.alloc().ioBuffer(1024); }
@Override public ByteBuf allocate(ByteBufAllocator alloc) { return alloc.ioBuffer(guess()); }
@Override public ByteBuf allocate(ByteBufAllocator alloc) { return alloc.ioBuffer(guess()); }
/** * Allocate a {@link ByteBuf} which will be used for constructing a datagram packet. * Sub-classes may override this method to return a {@link ByteBuf} with a perfect matching initial capacity. */ protected ByteBuf allocateBuffer( ChannelHandlerContext ctx, @SuppressWarnings("unused") AddressedEnvelope<DnsQuery, InetSocketAddress> msg) throws Exception { return ctx.alloc().ioBuffer(1024); }
private static void writeBulkStringContent(ByteBufAllocator allocator, BulkStringRedisContent msg, List<Object> out) { out.add(msg.content().retain()); if (msg instanceof LastBulkStringRedisContent) { out.add(allocator.ioBuffer(RedisConstants.EOL_LENGTH).writeShort(RedisConstants.EOL_SHORT)); } }
@Override public ByteBuf allocate(ByteBufAllocator alloc) { return overrideGuess ? alloc.ioBuffer(guess0()) : delegate.allocate(alloc); }
public ByteBuf encodePingFrame(ByteBufAllocator allocator, int id) { byte flags = 0; int length = 4; ByteBuf frame = allocator.ioBuffer(SPDY_HEADER_SIZE + length).order(ByteOrder.BIG_ENDIAN); writeControlFrameHeader(frame, SPDY_PING_FRAME, flags, length); frame.writeInt(id); return frame; }
@Override protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, ByteBuf in, boolean preferDirect) throws Exception { final int length = in.readableBytes(); final int maxOutputLength = maxOutputBufferLength(length); return ctx.alloc().ioBuffer(maxOutputLength); }
/** * Allocate a {@link ByteBuf} which will be used as argument of {@link #encode(ChannelHandlerContext, I, ByteBuf)}. * Sub-classes may override this method to return {@link ByteBuf} with a perfect matching {@code initialCapacity}. */ protected ByteBuf allocateBuffer(ChannelHandlerContext ctx, @SuppressWarnings("unused") I msg, boolean preferDirect) throws Exception { if (preferDirect) { return ctx.alloc().ioBuffer(); } else { return ctx.alloc().heapBuffer(); } }
private static void writeString(ByteBufAllocator allocator, byte type, String content, List<Object> out) { ByteBuf buf = allocator.ioBuffer(RedisConstants.TYPE_LENGTH + ByteBufUtil.utf8MaxBytes(content) + RedisConstants.EOL_LENGTH); buf.writeByte(type); ByteBufUtil.writeUtf8(buf, content); buf.writeShort(RedisConstants.EOL_SHORT); out.add(buf); }
public ByteBuf encodeRstStreamFrame(ByteBufAllocator allocator, int streamId, int statusCode) { byte flags = 0; int length = 8; ByteBuf frame = allocator.ioBuffer(SPDY_HEADER_SIZE + length).order(ByteOrder.BIG_ENDIAN); writeControlFrameHeader(frame, SPDY_RST_STREAM_FRAME, flags, length); frame.writeInt(streamId); frame.writeInt(statusCode); return frame; }
public ByteBuf encodeGoAwayFrame(ByteBufAllocator allocator, int lastGoodStreamId, int statusCode) { byte flags = 0; int length = 8; ByteBuf frame = allocator.ioBuffer(SPDY_HEADER_SIZE + length).order(ByteOrder.BIG_ENDIAN); writeControlFrameHeader(frame, SPDY_GOAWAY_FRAME, flags, length); frame.writeInt(lastGoodStreamId); frame.writeInt(statusCode); return frame; }
public ByteBuf encodeWindowUpdateFrame(ByteBufAllocator allocator, int streamId, int deltaWindowSize) { byte flags = 0; int length = 8; ByteBuf frame = allocator.ioBuffer(SPDY_HEADER_SIZE + length).order(ByteOrder.BIG_ENDIAN); writeControlFrameHeader(frame, SPDY_WINDOW_UPDATE_FRAME, flags, length); frame.writeInt(streamId); frame.writeInt(deltaWindowSize); return frame; } }
private void writeIntegerMessage(ByteBufAllocator allocator, IntegerRedisMessage msg, List<Object> out) { ByteBuf buf = allocator.ioBuffer(RedisConstants.TYPE_LENGTH + RedisConstants.LONG_MAX_LENGTH + RedisConstants.EOL_LENGTH); buf.writeByte(RedisMessageType.INTEGER.value()); buf.writeBytes(numberToBytes(msg.value())); buf.writeShort(RedisConstants.EOL_SHORT); out.add(buf); }
public ByteBuf encodeSynReplyFrame(ByteBufAllocator allocator, int streamId, boolean last, ByteBuf headerBlock) { int headerBlockLength = headerBlock.readableBytes(); byte flags = last ? SPDY_FLAG_FIN : 0; int length = 4 + headerBlockLength; ByteBuf frame = allocator.ioBuffer(SPDY_HEADER_SIZE + length).order(ByteOrder.BIG_ENDIAN); writeControlFrameHeader(frame, SPDY_SYN_REPLY_FRAME, flags, length); frame.writeInt(streamId); frame.writeBytes(headerBlock, headerBlock.readerIndex(), headerBlockLength); return frame; }
public ByteBuf encodeHeadersFrame(ByteBufAllocator allocator, int streamId, boolean last, ByteBuf headerBlock) { int headerBlockLength = headerBlock.readableBytes(); byte flags = last ? SPDY_FLAG_FIN : 0; int length = 4 + headerBlockLength; ByteBuf frame = allocator.ioBuffer(SPDY_HEADER_SIZE + length).order(ByteOrder.BIG_ENDIAN); writeControlFrameHeader(frame, SPDY_HEADERS_FRAME, flags, length); frame.writeInt(streamId); frame.writeBytes(headerBlock, headerBlock.readerIndex(), headerBlockLength); return frame; }
private void writeBulkStringHeader(ByteBufAllocator allocator, BulkStringHeaderRedisMessage msg, List<Object> out) { final ByteBuf buf = allocator.ioBuffer(RedisConstants.TYPE_LENGTH + (msg.isNull() ? RedisConstants.NULL_LENGTH : RedisConstants.LONG_MAX_LENGTH + RedisConstants.EOL_LENGTH)); buf.writeByte(RedisMessageType.BULK_STRING.value()); if (msg.isNull()) { buf.writeShort(RedisConstants.NULL_SHORT); } else { buf.writeBytes(numberToBytes(msg.bulkStringLength())); buf.writeShort(RedisConstants.EOL_SHORT); } out.add(buf); }
public ByteBuf encodeDataFrame(ByteBufAllocator allocator, int streamId, boolean last, ByteBuf data) { byte flags = last ? SPDY_DATA_FLAG_FIN : 0; int length = data.readableBytes(); ByteBuf frame = allocator.ioBuffer(SPDY_HEADER_SIZE + length).order(ByteOrder.BIG_ENDIAN); frame.writeInt(streamId & 0x7FFFFFFF); frame.writeByte(flags); frame.writeMedium(length); frame.writeBytes(data, data.readerIndex(), length); return frame; }
public ByteBuf encodeSynStreamFrame(ByteBufAllocator allocator, int streamId, int associatedToStreamId, byte priority, boolean last, boolean unidirectional, ByteBuf headerBlock) { int headerBlockLength = headerBlock.readableBytes(); byte flags = last ? SPDY_FLAG_FIN : 0; if (unidirectional) { flags |= SPDY_FLAG_UNIDIRECTIONAL; } int length = 10 + headerBlockLength; ByteBuf frame = allocator.ioBuffer(SPDY_HEADER_SIZE + length).order(ByteOrder.BIG_ENDIAN); writeControlFrameHeader(frame, SPDY_SYN_STREAM_FRAME, flags, length); frame.writeInt(streamId); frame.writeInt(associatedToStreamId); frame.writeShort((priority & 0xFF) << 13); frame.writeBytes(headerBlock, headerBlock.readerIndex(), headerBlockLength); return frame; }