// Copyright 2023 The Go Authors. All rights reserved.// Use of this source code is governed by a BSD-style// license that can be found in the LICENSE file.package rawimport ()// Writer emits the wire format of a trace.//// It may not produce a byte-for-byte compatible trace from what is// produced by the runtime, because it may be missing extra padding// in the LEB128 encoding that the runtime adds but isn't necessary// when you know the data up-front.typeWriterstruct { w io.Writer buf []byte v version.Version specs []event.Spec}// NewWriter creates a new byte format writer.func ( io.Writer, version.Version) (*Writer, error) { , := version.WriteHeader(, )return &Writer{w: , v: , specs: .Specs()}, }// WriteEvent writes a single event to the trace wire format stream.func ( *Writer) ( Event) error {// Check version.if .Version != .v {returnfmt.Errorf("mismatched version between writer (go 1.%d) and event (go 1.%d)", .v, .Version) }// Write event header byte. .buf = append(.buf, uint8(.Ev))// Write out all arguments. := .specs[.Ev]for , := range .Args[:len(.Args)] { .buf = binary.AppendUvarint(.buf, ) }if .IsStack { := .Args[len(.Args):]for := 0; < len(); ++ { .buf = binary.AppendUvarint(.buf, []) } }// Write out the length of the data.if .HasData { .buf = binary.AppendUvarint(.buf, uint64(len(.Data))) }// Write out varint events. , := .w.Write(.buf) .buf = .buf[:0]if != nil {return }// Write out data.if .HasData { , := .w.Write(.Data)return }returnnil}
The pages are generated with Goldsv0.7.0-preview. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.