/** * Returns a test instance of {@link SetupFrame}. * * @return a test instance of {@link SetupFrame} */ public static SetupFrame createTestSetupFrame() { return createSetupFrame( DEFAULT, true, 1, 1, Duration.ofMillis(1), Duration.ofMillis(1), null, "", "", null, null); }
/** * Returns the resume identification token directly. If the Resume Enabled flag is not set, * returns {@code null}. * * <p><b>Note:</b> this resume identification token will be outside of the {@link Frame}'s * lifecycle and may be released at any time. It is highly recommended that you {@link * ByteBuf#retain()} the resume identification token if you store it. * * @return the resume identification token directly, or {@code null} if the Resume Enabled flag is * not set * @see #mapResumeIdentificationToken(Function) */ public @Nullable ByteBuf getUnsafeResumeIdentificationToken() { if (!isFlagSet(FLAG_RESUME_ENABLED)) { return null; } ByteBuf byteBuf = getByteBuf(); return byteBuf.slice( getResumeIdentificationTokenOffset(), getResumeIdentificationTokenLength()); }
@Override public ByteBuf getUnsafeData() { return getData(getMetadataLengthOffset()); }
private int getMetadataLengthOffset() { return getDataMimeTypeOffset() + getDataMimeTypeLength(); }
@Override public String toString() { return "SetupFrame{" + "lease=" + isLeaseFlagSet() + ", majorVersion=" + getMajorVersion() + ", minorVersion=" + getMinorVersion() + ", keepAliveInterval=" + getKeepAliveInterval() + ", maxLifetime=" + getMaxLifetime() + ", resumeIdentificationToken=" + mapResumeIdentificationToken(ByteBufUtil::hexDump) + ", metadataMimeType=" + getMetadataMimeType() + ", dataMimeType=" + getDataMimeType() + ", metadata=" + mapMetadata(ByteBufUtil::hexDump) + ", data=" + mapData(ByteBufUtil::hexDump) + '}'; }
ByteBuf resumeIdentificationTokenByteBuf = getUtf8AsByteBuf(resumeIdentificationToken); ByteBuf metadataByteBuf = getUtf8AsByteBuf(metadata); ByteBuf dataByteBuf = getUtf8AsByteBuf(data); return createSetupFrame( byteBufAllocator, lease, return createSetupFrame( byteBufAllocator, lease, getUtf8AsByteBufRequired(metadataMimeType, "metadataMimeType must not be null"); ByteBuf dataMimeTypeByteBuf = getUtf8AsByteBufRequired(dataMimeType, "dataMimeType must not be null"); ByteBuf byteBuf = createFrameTypeAndFlags(byteBufAllocator, FrameType.SETUP); byteBuf = setFlag(byteBuf, FLAG_LEASE); setFlag(byteBuf, FLAG_RESUME_ENABLED) .writeShort(getLengthAsUnsignedShort(resumeIdentificationToken)); byteBuf = byteBuf = appendMetadata(byteBufAllocator, byteBuf, metadata); byteBuf = appendData(byteBuf, data); return RECYCLER.get().setByteBuf(byteBuf); } finally {
/** * Returns the data MIME-type. * * @param charset the {@link Charset} to decode the data MIME-type with * @return the data MIME-type */ public String getDataMimeType(Charset charset) { return getByteBuf().slice(getDataMimeTypeOffset(), getDataMimeTypeLength()).toString(charset); }
/** * Returns the metadata MIME-type. * * @param charset the {@link Charset} to decode the metadata MIME-type with * @return the metadata MIME-type */ public String getMetadataMimeType(Charset charset) { return getByteBuf() .slice(getMetadataMimeTypeOffset(), getMetadataMimeTypeLength()) .toString(charset); }
/** * Returns the keep alive interval. * * @return the keep alive interval */ public Duration getKeepAliveInterval() { return Duration.ofMillis(getByteBuf().getInt(OFFSET_KEEPALIVE_INTERVAL)); }
private int getResumeIdentificationTokenLength() { if (isFlagSet(FLAG_RESUME_ENABLED)) { return getByteBuf().getUnsignedShort(OFFSET_RESUME_IDENTIFICATION_TOKEN_LENGTH); } else { return 0; } }
private int getDataMimeTypeLength() { return getByteBuf().getUnsignedByte(getDataMimeTypeLengthOffset()); }
private int getMetadataMimeTypeLength() { return getByteBuf().getUnsignedByte(getMetadataMimeTypeLengthOffset()); }
/** * Returns the data MIME-type, decoded at {@link StandardCharsets#UTF_8}. * * @return the data MIME-type, decoded as {@link StandardCharsets#UTF_8} */ public String getDataMimeType() { return getDataMimeType(UTF_8); }
private int getDataMimeTypeOffset() { return getDataMimeTypeLengthOffset() + Byte.BYTES; }
@Override public String toString() { return "SetupFrame{" + "lease=" + isLeaseFlagSet() + ", majorVersion=" + getMajorVersion() + ", minorVersion=" + getMinorVersion() + ", keepAliveInterval=" + getKeepAliveInterval() + ", maxLifetime=" + getMaxLifetime() + ", resumeIdentificationToken=" + mapResumeIdentificationToken(ByteBufUtil::hexDump) + ", metadataMimeType=" + getMetadataMimeType() + ", dataMimeType=" + getDataMimeType() + ", metadata=" + mapMetadata(ByteBufUtil::hexDump) + ", data=" + mapData(ByteBufUtil::hexDump) + '}'; }
ByteBuf resumeIdentificationTokenByteBuf = getUtf8AsByteBuf(resumeIdentificationToken); ByteBuf metadataByteBuf = getUtf8AsByteBuf(metadata); ByteBuf dataByteBuf = getUtf8AsByteBuf(data); return createSetupFrame( byteBufAllocator, lease, return createSetupFrame( byteBufAllocator, lease, getUtf8AsByteBufRequired(metadataMimeType, "metadataMimeType must not be null"); ByteBuf dataMimeTypeByteBuf = getUtf8AsByteBufRequired(dataMimeType, "dataMimeType must not be null"); ByteBuf byteBuf = createFrameTypeAndFlags(byteBufAllocator, FrameType.SETUP); byteBuf = setFlag(byteBuf, FLAG_LEASE); setFlag(byteBuf, FLAG_RESUME_ENABLED) .writeShort(getLengthAsUnsignedShort(resumeIdentificationToken)); byteBuf = byteBuf = appendMetadata(byteBufAllocator, byteBuf, metadata); byteBuf = appendData(byteBuf, data); return RECYCLER.get().setByteBuf(byteBuf); } finally {
/** * Returns the data MIME-type. * * @param charset the {@link Charset} to decode the data MIME-type with * @return the data MIME-type */ public String getDataMimeType(Charset charset) { return getByteBuf().slice(getDataMimeTypeOffset(), getDataMimeTypeLength()).toString(charset); }
/** * Returns the metadata MIME-type. * * @param charset the {@link Charset} to decode the metadata MIME-type with * @return the metadata MIME-type */ public String getMetadataMimeType(Charset charset) { return getByteBuf() .slice(getMetadataMimeTypeOffset(), getMetadataMimeTypeLength()) .toString(charset); }
/** * Returns the major version of the protocol. * * @return the major version of the protocol */ public int getMajorVersion() { return getByteBuf().getUnsignedShort(OFFSET_MAJOR_VERSION); }
private int getResumeIdentificationTokenLength() { if (isFlagSet(FLAG_RESUME_ENABLED)) { return getByteBuf().getUnsignedShort(OFFSET_RESUME_IDENTIFICATION_TOKEN_LENGTH); } else { return 0; } }