Source File
encode.go
Belonging Package
vendor/golang.org/x/net/http2/hpack
package hpack
import (
)
const (
uint32Max = ^uint32(0)
initialHeaderTableSize = 4096
)
type Encoder struct {
func ( io.Writer) *Encoder {
:= &Encoder{
minSize: uint32Max,
maxSizeLimit: initialHeaderTableSize,
tableSizeUpdate: false,
w: ,
}
.dynTab.table.init()
.dynTab.setMaxSize(initialHeaderTableSize)
return
}
func ( *Encoder) ( HeaderField) error {
.buf = .buf[:0]
if .tableSizeUpdate {
.tableSizeUpdate = false
if .minSize < .dynTab.maxSize {
.buf = appendTableSize(.buf, .minSize)
}
.minSize = uint32Max
.buf = appendTableSize(.buf, .dynTab.maxSize)
}
, := .searchTable()
if {
.buf = appendIndexed(.buf, )
} else {
:= .shouldIndex()
if {
.dynTab.add()
}
if == 0 {
.buf = appendNewName(.buf, , )
} else {
.buf = appendIndexedName(.buf, , , )
}
}
, := .w.Write(.buf)
if == nil && != len(.buf) {
= io.ErrShortWrite
}
return
}
func ( *Encoder) ( HeaderField) ( uint64, bool) {
, = staticTable.search()
if {
return , true
}
, := .dynTab.table.search()
if || ( == 0 && != 0) {
return + uint64(staticTable.len()),
}
return , false
}
func ( *Encoder) ( uint32) {
if > .maxSizeLimit {
= .maxSizeLimit
}
if < .minSize {
.minSize =
}
.tableSizeUpdate = true
.dynTab.setMaxSize()
}
func ( *Encoder) ( uint32) {
.maxSizeLimit =
if .dynTab.maxSize > {
.tableSizeUpdate = true
.dynTab.setMaxSize()
}
}
func ( []byte, uint64) []byte {
:= len()
= appendVarInt(, 7, )
[] |= 0x80
return
}
func ( []byte, HeaderField, bool) []byte {
= append(, encodeTypeByte(, .Sensitive))
= appendHpackString(, .Name)
return appendHpackString(, .Value)
}
func ( []byte, HeaderField, uint64, bool) []byte {
:= len()
var byte
if {
= 6
} else {
= 4
}
= appendVarInt(, , )
[] |= encodeTypeByte(, .Sensitive)
return appendHpackString(, .Value)
}
func ( []byte, string) []byte {
:= HuffmanEncodeLength()
if < uint64(len()) {
:= len()
= appendVarInt(, 7, )
= AppendHuffmanString(, )
[] |= 0x80
} else {
= appendVarInt(, 7, uint64(len()))
= append(, ...)
}
return
}
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |