// 
// Decompiled by Procyon v0.6.0
// 

package io.netty.handler.codec.http3;

import io.netty.channel.socket.ChannelInputShutdownReadComplete;
import io.netty.channel.ChannelHandlerContext;

final class Http3PushStreamClientValidationHandler extends Http3FrameTypeInboundValidationHandler<Http3RequestStreamFrame>
{
    private final QpackAttributes qpackAttributes;
    private final QpackDecoder qpackDecoder;
    private final Http3RequestStreamCodecState decodeState;
    private long expectedLength;
    private long seenLength;
    
    Http3PushStreamClientValidationHandler(final QpackAttributes qpackAttributes, final QpackDecoder qpackDecoder, final Http3RequestStreamCodecState decodeState) {
        super(Http3RequestStreamFrame.class);
        this.expectedLength = -1L;
        this.qpackAttributes = qpackAttributes;
        this.qpackDecoder = qpackDecoder;
        this.decodeState = decodeState;
    }
    
    @Override
    void channelRead(final ChannelHandlerContext ctx, final Http3RequestStreamFrame frame) {
        if (frame instanceof Http3PushPromiseFrame) {
            ctx.fireChannelRead((Object)frame);
            return;
        }
        if (frame instanceof Http3HeadersFrame) {
            final Http3HeadersFrame headersFrame = (Http3HeadersFrame)frame;
            final long maybeContentLength = Http3RequestStreamValidationUtils.validateHeaderFrameRead(headersFrame, ctx, this.decodeState);
            if (maybeContentLength >= 0L) {
                this.expectedLength = maybeContentLength;
            }
            else if (maybeContentLength == -2L) {
                return;
            }
        }
        if (frame instanceof Http3DataFrame) {
            final Http3DataFrame dataFrame = (Http3DataFrame)frame;
            final long maybeContentLength = Http3RequestStreamValidationUtils.validateDataFrameRead(dataFrame, ctx, this.expectedLength, this.seenLength, false);
            if (maybeContentLength >= 0L) {
                this.seenLength = maybeContentLength;
            }
            else if (maybeContentLength == -2L) {
                return;
            }
        }
        ctx.fireChannelRead((Object)frame);
    }
    
    @Override
    public void userEventTriggered(final ChannelHandlerContext ctx, final Object evt) {
        if (evt == ChannelInputShutdownReadComplete.INSTANCE) {
            Http3RequestStreamValidationUtils.sendStreamAbandonedIfRequired(ctx, this.qpackAttributes, this.qpackDecoder, this.decodeState);
            if (!Http3RequestStreamValidationUtils.validateOnStreamClosure(ctx, this.expectedLength, this.seenLength, false)) {
                return;
            }
        }
        ctx.fireUserEventTriggered(evt);
    }
    
    @Override
    public boolean isSharable() {
        return false;
    }
}
