Source File
value.go
Belonging Package
internal/trace
// 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 traceimport ()// Value is a dynamically-typed value obtained from a trace.type Value struct {kind ValueKindpointer unsafe.Pointerscalar uint64}// ValueKind is the type of a dynamically-typed value from a trace.type ValueKind uint8const (ValueBad ValueKind = iotaValueUint64ValueString)// Kind returns the ValueKind of the value.//// It represents the underlying structure of the value.//// New ValueKinds may be added in the future. Users of this type must be robust// to that possibility.func ( Value) () ValueKind {return .kind}// Uint64 returns the uint64 value for a ValueUint64.//// Panics if this Value's Kind is not ValueUint64.func ( Value) () uint64 {if .kind != ValueUint64 {panic("Uint64 called on Value of a different Kind")}return .scalar}// String returns the string value for a ValueString, and otherwise// a string representation of the value for other kinds of values.func ( Value) () string {if .kind == ValueString {return unsafe.String((*byte)(.pointer), int(.scalar))}switch .kind {case ValueUint64:return fmt.Sprintf("Value{Uint64(%d)}", .Uint64())}return "Value{Bad}"}func uint64Value( uint64) Value {return Value{kind: ValueUint64, scalar: }}func stringValue( string) Value {return Value{kind: ValueString, scalar: uint64(len()), pointer: unsafe.Pointer(unsafe.StringData())}}
![]() |
The pages are generated with Golds v0.7.9-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. |