Source File
huffman.go
Belonging Package
golang.org/x/net/http2/hpack
var ErrInvalidHuffman = errors.New("hpack: invalid Huffman-encoded data")
, , := uint(0), uint8(0), uint8(0)
for , := range {
= <<8 | uint()
+= 8
+= 8
for >= 8 {
:= byte( >> ( - 8))
= .children[]
if == nil {
return ErrInvalidHuffman
}
if .children == nil {
if != 0 && .Len() == {
return ErrStringLength
}
.WriteByte(.sym)
-= .codeLen
=
=
} else {
-= 8
}
}
}
for > 0 {
= .children[byte(<<(8-))]
if == nil {
return ErrInvalidHuffman
}
if .children != nil || .codeLen > {
break
}
if != 0 && .Len() == {
return ErrStringLength
}
.WriteByte(.sym)
-= .codeLen
=
=
}
return ErrInvalidHuffman
}
return ErrInvalidHuffman
}
return nil
}
type incomparable [0]func()
type node struct {
_ incomparable
codeLen uint8 // number of bits that led to the output of sym
sym byte // output symbol
}
func () *node {
return &node{children: new([256]*node)}
}
var (
buildRootOnce sync.Once
lazyRootHuffmanNode *node
)
func () *node {
buildRootOnce.Do(buildRootHuffmanNode)
return lazyRootHuffmanNode
}
func () {
if len(huffmanCodes) != 256 {
panic("unexpected size")
}
lazyRootHuffmanNode = newInternalNode()
for , := range huffmanCodes {
addDecoderNode(byte(), , huffmanCodeLen[])
}
}
func ( byte, uint32, uint8) {
:= lazyRootHuffmanNode
for > 8 {
-= 8
:= uint8( >> )
if .children[] == nil {
.children[] = newInternalNode()
}
= .children[]
}
:= 8 -
, := int(uint8(<<)), int(1<<)
for := ; < +; ++ {
.children[] = &node{sym: , codeLen: }
}
}
![]() |
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. |