mirror of
https://github.com/refraction-networking/uquic.git
synced 2025-04-04 12:47:36 +03:00
add writing of basic ack frames
This commit is contained in:
parent
df96797e9c
commit
daa77ec2a6
2 changed files with 29 additions and 0 deletions
17
frame.go
17
frame.go
|
@ -85,3 +85,20 @@ func WriteStreamFrame(b *bytes.Buffer, f *StreamFrame) {
|
|||
utils.WriteUint16(b, uint16(len(f.Data)))
|
||||
b.Write(f.Data)
|
||||
}
|
||||
|
||||
// An AckFrame in QUIC
|
||||
type AckFrame struct {
|
||||
LargestObserved uint32 // TODO: change to uint64
|
||||
}
|
||||
|
||||
// WriteAckFrame writes an ack frame.
|
||||
func WriteAckFrame(b *bytes.Buffer, f *AckFrame) {
|
||||
typeByte := uint8(0x48)
|
||||
b.WriteByte(typeByte)
|
||||
b.WriteByte(0x00) // TODO: Entropy accumulation
|
||||
utils.WriteUint32(b, f.LargestObserved)
|
||||
utils.WriteUint16(b, 1) // TODO: Ack delay time
|
||||
b.WriteByte(0x01) // Just one timestamp
|
||||
b.WriteByte(0x00) // Largest observed
|
||||
utils.WriteUint32(b, 0) // First timestamp
|
||||
}
|
||||
|
|
|
@ -52,4 +52,16 @@ var _ = Describe("Frame", func() {
|
|||
})
|
||||
})
|
||||
})
|
||||
|
||||
Context("ACK frames", func() {
|
||||
Context("when writing", func() {
|
||||
It("writes simple frames", func() {
|
||||
b := &bytes.Buffer{}
|
||||
WriteAckFrame(b, &AckFrame{
|
||||
LargestObserved: 1,
|
||||
})
|
||||
Expect(b.Bytes()).To(Equal([]byte{0x48, 0, 0x01, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0}))
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue