refactor header writing to append to a byte slice (#3646)

This avoids having to allocate a bytes.Buffer.
This commit is contained in:
Marten Seemann 2023-01-17 01:56:06 -08:00 committed by GitHub
parent 3d4bbc28ba
commit c24fbb094c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
18 changed files with 282 additions and 279 deletions

View file

@ -28,7 +28,6 @@ func isProxyRunning() bool {
var _ = Describe("QUIC Proxy", func() {
makePacket := func(p protocol.PacketNumber, payload []byte) []byte {
b := &bytes.Buffer{}
hdr := wire.ExtendedHeader{
Header: wire.Header{
Type: protocol.PacketTypeInitial,
@ -40,10 +39,10 @@ var _ = Describe("QUIC Proxy", func() {
PacketNumber: p,
PacketNumberLen: protocol.PacketNumberLen4,
}
Expect(hdr.Write(b, protocol.VersionWhatever)).To(Succeed())
raw := b.Bytes()
raw = append(raw, payload...)
return raw
b, err := hdr.Append(nil, protocol.Version1)
Expect(err).ToNot(HaveOccurred())
b = append(b, payload...)
return b
}
readPacketNumber := func(b []byte) protocol.PacketNumber {