qlog: implement a minimal jsontext-like JSON encoder (#5353)

* qlog: use fork of encoding/json/jsontext instead of unmaintained gojay

* implement a minimal jsontext-compatible encoder

* qlogtext: improve fuzz test

* qlog: simplify JSON encoding error handling

* qlog: make use of jsontext.Bool
This commit is contained in:
Marten Seemann
2025-10-06 12:48:40 +08:00
committed by GitHub
parent 7c1ce0efe2
commit e6d5d960e3
14 changed files with 1714 additions and 637 deletions

View File

@@ -5,10 +5,12 @@ import (
"encoding/json"
"testing"
"github.com/francoispqt/gojay"
"github.com/quic-go/quic-go/internal/protocol"
"github.com/quic-go/quic-go/internal/wire"
"github.com/quic-go/quic-go/logging"
"github.com/quic-go/quic-go/qlog/jsontext"
"github.com/stretchr/testify/require"
)
@@ -34,8 +36,8 @@ func TestPacketTypeFromEncryptionLevel(t *testing.T) {
func checkHeader(t *testing.T, hdr *wire.ExtendedHeader, expected map[string]any) {
buf := &bytes.Buffer{}
enc := gojay.NewEncoder(buf)
require.NoError(t, enc.Encode(transformLongHeader(hdr)))
enc := jsontext.NewEncoder(buf)
require.NoError(t, transformLongHeader(hdr).Encode(enc))
data := buf.Bytes()
require.True(t, json.Valid(data))
checkEncoding(t, data, expected)