blob: dae825ed8b9d7193e205d44e824067612ac79943 [file] [log] [blame]
Joey Armstrong5f51f2e2023-01-17 17:06:26 -05001// 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 Uint64ToRaw(u uint64) uint64 {
42 return u
43}
44
45func RawToUint64(r uint64) uint64 {
46 return r
47}
48
49func Float64ToRaw(f float64) uint64 {
50 return math.Float64bits(f)
51}
52
53func RawToFloat64(r uint64) float64 {
54 return math.Float64frombits(r)
55}
56
57func Int32ToRaw(i int32) uint64 {
58 return uint64(i)
59}
60
61func RawToInt32(r uint64) int32 {
62 return int32(r)
63}
64
65func Uint32ToRaw(u uint32) uint64 {
66 return uint64(u)
67}
68
69func RawToUint32(r uint64) uint32 {
70 return uint32(r)
71}
72
73func Float32ToRaw(f float32) uint64 {
74 return Uint32ToRaw(math.Float32bits(f))
75}
76
77func RawToFloat32(r uint64) float32 {
78 return math.Float32frombits(RawToUint32(r))
79}
80
81func RawPtrToFloat64Ptr(r *uint64) *float64 {
82 return (*float64)(unsafe.Pointer(r))
83}
84
85func RawPtrToInt64Ptr(r *uint64) *int64 {
86 return (*int64)(unsafe.Pointer(r))
87}
88
89func RawPtrToUint64Ptr(r *uint64) *uint64 {
90 return r
91}