// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_CONTINUATION_FRAME = 0x09;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DATA_FRAME = 0x00;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DEFAULT_DEPENDENCY = 0;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DEFAULT_WEIGHT = 16;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_ACK = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_END_HEADERS = 0x04;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_END_STREAM = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_PRIORITY = 0x20;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_FRAME_HEADER_SIZE = 9;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_GOAWAY_FRAME = 0x07;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_HEADERS_FRAME = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_MAX_LENGTH = 0x4000; // Initial MAX_FRAME_SIZE value is 2^14
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PING_FRAME = 0x06;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PRIORITY_FRAME = 0x02;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PUSH_PROMISE_FRAME = 0x05;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_RST_STREAM_FRAME = 0x03;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_SETTINGS_FRAME = 0x04;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_WINDOW_UPDATE_FRAME = 0x08;


import java.util.Set;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import static com.twitter.http2.HttpCodecUtil.HTTP_CONTINUATION_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_DATA_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_DEFAULT_DEPENDENCY;
import static com.twitter.http2.HttpCodecUtil.HTTP_DEFAULT_WEIGHT;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_ACK;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_END_HEADERS;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_END_STREAM;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_PRIORITY;
import static com.twitter.http2.HttpCodecUtil.HTTP_FRAME_HEADER_SIZE;
import static com.twitter.http2.HttpCodecUtil.HTTP_GOAWAY_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_HEADERS_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_MAX_LENGTH;
import static com.twitter.http2.HttpCodecUtil.HTTP_PING_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_PRIORITY_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_PUSH_PROMISE_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_RST_STREAM_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_SETTINGS_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_WINDOW_UPDATE_FRAME;
            header.writeByte(weight - 1);
            length -= 5;
        }
        ByteBuf frame = Unpooled.wrappedBuffer(header, headerBlock.readSlice(length));
        if (needsContinuations) {
            while (headerBlock.readableBytes() > HTTP_MAX_LENGTH) {
                header = Unpooled.buffer(HTTP_FRAME_HEADER_SIZE);
                writeFrameHeader(header, HTTP_MAX_LENGTH, HTTP_CONTINUATION_FRAME, (byte) 0, streamId);
                frame = Unpooled.wrappedBuffer(frame, header, headerBlock.readSlice(HTTP_MAX_LENGTH));
            }
            header = Unpooled.buffer(HTTP_FRAME_HEADER_SIZE);
            writeFrameHeader(
                    header,
                    headerBlock.readableBytes(),
                    HTTP_CONTINUATION_FRAME,
                    HTTP_FLAG_END_HEADERS,
                    streamId
            );
            frame = Unpooled.wrappedBuffer(frame, header, headerBlock);
        }
        return frame;
    }

    /**
     * Encode an HTTP/2 PRIORITY Frame
     */
    public ByteBuf encodePriorityFrame(int streamId, boolean exclusive, int dependency, int weight) {
        int length = 5;
        byte flags = 0;
        ByteBuf frame = Unpooled.buffer(HTTP_FRAME_HEADER_SIZE + length);
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_CONTINUATION_FRAME = 0x09;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DATA_FRAME = 0x00;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DEFAULT_DEPENDENCY = 0;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_DEFAULT_WEIGHT = 16;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_ACK = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_END_HEADERS = 0x04;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_END_STREAM = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final byte HTTP_FLAG_PRIORITY = 0x20;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_FRAME_HEADER_SIZE = 9;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_GOAWAY_FRAME = 0x07;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_HEADERS_FRAME = 0x01;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_MAX_LENGTH = 0x4000; // Initial MAX_FRAME_SIZE value is 2^14
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PING_FRAME = 0x06;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PRIORITY_FRAME = 0x02;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_PUSH_PROMISE_FRAME = 0x05;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_RST_STREAM_FRAME = 0x03;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_SETTINGS_FRAME = 0x04;
// 
// Path: src/main/java/com/twitter/http2/HttpCodecUtil.java
// static final int HTTP_WINDOW_UPDATE_FRAME = 0x08;


// Path: src/main/java/com/twitter/http2/HttpFrameEncoder.java
import java.util.Set;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import static com.twitter.http2.HttpCodecUtil.HTTP_CONTINUATION_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_DATA_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_DEFAULT_DEPENDENCY;
import static com.twitter.http2.HttpCodecUtil.HTTP_DEFAULT_WEIGHT;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_ACK;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_END_HEADERS;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_END_STREAM;
import static com.twitter.http2.HttpCodecUtil.HTTP_FLAG_PRIORITY;
import static com.twitter.http2.HttpCodecUtil.HTTP_FRAME_HEADER_SIZE;
import static com.twitter.http2.HttpCodecUtil.HTTP_GOAWAY_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_HEADERS_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_MAX_LENGTH;
import static com.twitter.http2.HttpCodecUtil.HTTP_PING_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_PRIORITY_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_PUSH_PROMISE_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_RST_STREAM_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_SETTINGS_FRAME;
import static com.twitter.http2.HttpCodecUtil.HTTP_WINDOW_UPDATE_FRAME;

            header.writeByte(weight - 1);
            length -= 5;
        }
        ByteBuf frame = Unpooled.wrappedBuffer(header, headerBlock.readSlice(length));
        if (needsContinuations) {
            while (headerBlock.readableBytes() > HTTP_MAX_LENGTH) {
                header = Unpooled.buffer(HTTP_FRAME_HEADER_SIZE);
                writeFrameHeader(header, HTTP_MAX_LENGTH, HTTP_CONTINUATION_FRAME, (byte) 0, streamId);
                frame = Unpooled.wrappedBuffer(frame, header, headerBlock.readSlice(HTTP_MAX_LENGTH));
            }
            header = Unpooled.buffer(HTTP_FRAME_HEADER_SIZE);
            writeFrameHeader(
                    header,
                    headerBlock.readableBytes(),
                    HTTP_CONTINUATION_FRAME,
                    HTTP_FLAG_END_HEADERS,
                    streamId
            );
            frame = Unpooled.wrappedBuffer(frame, header, headerBlock);
        }
        return frame;
    }

    /**
     * Encode an HTTP/2 PRIORITY Frame
     */
    public ByteBuf encodePriorityFrame(int streamId, boolean exclusive, int dependency, int weight) {
        int length = 5;
        byte flags = 0;
        ByteBuf frame = Unpooled.buffer(HTTP_FRAME_HEADER_SIZE + length);
        writeFrameHeader(frame, length, HTTP_PRIORITY_FRAME, flags, streamId);