1 /*
2 * Copyright 2015 The Netty Project
3 *
4 * The Netty Project licenses this file to you under the Apache License,
5 * version 2.0 (the "License"); you may not use this file except in compliance
6 * with the License. You may obtain a copy of the License at:
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations
14 * under the License.
15 */
16
17 /*
18 * Copyright 2015 Twitter, Inc.
19 *
20 * Licensed under the Apache License, Version 2.0 (the "License");
21 * you may not use this file except in compliance with the License.
22 * You may obtain a copy of the License at
23 *
24 * https://www.apache.org/licenses/LICENSE-2.0
25 *
26 * Unless required by applicable law or agreed to in writing, software
27 * distributed under the License is distributed on an "AS IS" BASIS,
28 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
29 * See the License for the specific language governing permissions and
30 * limitations under the License.
31 */
32 package io.netty5.handler.codec.http2;
33
34 import io.netty5.buffer.api.Buffer;
35
36 import java.util.List;
37
38 import static io.netty5.buffer.api.DefaultBufferAllocators.onHeapAllocator;
39
40 /**
41 * Enum that indicates the size of the headers to be used for the benchmark.
42 */
43 public enum HpackHeadersSize {
44 SMALL(5, 20, 40),
45 MEDIUM(20, 40, 80),
46 LARGE(100, 100, 300);
47
48 private final int numHeaders;
49 private final int nameLength;
50 private final int valueLength;
51
52 HpackHeadersSize(int numHeaders, int nameLength, int valueLength) {
53 this.numHeaders = numHeaders;
54 this.nameLength = nameLength;
55 this.valueLength = valueLength;
56 }
57
58 public List<HpackHeader> newHeaders(boolean limitAscii) {
59 return HpackHeader.createHeaders(numHeaders, nameLength, valueLength, limitAscii);
60 }
61
62 public Buffer newOutBuffer() {
63 return onHeapAllocator().allocate(numHeaders * (nameLength + valueLength));
64 }
65 }