add logging aliases for frames, create a logging.STREAM and CRYPTO frame

This commit is contained in:
Marten Seemann
2020-07-02 15:59:33 +07:00
parent fea17a671b
commit ed120f670c
12 changed files with 300 additions and 184 deletions

View File

@@ -0,0 +1,29 @@
package logutils
import (
"github.com/lucas-clemente/quic-go/internal/protocol"
"github.com/lucas-clemente/quic-go/internal/wire"
"github.com/lucas-clemente/quic-go/logging"
)
// ConvertFrame converts a wire.Frame into a logging.Frame.
// This makes it possible for external packages to access the frames.
// Furthermore, it removes the data slices from CRYPTO and STREAM frames.
func ConvertFrame(frame wire.Frame) logging.Frame {
switch f := frame.(type) {
case *wire.CryptoFrame:
return &logging.CryptoFrame{
Offset: f.Offset,
Length: protocol.ByteCount(len(f.Data)),
}
case *wire.StreamFrame:
return &logging.StreamFrame{
StreamID: f.StreamID,
Offset: f.Offset,
Length: f.DataLen(),
Fin: f.Fin,
}
default:
return logging.Frame(frame)
}
}