2020-03-24 07:41:10 +02:00
|
|
|
// 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.
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
package internal
|
2019-10-31 00:01:19 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"math"
|
|
|
|
"unsafe"
|
|
|
|
)
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func BoolToRaw(b bool) uint64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
if b {
|
|
|
|
return 1
|
|
|
|
}
|
|
|
|
return 0
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func RawToBool(r uint64) bool {
|
2019-10-31 00:01:19 +02:00
|
|
|
return r != 0
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func Int64ToRaw(i int64) uint64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return uint64(i)
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func RawToInt64(r uint64) int64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return int64(r)
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func Uint64ToRaw(u uint64) uint64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return u
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func RawToUint64(r uint64) uint64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return r
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func Float64ToRaw(f float64) uint64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return math.Float64bits(f)
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func RawToFloat64(r uint64) float64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return math.Float64frombits(r)
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func Int32ToRaw(i int32) uint64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return uint64(i)
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func RawToInt32(r uint64) int32 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return int32(r)
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func Uint32ToRaw(u uint32) uint64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return uint64(u)
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func RawToUint32(r uint64) uint32 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return uint32(r)
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func Float32ToRaw(f float32) uint64 {
|
|
|
|
return Uint32ToRaw(math.Float32bits(f))
|
2019-10-31 00:01:19 +02:00
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func RawToFloat32(r uint64) float32 {
|
|
|
|
return math.Float32frombits(RawToUint32(r))
|
2019-10-31 00:01:19 +02:00
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func RawPtrToFloat64Ptr(r *uint64) *float64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return (*float64)(unsafe.Pointer(r))
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func RawPtrToInt64Ptr(r *uint64) *int64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return (*int64)(unsafe.Pointer(r))
|
|
|
|
}
|
|
|
|
|
2020-05-11 08:44:42 +02:00
|
|
|
func RawPtrToUint64Ptr(r *uint64) *uint64 {
|
2019-10-31 00:01:19 +02:00
|
|
|
return r
|
|
|
|
}
|