...

Source file src/github.com/Microsoft/go-winio/pkg/etw/eventdata.go

Documentation: github.com/Microsoft/go-winio/pkg/etw

     1  //go:build windows
     2  // +build windows
     3  
     4  package etw
     5  
     6  import (
     7  	"bytes"
     8  	"encoding/binary"
     9  	"syscall"
    10  )
    11  
    12  // eventData maintains a buffer which builds up the data for an ETW event. It
    13  // needs to be paired with EventMetadata which describes the event.
    14  type eventData struct {
    15  	buffer bytes.Buffer
    16  }
    17  
    18  // toBytes returns the raw binary data containing the event data. The returned
    19  // value is not copied from the internal buffer, so it can be mutated by the
    20  // eventData object after it is returned.
    21  func (ed *eventData) toBytes() []byte {
    22  	return ed.buffer.Bytes()
    23  }
    24  
    25  // writeString appends a string, including the null terminator, to the buffer.
    26  func (ed *eventData) writeString(data string) {
    27  	_, _ = ed.buffer.WriteString(data)
    28  	_ = ed.buffer.WriteByte(0)
    29  }
    30  
    31  // writeInt8 appends a int8 to the buffer.
    32  func (ed *eventData) writeInt8(value int8) {
    33  	_ = ed.buffer.WriteByte(uint8(value))
    34  }
    35  
    36  // writeInt16 appends a int16 to the buffer.
    37  func (ed *eventData) writeInt16(value int16) {
    38  	_ = binary.Write(&ed.buffer, binary.LittleEndian, value)
    39  }
    40  
    41  // writeInt32 appends a int32 to the buffer.
    42  func (ed *eventData) writeInt32(value int32) {
    43  	_ = binary.Write(&ed.buffer, binary.LittleEndian, value)
    44  }
    45  
    46  // writeInt64 appends a int64 to the buffer.
    47  func (ed *eventData) writeInt64(value int64) {
    48  	_ = binary.Write(&ed.buffer, binary.LittleEndian, value)
    49  }
    50  
    51  // writeUint8 appends a uint8 to the buffer.
    52  func (ed *eventData) writeUint8(value uint8) {
    53  	_ = ed.buffer.WriteByte(value)
    54  }
    55  
    56  // writeUint16 appends a uint16 to the buffer.
    57  func (ed *eventData) writeUint16(value uint16) {
    58  	_ = binary.Write(&ed.buffer, binary.LittleEndian, value)
    59  }
    60  
    61  // writeUint32 appends a uint32 to the buffer.
    62  func (ed *eventData) writeUint32(value uint32) {
    63  	_ = binary.Write(&ed.buffer, binary.LittleEndian, value)
    64  }
    65  
    66  // writeUint64 appends a uint64 to the buffer.
    67  func (ed *eventData) writeUint64(value uint64) {
    68  	_ = binary.Write(&ed.buffer, binary.LittleEndian, value)
    69  }
    70  
    71  // writeFiletime appends a FILETIME to the buffer.
    72  func (ed *eventData) writeFiletime(value syscall.Filetime) {
    73  	_ = binary.Write(&ed.buffer, binary.LittleEndian, value)
    74  }
    75  

View as plain text