/** * Returns a test instance of {@link ExtensionFrame}. * * @return a test instance of {@link ExtensionFrame} */ public static ExtensionFrame createTestExtensionFrame() { return createExtensionFrame(DEFAULT, true, 1, (ByteBuf) null, null); }
/** * Creates the {@code EXT} frame. * * @param byteBufAllocator the {@code ByteBufAllocator} to use * @param ignore whether to set the Ignore flag * @param extendedType the type of the extended frame * @param metadata the {@code metadata} * @param data the {@code data} * @return the {@code EXT} frame * @throws NullPointerException if {@code byteBufAllocator} is {@code null} */ public static ExtensionFrame createExtensionFrame( ByteBufAllocator byteBufAllocator, boolean ignore, int extendedType, @Nullable ByteBuf metadata, @Nullable ByteBuf data) { ByteBuf byteBuf = createFrameTypeAndFlags(byteBufAllocator, EXT); if (ignore) { byteBuf = setFlag(byteBuf, FLAG_IGNORE); } byteBuf = byteBuf.writeInt(extendedType); byteBuf = appendMetadata(byteBufAllocator, byteBuf, metadata); byteBuf = appendData(byteBuf, data); return RECYCLER.get().setByteBuf(byteBuf); }
/** * Returns the extended type. * * @return the extended type */ public int getExtendedType() { return getByteBuf().getInt(OFFSET_EXTENDED_TYPE); }
@Override public String toString() { return "ExtensionFrame{" + "ignore=" + isIgnoreFlagSet() + ", extendedType=" + getExtendedType() + ", metadata=" + mapMetadata(ByteBufUtil::hexDump) + ", data=" + mapData(ByteBufUtil::hexDump) + '}'; } }
/** * Creates the {@code EXT} frame. * * @param byteBufAllocator the {@code ByteBufAllocator} to use * @param ignore whether to set the Ignore flag * @param extendedType the type of the extended frame * @param metadata the {@code metadata} * @param data the {@code data} * @return the {@code EXT} frame * @throws NullPointerException if {@code byteBufAllocator} is {@code null} */ public static ExtensionFrame createExtensionFrame( ByteBufAllocator byteBufAllocator, boolean ignore, int extendedType, @Nullable String metadata, @Nullable String data) { ByteBuf metadataByteBuf = getUtf8AsByteBuf(metadata); ByteBuf dataByteBuf = getUtf8AsByteBuf(data); try { return createExtensionFrame( byteBufAllocator, ignore, extendedType, metadataByteBuf, dataByteBuf); } finally { release(metadataByteBuf); release(dataByteBuf); } }
@Override public @Nullable ByteBuf getUnsafeMetadata() { return getMetadata(OFFSET_METADATA_LENGTH); }
/** * Returns whether the Ignore flag is set. * * @return whether the Ignore flag is set */ public boolean isIgnoreFlagSet() { return isFlagSet(FLAG_IGNORE); }
@Override public ByteBuf getUnsafeData() { return getData(OFFSET_METADATA_LENGTH); }
@Override public String toString() { return "ExtensionFrame{" + "ignore=" + isIgnoreFlagSet() + ", extendedType=" + getExtendedType() + ", metadata=" + mapMetadata(ByteBufUtil::hexDump) + ", data=" + mapData(ByteBufUtil::hexDump) + '}'; } }
/** * Creates the {@code EXT} frame. * * @param byteBufAllocator the {@code ByteBufAllocator} to use * @param ignore whether to set the Ignore flag * @param extendedType the type of the extended frame * @param metadata the {@code metadata} * @param data the {@code data} * @return the {@code EXT} frame * @throws NullPointerException if {@code byteBufAllocator} is {@code null} */ public static ExtensionFrame createExtensionFrame( ByteBufAllocator byteBufAllocator, boolean ignore, int extendedType, @Nullable String metadata, @Nullable String data) { ByteBuf metadataByteBuf = getUtf8AsByteBuf(metadata); ByteBuf dataByteBuf = getUtf8AsByteBuf(data); try { return createExtensionFrame( byteBufAllocator, ignore, extendedType, metadataByteBuf, dataByteBuf); } finally { release(metadataByteBuf); release(dataByteBuf); } }
@Override public @Nullable ByteBuf getUnsafeMetadata() { return getMetadata(OFFSET_METADATA_LENGTH); }
/** * Returns whether the Ignore flag is set. * * @return whether the Ignore flag is set */ public boolean isIgnoreFlagSet() { return isFlagSet(FLAG_IGNORE); }
@Override public ByteBuf getUnsafeData() { return getData(OFFSET_METADATA_LENGTH); }
/** * Creates the {@code EXT} frame. * * @param byteBufAllocator the {@code ByteBufAllocator} to use * @param ignore whether to set the Ignore flag * @param extendedType the type of the extended frame * @param metadata the {@code metadata} * @param data the {@code data} * @return the {@code EXT} frame * @throws NullPointerException if {@code byteBufAllocator} is {@code null} */ public static ExtensionFrame createExtensionFrame( ByteBufAllocator byteBufAllocator, boolean ignore, int extendedType, @Nullable ByteBuf metadata, @Nullable ByteBuf data) { ByteBuf byteBuf = createFrameTypeAndFlags(byteBufAllocator, EXT); if (ignore) { byteBuf = setFlag(byteBuf, FLAG_IGNORE); } byteBuf = byteBuf.writeInt(extendedType); byteBuf = appendMetadata(byteBufAllocator, byteBuf, metadata); byteBuf = appendData(byteBuf, data); return RECYCLER.get().setByteBuf(byteBuf); }
public static ExtensionFrame createTestExtensionFrame() { return createExtensionFrame(DEFAULT, true, 1, (ByteBuf) null, null); }
/** * Returns the extended type. * * @return the extended type */ public int getExtendedType() { return getByteBuf().getInt(OFFSET_EXTENDED_TYPE); }
return createResumeOkFrame(byteBuf); case EXT: return createExtensionFrame(byteBuf); default: throw new IllegalArgumentException(
@DisplayName("createExtensionFrame throws NullPointerException with null byteBufAllocator") @Test void createExtensionFrameNullByteBuf() { assertThatNullPointerException() .isThrownBy(() -> createExtensionFrame(null, true, 100, (ByteBuf) null, null)) .withMessage("byteBufAllocator must not be null"); }
return createResumeOkFrame(byteBuf); case EXT: return createExtensionFrame(byteBuf); default: throw new IllegalArgumentException(