github.com/tumi8/quic-go@v0.37.4-tum/qlog/trace.go (about) 1 package qlog 2 3 import ( 4 "time" 5 6 "github.com/tumi8/quic-go/logging" 7 "github.com/tumi8/quic-go/noninternal/protocol" 8 "github.com/francoispqt/gojay" 9 10 ) 11 12 type topLevel struct { 13 trace trace 14 } 15 16 func (topLevel) IsNil() bool { return false } 17 func (l topLevel) MarshalJSONObject(enc *gojay.Encoder) { 18 enc.StringKey("qlog_format", "NDJSON") 19 enc.StringKey("qlog_version", "draft-02") 20 enc.StringKeyOmitEmpty("title", "quic-go qlog") 21 enc.ObjectKey("configuration", configuration{Version: quicGoVersion}) 22 enc.ObjectKey("trace", l.trace) 23 } 24 25 type configuration struct { 26 Version string 27 } 28 29 func (c configuration) IsNil() bool { return false } 30 func (c configuration) MarshalJSONObject(enc *gojay.Encoder) { 31 enc.StringKey("code_version", c.Version) 32 } 33 34 type vantagePoint struct { 35 Name string 36 Type protocol.Perspective 37 } 38 39 func (p vantagePoint) IsNil() bool { return false } 40 func (p vantagePoint) MarshalJSONObject(enc *gojay.Encoder) { 41 enc.StringKeyOmitEmpty("name", p.Name) 42 switch p.Type { 43 case protocol.PerspectiveClient: 44 enc.StringKey("type", "client") 45 case protocol.PerspectiveServer: 46 enc.StringKey("type", "server") 47 } 48 } 49 50 type commonFields struct { 51 ODCID logging.ConnectionID 52 GroupID logging.ConnectionID 53 ProtocolType string 54 ReferenceTime time.Time 55 } 56 57 func (f commonFields) MarshalJSONObject(enc *gojay.Encoder) { 58 enc.StringKey("ODCID", f.ODCID.String()) 59 enc.StringKey("group_id", f.ODCID.String()) 60 enc.StringKeyOmitEmpty("protocol_type", f.ProtocolType) 61 enc.Float64Key("reference_time", float64(f.ReferenceTime.UnixNano())/1e6) 62 enc.StringKey("time_format", "relative") 63 } 64 65 func (f commonFields) IsNil() bool { return false } 66 67 type trace struct { 68 VantagePoint vantagePoint 69 CommonFields commonFields 70 } 71 72 func (trace) IsNil() bool { return false } 73 func (t trace) MarshalJSONObject(enc *gojay.Encoder) { 74 enc.ObjectKey("vantage_point", t.VantagePoint) 75 enc.ObjectKey("common_fields", t.CommonFields) 76 }