-
Notifications
You must be signed in to change notification settings - Fork 6
/
priority.go
68 lines (54 loc) · 1.35 KB
/
priority.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package http2
import (
"github.com/dgrr/http2/http2utils"
)
const FramePriority FrameType = 0x2
var _ Frame = &Priority{}
// Priority represents the Priority frame.
//
// https://tools.ietf.org/html/rfc7540#section-6.3
type Priority struct {
stream uint32
weight byte
}
func (pry *Priority) Type() FrameType {
return FramePriority
}
// Reset resets priority fields.
func (pry *Priority) Reset() {
pry.stream = 0
pry.weight = 0
}
func (pry *Priority) CopyTo(p *Priority) {
p.stream = pry.stream
p.weight = pry.weight
}
// Stream returns the Priority frame stream.
func (pry *Priority) Stream() uint32 {
return pry.stream
}
// SetStream sets the Priority frame stream.
func (pry *Priority) SetStream(stream uint32) {
pry.stream = stream & (1<<31 - 1)
}
// Weight returns the Priority frame weight.
func (pry *Priority) Weight() byte {
return pry.weight
}
// SetWeight sets the Priority frame weight.
func (pry *Priority) SetWeight(w byte) {
pry.weight = w
}
func (pry *Priority) Deserialize(fr *FrameHeader) (err error) {
if len(fr.payload) < 5 {
err = ErrMissingBytes
} else {
pry.stream = http2utils.BytesToUint32(fr.payload) & (1<<31 - 1)
pry.weight = fr.payload[4]
}
return
}
func (pry *Priority) Serialize(fr *FrameHeader) {
fr.payload = http2utils.AppendUint32Bytes(fr.payload[:0], pry.stream)
fr.payload = append(fr.payload, pry.weight)
}