1// Copyright The OpenTelemetry Authors 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15package internal 16 17import ( 18 "math" 19 "unsafe" 20) 21 22func BoolToRaw(b bool) uint64 { 23 if b { 24 return 1 25 } 26 return 0 27} 28 29func RawToBool(r uint64) bool { 30 return r != 0 31} 32 33func Int64ToRaw(i int64) uint64 { 34 return uint64(i) 35} 36 37func RawToInt64(r uint64) int64 { 38 return int64(r) 39} 40 41func Float64ToRaw(f float64) uint64 { 42 return math.Float64bits(f) 43} 44 45func RawToFloat64(r uint64) float64 { 46 return math.Float64frombits(r) 47} 48 49func RawPtrToFloat64Ptr(r *uint64) *float64 { 50 return (*float64)(unsafe.Pointer(r)) 51} 52 53func RawPtrToInt64Ptr(r *uint64) *int64 { 54 return (*int64)(unsafe.Pointer(r)) 55} 56