public static Frame from(int streamId, final Throwable throwable, ByteBuf dataBuffer) { if (errorLogger.isDebugEnabled()) { errorLogger.debug("an error occurred, creating error frame", throwable); } final int code = ErrorFrameFlyweight.errorCodeFromException(throwable); final Frame frame = RECYCLER.get(); frame.setRefCnt(1); frame.content = ByteBufAllocator.DEFAULT.buffer( ErrorFrameFlyweight.computeFrameLength(dataBuffer.readableBytes())); frame.content.writerIndex( ErrorFrameFlyweight.encode(frame.content, streamId, code, dataBuffer)); return frame; }
public static int errorCode(final Frame frame) { ensureFrameType(FrameType.ERROR, frame); return ErrorFrameFlyweight.errorCode(frame.content); }
public static String message(Frame frame) { ensureFrameType(FrameType.ERROR, frame); return ErrorFrameFlyweight.message(frame.content); } }
@Test public void testEncoding() { int encoded = ErrorFrameFlyweight.encode( byteBuf, 1, ErrorFrameFlyweight.APPLICATION_ERROR, Unpooled.copiedBuffer("d", StandardCharsets.UTF_8)); assertEquals("00000b000000012c000000020164", ByteBufUtil.hexDump(byteBuf, 0, encoded)); assertEquals(ErrorFrameFlyweight.APPLICATION_ERROR, ErrorFrameFlyweight.errorCode(byteBuf)); assertEquals("d", ErrorFrameFlyweight.message(byteBuf)); } }
private ByteBuf createErrorFrame(int errorCode, String message) { ByteBuf byteBuf = Unpooled.buffer(); ErrorFrameFlyweight.encode(byteBuf, 0, errorCode, Unpooled.copiedBuffer(message, UTF_8)); return byteBuf; } }
public static int encode( final ByteBuf byteBuf, final int streamId, final int errorCode, final ByteBuf data) { final int frameLength = computeFrameLength(data.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, 0, FrameType.ERROR, streamId); byteBuf.setInt(ERROR_CODE_FIELD_OFFSET, errorCode); length += Integer.BYTES; length += FrameHeaderFlyweight.encodeData(byteBuf, length, data); return length; }
private static int payloadOffset(final ByteBuf byteBuf) { int typeAndFlags = byteBuf.getShort(FRAME_TYPE_AND_FLAGS_FIELD_OFFSET); FrameType frameType = FrameType.fromEncodedType(typeAndFlags >> FRAME_TYPE_SHIFT); int result = PAYLOAD_OFFSET; switch (frameType) { case SETUP: result = SetupFrameFlyweight.payloadOffset(byteBuf); break; case ERROR: result = ErrorFrameFlyweight.payloadOffset(byteBuf); break; case LEASE: result = LeaseFrameFlyweight.payloadOffset(byteBuf); break; case KEEPALIVE: result = KeepaliveFrameFlyweight.payloadOffset(byteBuf); break; case REQUEST_RESPONSE: case REQUEST_FNF: case REQUEST_STREAM: case REQUEST_CHANNEL: result = RequestFrameFlyweight.payloadOffset(frameType, byteBuf); break; case REQUEST_N: result = RequestNFrameFlyweight.payloadOffset(byteBuf); break; } return result; }
public static int encode( final ByteBuf byteBuf, final int streamId, final int errorCode, final ByteBuf data) { final int frameLength = computeFrameLength(data.readableBytes()); int length = FrameHeaderFlyweight.encodeFrameHeader(byteBuf, frameLength, 0, FrameType.ERROR, streamId); byteBuf.setInt(ERROR_CODE_FIELD_OFFSET, errorCode); length += Integer.BYTES; length += FrameHeaderFlyweight.encodeData(byteBuf, length, data); return length; }
private static int payloadOffset(final ByteBuf byteBuf) { int typeAndFlags = byteBuf.getShort(FRAME_TYPE_AND_FLAGS_FIELD_OFFSET); FrameType frameType = FrameType.fromEncodedType(typeAndFlags >> FRAME_TYPE_SHIFT); int result = PAYLOAD_OFFSET; switch (frameType) { case SETUP: result = SetupFrameFlyweight.payloadOffset(byteBuf); break; case ERROR: result = ErrorFrameFlyweight.payloadOffset(byteBuf); break; case LEASE: result = LeaseFrameFlyweight.payloadOffset(byteBuf); break; case KEEPALIVE: result = KeepaliveFrameFlyweight.payloadOffset(byteBuf); break; case REQUEST_RESPONSE: case REQUEST_FNF: case REQUEST_STREAM: case REQUEST_CHANNEL: result = RequestFrameFlyweight.payloadOffset(frameType, byteBuf); break; case REQUEST_N: result = RequestNFrameFlyweight.payloadOffset(byteBuf); break; } return result; }
public static Frame from(int streamId, final Throwable throwable, ByteBuf dataBuffer) { if (errorLogger.isDebugEnabled()) { errorLogger.debug("an error occurred, creating error frame", throwable); } final int code = ErrorFrameFlyweight.errorCodeFromException(throwable); final Frame frame = RECYCLER.get(); frame.setRefCnt(1); frame.content = ByteBufAllocator.DEFAULT.buffer( ErrorFrameFlyweight.computeFrameLength(dataBuffer.readableBytes())); frame.content.writerIndex( ErrorFrameFlyweight.encode(frame.content, streamId, code, dataBuffer)); return frame; }
public static String message(Frame frame) { ensureFrameType(FrameType.ERROR, frame); return ErrorFrameFlyweight.message(frame.content); } }
public static int errorCode(final Frame frame) { ensureFrameType(FrameType.ERROR, frame); return ErrorFrameFlyweight.errorCode(frame.content); }