github.com/shogo82148/std@v1.22.1-0.20240327122250-4e474527810c/internal/coverage/encodecounter/encode.go (about)

     1  // Copyright 2021 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package encodecounter
     6  
     7  import (
     8  	"github.com/shogo82148/std/bufio"
     9  	"github.com/shogo82148/std/internal/coverage"
    10  	"github.com/shogo82148/std/internal/coverage/stringtab"
    11  	"github.com/shogo82148/std/io"
    12  )
    13  
    14  type CoverageDataWriter struct {
    15  	stab    *stringtab.Writer
    16  	w       *bufio.Writer
    17  	csh     coverage.CounterSegmentHeader
    18  	tmp     []byte
    19  	cflavor coverage.CounterFlavor
    20  	segs    uint32
    21  	debug   bool
    22  }
    23  
    24  func NewCoverageDataWriter(w io.Writer, flav coverage.CounterFlavor) *CoverageDataWriter
    25  
    26  // CounterVisitor describes a helper object used during counter file
    27  // writing; when writing counter data files, clients pass a
    28  // CounterVisitor to the write/emit routines, then the expectation is
    29  // that the VisitFuncs method will then invoke the callback "f" with
    30  // data for each function to emit to the file.
    31  type CounterVisitor interface {
    32  	VisitFuncs(f CounterVisitorFn) error
    33  }
    34  
    35  // CounterVisitorFn describes a callback function invoked when writing
    36  // coverage counter data.
    37  type CounterVisitorFn func(pkid uint32, funcid uint32, counters []uint32) error
    38  
    39  // Write writes the contents of the count-data file to the writer
    40  // previously supplied to NewCoverageDataWriter. Returns an error
    41  // if something went wrong somewhere with the write.
    42  func (cfw *CoverageDataWriter) Write(metaFileHash [16]byte, args map[string]string, visitor CounterVisitor) error
    43  
    44  // AppendSegment appends a new segment to a counter data, with a new
    45  // args section followed by a payload of counter data clauses.
    46  func (cfw *CoverageDataWriter) AppendSegment(args map[string]string, visitor CounterVisitor) error