Search in sources :

Example 1 with MessageFramer

use of io.grpc.internal.MessageFramer in project grpc-java by grpc.

the class NettyHandlerTestBase method grpcDataFrame.

protected ByteBuf grpcDataFrame(int streamId, boolean endStream, byte[] content) {
    final ByteBuf compressionFrame = Unpooled.buffer(content.length);
    MessageFramer framer = new MessageFramer(new MessageFramer.Sink() {

        @Override
        public void deliverFrame(WritableBuffer frame, boolean endOfStream, boolean flush) {
            if (frame != null) {
                ByteBuf bytebuf = ((NettyWritableBuffer) frame).bytebuf();
                compressionFrame.writeBytes(bytebuf);
            }
        }
    }, new NettyWritableBufferAllocator(ByteBufAllocator.DEFAULT), StatsTraceContext.NOOP);
    framer.writePayload(new ByteArrayInputStream(content));
    framer.flush();
    ChannelHandlerContext ctx = newMockContext();
    new DefaultHttp2FrameWriter().writeData(ctx, streamId, compressionFrame, 0, endStream, newPromise());
    return captureWrite(ctx);
}
Also used : MessageFramer(io.grpc.internal.MessageFramer) WritableBuffer(io.grpc.internal.WritableBuffer) ByteArrayInputStream(java.io.ByteArrayInputStream) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) CompositeByteBuf(io.netty.buffer.CompositeByteBuf) DefaultHttp2FrameWriter(io.netty.handler.codec.http2.DefaultHttp2FrameWriter)

Aggregations

MessageFramer (io.grpc.internal.MessageFramer)1 WritableBuffer (io.grpc.internal.WritableBuffer)1 ByteBuf (io.netty.buffer.ByteBuf)1 CompositeByteBuf (io.netty.buffer.CompositeByteBuf)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 DefaultHttp2FrameWriter (io.netty.handler.codec.http2.DefaultHttp2FrameWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1