@@ -129,6 +129,8 @@ func (v Value) getState() *internal.State {
129
129
return internal .GetValueState (internal .Value (v ))
130
130
}
131
131
132
+ // FromRaw sets the value from the given raw value.
133
+ // Calling this function on zero-initialized Value will cause a panic.
132
134
func (v Value ) FromRaw (iv any ) error {
133
135
switch tv := iv .(type ) {
134
136
case nil :
@@ -198,37 +200,31 @@ func (v Value) Type() ValueType {
198
200
// Str returns the string value associated with this Value.
199
201
// The shorter name is used instead of String to avoid implementing fmt.Stringer interface.
200
202
// If the Type() is not ValueTypeStr then returns empty string.
201
- // Calling this function on zero-initialized Value will cause a panic.
202
203
func (v Value ) Str () string {
203
204
return v .getOrig ().GetStringValue ()
204
205
}
205
206
206
207
// Int returns the int64 value associated with this Value.
207
208
// If the Type() is not ValueTypeInt then returns int64(0).
208
- // Calling this function on zero-initialized Value will cause a panic.
209
209
func (v Value ) Int () int64 {
210
210
return v .getOrig ().GetIntValue ()
211
211
}
212
212
213
213
// Double returns the float64 value associated with this Value.
214
214
// If the Type() is not ValueTypeDouble then returns float64(0).
215
- // Calling this function on zero-initialized Value will cause a panic.
216
215
func (v Value ) Double () float64 {
217
216
return v .getOrig ().GetDoubleValue ()
218
217
}
219
218
220
219
// Bool returns the bool value associated with this Value.
221
220
// If the Type() is not ValueTypeBool then returns false.
222
- // Calling this function on zero-initialized Value will cause a panic.
223
221
func (v Value ) Bool () bool {
224
222
return v .getOrig ().GetBoolValue ()
225
223
}
226
224
227
225
// Map returns the map value associated with this Value.
228
- // If the Type() is not ValueTypeMap then returns an invalid map. Note that using
229
- // such map can cause panic.
230
- //
231
- // Calling this function on zero-initialized Value will cause a panic.
226
+ // If the function is called on zero-initialized Value or if the Type() is not ValueTypeMap
227
+ // then it returns an invalid map. Note that using such map can cause panic.
232
228
func (v Value ) Map () Map {
233
229
kvlist := v .getOrig ().GetKvlistValue ()
234
230
if kvlist == nil {
@@ -238,10 +234,8 @@ func (v Value) Map() Map {
238
234
}
239
235
240
236
// Slice returns the slice value associated with this Value.
241
- // If the Type() is not ValueTypeSlice then returns an invalid slice. Note that using
242
- // such slice can cause panic.
243
- //
244
- // Calling this function on zero-initialized Value will cause a panic.
237
+ // If the function is called on zero-initialized Value or if the Type() is not ValueTypeSlice
238
+ // then returns an invalid slice. Note that using such slice can cause panic.
245
239
func (v Value ) Slice () Slice {
246
240
arr := v .getOrig ().GetArrayValue ()
247
241
if arr == nil {
@@ -251,10 +245,8 @@ func (v Value) Slice() Slice {
251
245
}
252
246
253
247
// Bytes returns the ByteSlice value associated with this Value.
254
- // If the Type() is not ValueTypeBytes then returns an invalid ByteSlice object. Note that using
255
- // such slice can cause panic.
256
- //
257
- // Calling this function on zero-initialized Value will cause a panic.
248
+ // If the function is called on zero-initialized Value or if the Type() is not ValueTypeBytes
249
+ // then returns an invalid ByteSlice object. Note that using such slice can cause panic.
258
250
func (v Value ) Bytes () ByteSlice {
259
251
bv , ok := v .getOrig ().GetValue ().(* otlpcommon.AnyValue_BytesValue )
260
252
if ! ok {
@@ -325,6 +317,7 @@ func (v Value) SetEmptySlice() Slice {
325
317
}
326
318
327
319
// CopyTo copies the Value instance overriding the destination.
320
+ // Calling this function on zero-initialized Value will cause a panic.
328
321
func (v Value ) CopyTo (dest Value ) {
329
322
dest .getState ().AssertMutable ()
330
323
destOrig := dest .getOrig ()
@@ -370,6 +363,7 @@ func (v Value) CopyTo(dest Value) {
370
363
// AsString converts an OTLP Value object of any type to its equivalent string
371
364
// representation. This differs from Str which only returns a non-empty value
372
365
// if the ValueType is ValueTypeStr.
366
+ // Calling this function on zero-initialized Value will cause a panic.
373
367
func (v Value ) AsString () string {
374
368
switch v .Type () {
375
369
case ValueTypeEmpty :
0 commit comments