Debian Codegraph @

trace/value.go

raw symbols SCIP
1 // Copyright 2023 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 // Code generated by "gen.bash" from internal/trace; DO NOT EDIT.
6
7 //go:build go1.23
8
9 package trace
10
11 import (
12 "fmt"
13 "unsafe"
14 )
15
16 // Value is a dynamically-typed value obtained from a trace.
17 type Value struct {
18 kind ValueKind
19 pointer unsafe.Pointer
20 scalar uint64
21 }
22
23 // ValueKind is the type of a dynamically-typed value from a trace.
24 type ValueKind uint8
25
26 const (
27 ValueBad ValueKind = iota
28 ValueUint64
29 ValueString
30 )
31
32 // Kind returns the ValueKind of the value.
33 //
34 // It represents the underlying structure of the value.
35 //
36 // New ValueKinds may be added in the future. Users of this type must be robust
37 // to that possibility.
38 func (v Value) Kind() ValueKind {
39 return v.kind
40 }
41
42 // Uint64 returns the uint64 value for a ValueUint64.
43 //
44 // Panics if this Value's Kind is not ValueUint64.
45 func (v Value) Uint64() uint64 {
46 if v.kind != ValueUint64 {
47 panic("Uint64 called on Value of a different Kind")
48 }
49 return v.scalar
50 }
51
52 // String returns the string value for a ValueString, and otherwise
53 // a string representation of the value for other kinds of values.
54 func (v Value) String() string {
55 if v.kind == ValueString {
56 return unsafe.String((*byte)(v.pointer), int(v.scalar))
57 }
58 switch v.kind {
59 case ValueUint64:
60 return fmt.Sprintf("Value{Uint64(%d)}", v.Uint64())
61 }
62 return "Value{Bad}"
63 }
64
65 // Uint64Value creates a value of kind ValueUint64.
66 func Uint64Value(x uint64) Value {
67 return Value{kind: ValueUint64, scalar: x}
68 }
69
70 // StringValue creates a value of kind ValueString.
71 func StringValue(s string) Value {
72 return Value{kind: ValueString, scalar: uint64(len(s)), pointer: unsafe.Pointer(unsafe.StringData(s))}
73 }