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
18 changed files with 282 additions and 279 deletions

View File

@@ -64,8 +64,8 @@ func Fuzz(data []byte) int {
if hdr.Length > 16383 {
return 1
}
b := &bytes.Buffer{}
if err := extHdr.Write(b, version); err != nil {
b, err := extHdr.Append(nil, version)
if err != nil {
// We are able to parse packets with connection IDs longer than 20 bytes,
// but in QUIC version 1, we don't write headers with longer connection IDs.
if hdr.DestConnectionID.Len() <= protocol.MaxConnIDLen &&
@@ -76,8 +76,8 @@ func Fuzz(data []byte) int {
}
// GetLength is not implemented for Retry packets
if hdr.Type != protocol.PacketTypeRetry {
if expLen := extHdr.GetLength(version); expLen != protocol.ByteCount(b.Len()) {
panic(fmt.Sprintf("inconsistent header length: %#v. Expected %d, got %d", extHdr, expLen, b.Len()))
if expLen := extHdr.GetLength(version); expLen != protocol.ByteCount(len(b)) {
panic(fmt.Sprintf("inconsistent header length: %#v. Expected %d, got %d", extHdr, expLen, len(b)))
}
}
return 1