...
1
2
3
4
5
6
7 package quic
8
9 import (
10 "sync"
11 "time"
12 )
13
14
15
16 type sentPacket struct {
17 num packetNumber
18 size int
19 time time.Time
20
21 ackEliciting bool
22 inFlight bool
23 acked bool
24 lost bool
25
26
27
28
29
30
31
32
33
34 b []byte
35 n int
36 }
37
38 var sentPool = sync.Pool{
39 New: func() any {
40 return &sentPacket{}
41 },
42 }
43
44 func newSentPacket() *sentPacket {
45 sent := sentPool.Get().(*sentPacket)
46 sent.reset()
47 return sent
48 }
49
50
51 func (sent *sentPacket) recycle() {
52 sentPool.Put(sent)
53 }
54
55 func (sent *sentPacket) reset() {
56 *sent = sentPacket{
57 b: sent.b[:0],
58 }
59 }
60
61
62
63 func (sent *sentPacket) appendNonAckElicitingFrame(frameType byte) {
64 sent.b = append(sent.b, frameType)
65 }
66
67 func (sent *sentPacket) appendAckElicitingFrame(frameType byte) {
68 sent.ackEliciting = true
69 sent.inFlight = true
70 sent.b = append(sent.b, frameType)
71 }
72
73 func (sent *sentPacket) appendInt(v uint64) {
74 sent.b = appendVarint(sent.b, v)
75 }
76
77 func (sent *sentPacket) appendOffAndSize(start int64, size int) {
78 sent.b = appendVarint(sent.b, uint64(start))
79 sent.b = appendVarint(sent.b, uint64(size))
80 }
81
82
83
84 func (sent *sentPacket) next() (frameType byte) {
85 f := sent.b[sent.n]
86 sent.n++
87 return f
88 }
89
90 func (sent *sentPacket) nextInt() uint64 {
91 v, n := consumeVarint(sent.b[sent.n:])
92 sent.n += n
93 return v
94 }
95
96 func (sent *sentPacket) nextRange() (start, end int64) {
97 start = int64(sent.nextInt())
98 end = start + int64(sent.nextInt())
99 return start, end
100 }
101
102 func (sent *sentPacket) done() bool {
103 return sent.n == len(sent.b)
104 }
105
View as plain text