public static ByteBuf safeBuffer(ByteBufHolder holder, ByteBufAllocator allocator) { return safeBuffer(holder.content(), allocator); }
@Override public void handle(Object event) { if (event instanceof ByteBuf) { ByteBuf byteBuf = (ByteBuf) event; byteBuf = VertxHandler.safeBuffer(byteBuf, allocator); Buffer data = Buffer.buffer(byteBuf); reportBytesRead(data.length()); dataHandler.handle(data); } } }
WebSocketFrameInternal decodeFrame(WebSocketFrame msg) { ByteBuf payload = safeBuffer(msg, chctx.alloc()); boolean isFinal = msg.isFinalFragment(); FrameType frameType; if (msg instanceof BinaryWebSocketFrame) { frameType = FrameType.BINARY; } else if (msg instanceof CloseWebSocketFrame) { frameType = FrameType.CLOSE; } else if (msg instanceof PingWebSocketFrame) { frameType = FrameType.PING; } else if (msg instanceof PongWebSocketFrame) { frameType = FrameType.PONG; } else if (msg instanceof TextWebSocketFrame) { frameType = FrameType.TEXT; } else if (msg instanceof ContinuationWebSocketFrame) { frameType = FrameType.CONTINUATION; } else { throw new IllegalStateException("Unsupported websocket msg " + msg); } return new WebSocketFrameImpl(frameType, payload, isFinal); }
private void handleHttpMessage(HttpObject obj) { if (obj instanceof HttpResponse) { handleResponseBegin((HttpResponse) obj); } else if (obj instanceof HttpContent) { HttpContent chunk = (HttpContent) obj; if (chunk.content().isReadable()) { Buffer buff = Buffer.buffer(VertxHandler.safeBuffer(chunk.content(), chctx.alloc())); handleResponseChunk(buff); } if (chunk instanceof LastHttpContent) { handleResponseEnd((LastHttpContent) chunk); } } }
public void handleMessage(Object msg) { if (msg instanceof DatagramPacket) { DatagramPacket packet = (DatagramPacket) msg; ByteBuf content = packet.content(); if (content.isDirect()) { content = VertxHandler.safeBuffer(content, chctx.alloc()); } handlePacket(new DatagramPacketImpl(packet.sender(), Buffer.buffer(content))); } }
private void handleContent(Object msg) { HttpContent content = (HttpContent) msg; if (content.decoderResult() != DecoderResult.SUCCESS) { handleError(content); return; } Buffer buffer = Buffer.buffer(VertxHandler.safeBuffer(content.content(), chctx.alloc())); if (METRICS_ENABLED) { reportBytesRead(buffer); } requestInProgress.handleContent(buffer); //TODO chunk trailers if (content instanceof LastHttpContent) { handleEnd(); } }
if (msg instanceof HttpContent) { HttpContent content = (HttpContent) msg; ByteBuf buf = VertxHandler.safeBuffer(content.content(), ctx.alloc()); boolean end = msg instanceof LastHttpContent; ctx.fireChannelRead(new DefaultHttp2DataFrame(buf, end, 0));
WebSocketFrame encodeFrame(WebSocketFrameImpl frame) { ByteBuf buf = frame.getBinaryData(); if (buf != Unpooled.EMPTY_BUFFER) { buf = safeBuffer(buf, chctx.alloc()); } switch (frame.type()) { case BINARY: return new BinaryWebSocketFrame(frame.isFinal(), 0, buf); case TEXT: return new TextWebSocketFrame(frame.isFinal(), 0, buf); case CLOSE: return new CloseWebSocketFrame(true, 0, buf); case CONTINUATION: return new ContinuationWebSocketFrame(frame.isFinal(), 0, buf); case PONG: return new PongWebSocketFrame(buf); case PING: return new PingWebSocketFrame(buf); default: throw new IllegalStateException("Unsupported websocket msg " + frame); } }
public static ByteBuf safeBuffer(ByteBufHolder holder, ByteBufAllocator allocator) { return safeBuffer(holder.content(), allocator); }
@Override public void handle(Object event) { if (event instanceof ByteBuf) { ByteBuf byteBuf = (ByteBuf) event; byteBuf = VertxHandler.safeBuffer(byteBuf, allocator); Buffer data = Buffer.buffer(byteBuf); reportBytesRead(data.length()); dataHandler.handle(data); } } }
WebSocketFrameInternal decodeFrame(WebSocketFrame msg) { ByteBuf payload = safeBuffer(msg, chctx.alloc()); boolean isFinal = msg.isFinalFragment(); FrameType frameType; if (msg instanceof BinaryWebSocketFrame) { frameType = FrameType.BINARY; } else if (msg instanceof CloseWebSocketFrame) { frameType = FrameType.CLOSE; } else if (msg instanceof PingWebSocketFrame) { frameType = FrameType.PING; } else if (msg instanceof PongWebSocketFrame) { frameType = FrameType.PONG; } else if (msg instanceof TextWebSocketFrame) { frameType = FrameType.TEXT; } else if (msg instanceof ContinuationWebSocketFrame) { frameType = FrameType.CONTINUATION; } else { throw new IllegalStateException("Unsupported websocket msg " + msg); } return new WebSocketFrameImpl(frameType, payload, isFinal); }
private void handleHttpMessage(HttpObject obj) { if (obj instanceof HttpResponse) { handleResponseBegin((HttpResponse) obj); } else if (obj instanceof HttpContent) { HttpContent chunk = (HttpContent) obj; if (chunk.content().isReadable()) { Buffer buff = Buffer.buffer(VertxHandler.safeBuffer(chunk.content(), chctx.alloc())); handleResponseChunk(buff); } if (chunk instanceof LastHttpContent) { handleResponseEnd((LastHttpContent) chunk); } } }
public void handleMessage(Object msg) { if (msg instanceof DatagramPacket) { DatagramPacket packet = (DatagramPacket) msg; ByteBuf content = packet.content(); if (content.isDirect()) { content = VertxHandler.safeBuffer(content, chctx.alloc()); } handlePacket(new DatagramPacketImpl(packet.sender(), Buffer.buffer(content))); } }
private void handleContent(Object msg) { HttpContent content = (HttpContent) msg; if (content.decoderResult() != DecoderResult.SUCCESS) { handleError(content); return; } Buffer buffer = Buffer.buffer(VertxHandler.safeBuffer(content.content(), chctx.alloc())); if (METRICS_ENABLED) { reportBytesRead(buffer); } requestInProgress.handleContent(buffer); //TODO chunk trailers if (content instanceof LastHttpContent) { handleEnd(); } }
if (msg instanceof HttpContent) { HttpContent content = (HttpContent) msg; ByteBuf buf = VertxHandler.safeBuffer(content.content(), ctx.alloc()); boolean end = msg instanceof LastHttpContent; ctx.fireChannelRead(new DefaultHttp2DataFrame(buf, end, 0));
WebSocketFrame encodeFrame(WebSocketFrameImpl frame) { ByteBuf buf = frame.getBinaryData(); if (buf != Unpooled.EMPTY_BUFFER) { buf = safeBuffer(buf, chctx.alloc()); } switch (frame.type()) { case BINARY: return new BinaryWebSocketFrame(frame.isFinal(), 0, buf); case TEXT: return new TextWebSocketFrame(frame.isFinal(), 0, buf); case CLOSE: return new CloseWebSocketFrame(true, 0, buf); case CONTINUATION: return new ContinuationWebSocketFrame(frame.isFinal(), 0, buf); case PONG: return new PongWebSocketFrame(buf); case PING: return new PingWebSocketFrame(buf); default: throw new IllegalStateException("Unsupported websocket msg " + frame); } }
ByteBuf newBuf = VertxHandler.safeBuffer(publish.payload(), chctx.alloc());
ByteBuf newBuf = VertxHandler.safeBuffer(publish.payload(), chctx.alloc());
ByteBuf newBuf = VertxHandler.safeBuffer(publish.payload(), this.chctx.alloc());
ByteBuf newBuf = VertxHandler.safeBuffer(publish.payload(), allocator);