1 /* 2 * Copyright 2020 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 package io.netty.handler.codec.http3; 17 18 import static io.netty.util.internal.ObjectUtil.checkNotNull; 19 20 class QpackHeaderField { 21 22 /** 23 * <a href="https://www.rfc-editor.org/rfc/rfc9204.html#name-dynamic-table-size"> 24 * Section 3.2.1 Dynamic Table Size</a>. 25 * The size of an entry is the sum of its name's length in bytes, its 26 * value's length in bytes, and 32. 27 */ 28 static final int ENTRY_OVERHEAD = 32; 29 30 static long sizeOf(CharSequence name, CharSequence value) { 31 return name.length() + value.length() + ENTRY_OVERHEAD; 32 } 33 34 final CharSequence name; 35 final CharSequence value; 36 37 // This constructor can only be used if name and value are ISO-8859-1 encoded. 38 QpackHeaderField(CharSequence name, CharSequence value) { 39 this.name = checkNotNull(name, "name"); 40 this.value = checkNotNull(value, "value"); 41 } 42 43 long size() { 44 return sizeOf(name, value); 45 } 46 47 @Override 48 public String toString() { 49 return name + ": " + value; 50 } 51 }