-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathqpack_encode.go
47 lines (40 loc) · 1.35 KB
/
qpack_encode.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright 2025 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
//go:build go1.24
package http3
type qpackEncoder struct {
// The encoder has no state for now,
// but that'll change once we add dynamic table support.
//
// TODO: dynamic table support.
}
func (qe *qpackEncoder) init() {
staticTableOnce.Do(initStaticTableMaps)
}
// encode encodes a list of headers into a QPACK encoded field section.
//
// The headers func must produce the same headers on repeated calls,
// although the order may vary.
func (qe *qpackEncoder) encode(headers func(func(itype indexType, name, value string))) []byte {
// Encoded Field Section prefix.
//
// We don't yet use the dynamic table, so both values here are zero.
var b []byte
b = appendPrefixedInt(b, 0, 8, 0) // Required Insert Count
b = appendPrefixedInt(b, 0, 7, 0) // Delta Base
headers(func(itype indexType, name, value string) {
if itype == mayIndex {
if i, ok := staticTableByNameValue[tableEntry{name, value}]; ok {
b = appendIndexedFieldLine(b, staticTable, i)
return
}
}
if i, ok := staticTableByName[name]; ok {
b = appendLiteralFieldLineWithNameReference(b, staticTable, itype, i, value)
} else {
b = appendLiteralFieldLineWithLiteralName(b, itype, name, value)
}
})
return b
}