github.com/ooni/psiphon/tunnel-core@v0.0.0-20230105123940-fe12a24c96ee/oovendor/quic-go/internal/logutils/frame.go (about)

     1  package logutils
     2  
     3  import (
     4  	"github.com/ooni/psiphon/tunnel-core/oovendor/quic-go/internal/protocol"
     5  	"github.com/ooni/psiphon/tunnel-core/oovendor/quic-go/internal/wire"
     6  	"github.com/ooni/psiphon/tunnel-core/oovendor/quic-go/logging"
     7  )
     8  
     9  // ConvertFrame converts a wire.Frame into a logging.Frame.
    10  // This makes it possible for external packages to access the frames.
    11  // Furthermore, it removes the data slices from CRYPTO and STREAM frames.
    12  func ConvertFrame(frame wire.Frame) logging.Frame {
    13  	switch f := frame.(type) {
    14  	case *wire.CryptoFrame:
    15  		return &logging.CryptoFrame{
    16  			Offset: f.Offset,
    17  			Length: protocol.ByteCount(len(f.Data)),
    18  		}
    19  	case *wire.StreamFrame:
    20  		return &logging.StreamFrame{
    21  			StreamID: f.StreamID,
    22  			Offset:   f.Offset,
    23  			Length:   f.DataLen(),
    24  			Fin:      f.Fin,
    25  		}
    26  	case *wire.DatagramFrame:
    27  		return &logging.DatagramFrame{
    28  			Length: logging.ByteCount(len(f.Data)),
    29  		}
    30  	default:
    31  		return logging.Frame(frame)
    32  	}
    33  }