/** * Returns a test instance of {@link ErrorFrame}. * * @return a test instance of {@link ErrorFrame} */ public static ErrorFrame createTestErrorFrame() { return createErrorFrame(DEFAULT, 1, (ByteBuf) null); }
/** * Creates the {@code ERROR} frame. * * @param byteBufAllocator the {@code ByteBufAllocator} to use * @param errorCode the error code * @param data the error data * @return the {@code ERROR} frame * @throws NullPointerException if {@code byteBufAllocator} is {@code null} */ public static ErrorFrame createErrorFrame( ByteBufAllocator byteBufAllocator, int errorCode, @Nullable ByteBuf data) { ByteBuf byteBuf = createFrameTypeAndFlags(byteBufAllocator, ERROR).writeInt(errorCode); byteBuf = appendData(byteBuf, data); return RECYCLER.get().setByteBuf(byteBuf); }
/** * Returns the error code. * * @return the error code */ public int getErrorCode() { return getByteBuf().getInt(OFFSET_ERROR_CODE); }
@Override public String toString() { return "ErrorFrame{" + "errorCode=" + getErrorCode() + ", data=" + mapData(ByteBufUtil::hexDump) + '}'; } }
/** * Creates the {@code ERROR} frame. * * @param byteBufAllocator the {@code ByteBufAllocator} to use * @param errorCode the error code * @param data the error data * @return the {@code ERROR} frame * @throws NullPointerException if {@code byteBufAllocator} is {@code null} */ public static ErrorFrame createErrorFrame( ByteBufAllocator byteBufAllocator, int errorCode, @Nullable String data) { ByteBuf dataByteBuf = getUtf8AsByteBuf(data); try { return createErrorFrame(byteBufAllocator, errorCode, dataByteBuf); } finally { release(dataByteBuf); } }
/** * Creates the {@code ERROR} frame. * * @param byteBuf the {@link ByteBuf} representing the frame * @return the {@code ERROR} frame. * @throws NullPointerException if {@code byteBuf} is {@code null} */ public static ErrorFrame createErrorFrame(ByteBuf byteBuf) { Objects.requireNonNull(byteBuf, "byteBuf must not be null"); return RECYCLER.get().setByteBuf(byteBuf.retain()); }
@Override public ByteBuf getUnsafeData() { return getData(OFFSET_DATA); }
/** * Creates the {@code ERROR} frame. * * @param byteBufAllocator the {@code ByteBufAllocator} to use * @param errorCode the error code * @param data the error data * @return the {@code ERROR} frame * @throws NullPointerException if {@code byteBufAllocator} is {@code null} */ public static ErrorFrame createErrorFrame( ByteBufAllocator byteBufAllocator, int errorCode, @Nullable String data) { ByteBuf dataByteBuf = getUtf8AsByteBuf(data); try { return createErrorFrame(byteBufAllocator, errorCode, dataByteBuf); } finally { release(dataByteBuf); } }
@Override public String toString() { return "ErrorFrame{" + "errorCode=" + getErrorCode() + ", data=" + mapData(ByteBufUtil::hexDump) + '}'; } }
/** * Creates the {@code ERROR} frame. * * @param byteBuf the {@link ByteBuf} representing the frame * @return the {@code ERROR} frame. * @throws NullPointerException if {@code byteBuf} is {@code null} */ public static ErrorFrame createErrorFrame(ByteBuf byteBuf) { Objects.requireNonNull(byteBuf, "byteBuf must not be null"); return RECYCLER.get().setByteBuf(byteBuf.retain()); }
@Override public ByteBuf getUnsafeData() { return getData(OFFSET_DATA); }
public static ErrorFrame createTestErrorFrame() { return createErrorFrame(DEFAULT, 1, (ByteBuf) null); }
/** * Creates the {@code ERROR} frame. * * @param byteBufAllocator the {@code ByteBufAllocator} to use * @param errorCode the error code * @param data the error data * @return the {@code ERROR} frame * @throws NullPointerException if {@code byteBufAllocator} is {@code null} */ public static ErrorFrame createErrorFrame( ByteBufAllocator byteBufAllocator, int errorCode, @Nullable ByteBuf data) { ByteBuf byteBuf = createFrameTypeAndFlags(byteBufAllocator, ERROR).writeInt(errorCode); byteBuf = appendData(byteBuf, data); return RECYCLER.get().setByteBuf(byteBuf); }
/** * Returns the error code. * * @return the error code */ public int getErrorCode() { return getByteBuf().getInt(OFFSET_ERROR_CODE); }
@DisplayName("createErrorFrame throws NullPointerException with null byteBufAllocator") @Test void createErrorFrameNullByteBufAllocator() { assertThatNullPointerException() .isThrownBy(() -> createErrorFrame(null, 0, EMPTY_BUFFER)) .withMessage("byteBufAllocator must not be null"); }
return createPayloadFrame(byteBuf); case ERROR: return createErrorFrame(byteBuf); case METADATA_PUSH: return createMetadataPushFrame(byteBuf);
return createPayloadFrame(byteBuf); case ERROR: return createErrorFrame(byteBuf); case METADATA_PUSH: return createMetadataPushFrame(byteBuf);