Copyright The OpenTelemetry Authors Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

package label

import (
	
	
	
	
	
	

	
)
go:generate stringer -type=Type
Type describes the type of the data Value holds.
type Type int
Value represents the value part in key-value pairs.
type Value struct {
	vtype    Type
	numeric  uint64
TODO Lazy value type?

	array interface{}
}

const (
	INVALID Type = iota // No value.
	BOOL                // Boolean value, use AsBool() to get it.
	INT32               // 32 bit signed integral value, use AsInt32() to get it.
	INT64               // 64 bit signed integral value, use AsInt64() to get it.
	UINT32              // 32 bit unsigned integral value, use AsUint32() to get it.
	UINT64              // 64 bit unsigned integral value, use AsUint64() to get it.
	FLOAT32             // 32 bit floating point value, use AsFloat32() to get it.
	FLOAT64             // 64 bit floating point value, use AsFloat64() to get it.
	STRING              // String value, use AsString() to get it.
	ARRAY               // Array value of arbitrary type, use AsArray() to get it.
)
BoolValue creates a BOOL Value.
func ( bool) Value {
	return Value{
		vtype:   BOOL,
		numeric: internal.BoolToRaw(),
	}
}
Int64Value creates an INT64 Value.
Uint64Value creates a UINT64 Value.
Float64Value creates a FLOAT64 Value.
Int32Value creates an INT32 Value.
Uint32 creates a UINT32 Value.
Float32 creates a FLOAT32 Value.
String creates a STRING Value.
func ( string) Value {
	return Value{
		vtype:    STRING,
		stringly: ,
	}
}
Int creates either an INT32 or an INT64 Value, depending on whether the int type is 32 or 64 bits wide.
func ( int) Value {
	if unsafe.Sizeof() == 4 {
		return Int32Value(int32())
	}
	return Int64Value(int64())
}
Uint creates either a UINT32 or a UINT64 Value, depending on whether the uint type is 32 or 64 bits wide.
func ( uint) Value {
	if unsafe.Sizeof() == 4 {
		return Uint32Value(uint32())
	}
	return Uint64Value(uint64())
}
Array creates an ARRAY value.
func ( interface{}) Value {
	switch reflect.TypeOf().Kind() {
	case reflect.Array, reflect.Slice:
get array type regardless of dimensions
			 := reflect.TypeOf().String()
			 = [strings.LastIndex(, "]")+1:]
			switch  {
			case "bool", "int", "int32", "int64",
				"float32", "float64", "string",
				"uint", "uint32", "uint64":
				return true
			}
			return false
		}()
		if  {
			return Value{
				vtype: ARRAY,
				array: ,
			}
		}
	}
	return Value{vtype: INVALID}
}
Type returns a type of the Value.
func ( Value) () Type {
	return .vtype
}
AsBool returns the bool value. Make sure that the Value's type is BOOL.
func ( Value) () bool {
	return internal.RawToBool(.numeric)
}
AsInt32 returns the int32 value. Make sure that the Value's type is INT32.
func ( Value) () int32 {
	return internal.RawToInt32(.numeric)
}
AsInt64 returns the int64 value. Make sure that the Value's type is INT64.
func ( Value) () int64 {
	return internal.RawToInt64(.numeric)
}
AsUint32 returns the uint32 value. Make sure that the Value's type is UINT32.
func ( Value) () uint32 {
	return internal.RawToUint32(.numeric)
}
AsUint64 returns the uint64 value. Make sure that the Value's type is UINT64.
func ( Value) () uint64 {
	return internal.RawToUint64(.numeric)
}
AsFloat32 returns the float32 value. Make sure that the Value's type is FLOAT32.
AsFloat64 returns the float64 value. Make sure that the Value's type is FLOAT64.
AsString returns the string value. Make sure that the Value's type is STRING.
func ( Value) () string {
	return .stringly
}
AsArray returns the array Value as an interface{}.
func ( Value) () interface{} {
	return .array
}

type unknownValueType struct{}
AsInterface returns Value's data as interface{}.
func ( Value) () interface{} {
	switch .Type() {
	case ARRAY:
		return .AsArray()
	case BOOL:
		return .AsBool()
	case INT32:
		return .AsInt32()
	case INT64:
		return .AsInt64()
	case UINT32:
		return .AsUint32()
	case UINT64:
		return .AsUint64()
	case FLOAT32:
		return .AsFloat32()
	case FLOAT64:
		return .AsFloat64()
	case STRING:
		return .stringly
	}
	return unknownValueType{}
}
Emit returns a string representation of Value's data.
func ( Value) () string {
	switch .Type() {
	case ARRAY:
		return fmt.Sprint(.array)
	case BOOL:
		return strconv.FormatBool(.AsBool())
	case INT32:
		return strconv.FormatInt(int64(.AsInt32()), 10)
	case INT64:
		return strconv.FormatInt(.AsInt64(), 10)
	case UINT32:
		return strconv.FormatUint(uint64(.AsUint32()), 10)
	case UINT64:
		return strconv.FormatUint(.AsUint64(), 10)
	case FLOAT32:
		return fmt.Sprint(.AsFloat32())
	case FLOAT64:
		return fmt.Sprint(.AsFloat64())
	case STRING:
		return .stringly
	default:
		return "unknown"
	}
}
MarshalJSON returns the JSON encoding of the Value.
func ( Value) () ([]byte, error) {
	var  struct {
		  string
		 interface{}
	}
	. = .Type().String()
	. = .AsInterface()
	return json.Marshal()