MCPcopy
hub / github.com/grafana/tempo / EncodeToString

Method EncodeToString

pkg/traceql/ast_stringer.go:87–136  ·  view source on GitHub ↗
(quotes bool)

Source from the content-addressed store, hash-verified

85}
86
87func (s Static) EncodeToString(quotes bool) string {
88 switch s.Type {
89 case TypeNil:
90 return "nil"
91 case TypeInt:
92 i, _ := s.Int()
93 return strconv.Itoa(i)
94 case TypeFloat:
95 f := strconv.FormatFloat(s.Float(), 'g', -1, 64)
96 // if the float string doesn't contain e or ., then append .0 to distinguish it from an int
97 if !strings.ContainsAny(f, "e.") {
98 f += ".0"
99 }
100 return f
101 case TypeString:
102 var str string
103 if len(s.valBytes) > 0 {
104 str = unsafe.String(unsafe.SliceData(s.valBytes), len(s.valBytes))
105 }
106 if quotes {
107 return "`" + str + "`"
108 }
109 return str
110 case TypeBoolean:
111 b, _ := s.Bool()
112 return strconv.FormatBool(b)
113 case TypeDuration:
114 d, _ := s.Duration()
115 return d.String()
116 case TypeStatus:
117 st, _ := s.Status()
118 return st.String()
119 case TypeKind:
120 k, _ := s.Kind()
121 return k.String()
122 case TypeIntArray:
123 ints, _ := s.IntArray()
124 return arrayToString(ints, false)
125 case TypeFloatArray:
126 floats, _ := s.FloatArray()
127 return arrayToString(floats, false)
128 case TypeStringArray:
129 return arrayToString(s.valStrings, true)
130 case TypeBooleanArray:
131 booleans, _ := s.BooleanArray()
132 return arrayToString(booleans, false)
133 default:
134 return fmt.Sprintf("static(%d)", s.Type)
135 }
136}
137
138func arrayToString[T any](array []T, quoted bool) string {
139 tmpl := "%v"

Callers 15

AsAnyValueMethod · 0.95
appendMethod · 0.95
StringMethod · 0.95
FindMethod · 0.80
RedactBlockMethod · 0.80
createStringPredicateFunction · 0.80
createBytesPredicateFunction · 0.80
createIntPredicateFunction · 0.80
createFloatPredicateFunction · 0.80
createBoolPredicateFunction · 0.80
SearchTagValuesMethod · 0.80

Calls 11

IntMethod · 0.95
FloatMethod · 0.95
BoolMethod · 0.95
DurationMethod · 0.95
StatusMethod · 0.95
KindMethod · 0.95
IntArrayMethod · 0.95
FloatArrayMethod · 0.95
BooleanArrayMethod · 0.95
arrayToStringFunction · 0.85
StringMethod · 0.45