rawhelpers.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. package internal
  15. import (
  16. "math"
  17. "unsafe"
  18. )
  19. func BoolToRaw(b bool) uint64 {
  20. if b {
  21. return 1
  22. }
  23. return 0
  24. }
  25. func RawToBool(r uint64) bool {
  26. return r != 0
  27. }
  28. func Int64ToRaw(i int64) uint64 {
  29. return uint64(i)
  30. }
  31. func RawToInt64(r uint64) int64 {
  32. return int64(r)
  33. }
  34. func Float64ToRaw(f float64) uint64 {
  35. return math.Float64bits(f)
  36. }
  37. func RawToFloat64(r uint64) float64 {
  38. return math.Float64frombits(r)
  39. }
  40. func RawPtrToFloat64Ptr(r *uint64) *float64 {
  41. return (*float64)(unsafe.Pointer(r))
  42. }
  43. func RawPtrToInt64Ptr(r *uint64) *int64 {
  44. return (*int64)(unsafe.Pointer(r))
  45. }