Home / Class/ Http3FrameValidationUtils Class — netty Architecture

Http3FrameValidationUtils Class — netty Architecture

Architecture documentation for the Http3FrameValidationUtils class in Http3FrameValidationUtils.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  6c904938_27e7_1841_a972_600874324a0f["Http3FrameValidationUtils"]
  85d28ec6_7f69_0249_8c91_7176ca8f2bce["Http3FrameValidationUtils.java"]
  6c904938_27e7_1841_a972_600874324a0f -->|defined in| 85d28ec6_7f69_0249_8c91_7176ca8f2bce
  e18564aa_4cfc_d5c0_5df1_78c5a00edfdb["Http3FrameValidationUtils()"]
  6c904938_27e7_1841_a972_600874324a0f -->|method| e18564aa_4cfc_d5c0_5df1_78c5a00edfdb
  4d4fd860_2af4_dc76_2237_8007888c50cf["T()"]
  6c904938_27e7_1841_a972_600874324a0f -->|method| 4d4fd860_2af4_dc76_2237_8007888c50cf
  390c7f60_3b90_c6dc_ee90_fc87902024f3["isValid()"]
  6c904938_27e7_1841_a972_600874324a0f -->|method| 390c7f60_3b90_c6dc_ee90_fc87902024f3
  2822afc7_eddb_27ce_59b6_12f016fde506["frameTypeUnexpected()"]
  6c904938_27e7_1841_a972_600874324a0f -->|method| 2822afc7_eddb_27ce_59b6_12f016fde506

Relationship Graph

Source Code

codec-http3/src/main/java/io/netty/handler/codec/http3/Http3FrameValidationUtils.java lines 24–97

final class Http3FrameValidationUtils {

    private Http3FrameValidationUtils() {
        // no instances
    }

    @SuppressWarnings("unchecked")
    private static <T> T cast(Object msg) {
        return (T) msg;
    }

    private static <T> boolean isValid(Class<T> frameType, Object msg) {
        return frameType.isInstance(msg);
    }

    /**
     * Check if the passed {@code msg} is of the {@code expectedFrameType} and return the expected type, else return
     * {@code null}.
     *
     * @param expectedFrameType {@link Class} of the expected frame type.
     * @param msg to validate.
     * @param <T> Expected type.
     * @return {@code msg} as expected frame type or {@code null} if it can not be converted to the expected type.
     */
    @Nullable
    static <T> T validateFrameWritten(Class<T> expectedFrameType, Object msg) {
        if (isValid(expectedFrameType, msg)) {
            return cast(msg);
        }
        return null;
    }

    /**
     * Check if the passed {@code msg} is of the {@code expectedFrameType} and return the expected type, else return
     * {@code null}.
     *
     * @param expectedFrameType {@link Class} of the expected frame type.
     * @param msg to validate.
     * @param <T> Expected type.
     * @return {@code msg} as expected frame type or {@code null} if it can not be converted to the expected type.
     */
    @Nullable
    static <T> T validateFrameRead(Class<T> expectedFrameType, Object msg) {
        if (isValid(expectedFrameType, msg)) {
            return cast(msg);
        }
        return null;
    }

    /**
     * Handle unexpected frame type by failing the passed {@link ChannelPromise}.
     *
     * @param promise to fail.
     * @param frame which is unexpected.
     */
    static void frameTypeUnexpected(ChannelPromise promise, Object frame) {
        String type = StringUtil.simpleClassName(frame);
        ReferenceCountUtil.release(frame);
        promise.setFailure(new Http3Exception(Http3ErrorCode.H3_FRAME_UNEXPECTED,
                "Frame of type " + type + " unexpected"));
    }

    /**
     * Handle unexpected frame type by propagating a connection error with code:
     * {@link Http3ErrorCode#H3_FRAME_UNEXPECTED}.
     *
     * @param ctx to use for propagation of failure.
     * @param frame which is unexpected.
     */
    static void frameTypeUnexpected(ChannelHandlerContext ctx, Object frame) {
        ReferenceCountUtil.release(frame);
        Http3CodecUtils.connectionError(ctx, Http3ErrorCode.H3_FRAME_UNEXPECTED, "Frame type unexpected", true);
    }
}

Frequently Asked Questions

What is the Http3FrameValidationUtils class?
Http3FrameValidationUtils is a class in the netty codebase, defined in codec-http3/src/main/java/io/netty/handler/codec/http3/Http3FrameValidationUtils.java.
Where is Http3FrameValidationUtils defined?
Http3FrameValidationUtils is defined in codec-http3/src/main/java/io/netty/handler/codec/http3/Http3FrameValidationUtils.java at line 24.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free