| Abhay Kumar | a2ae599 | 2025-11-10 14:02:24 +0000 | [diff] [blame^] | 1 | // Copyright The OpenTelemetry Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package attribute // import "go.opentelemetry.io/otel/attribute" |
| 5 | |
| 6 | import ( |
| 7 | "math" |
| 8 | ) |
| 9 | |
| 10 | func boolToRaw(b bool) uint64 { // nolint:revive // b is not a control flag. |
| 11 | if b { |
| 12 | return 1 |
| 13 | } |
| 14 | return 0 |
| 15 | } |
| 16 | |
| 17 | func rawToBool(r uint64) bool { |
| 18 | return r != 0 |
| 19 | } |
| 20 | |
| 21 | func int64ToRaw(i int64) uint64 { |
| 22 | // Assumes original was a valid int64 (overflow not checked). |
| 23 | return uint64(i) // nolint: gosec |
| 24 | } |
| 25 | |
| 26 | func rawToInt64(r uint64) int64 { |
| 27 | // Assumes original was a valid int64 (overflow not checked). |
| 28 | return int64(r) // nolint: gosec |
| 29 | } |
| 30 | |
| 31 | func float64ToRaw(f float64) uint64 { |
| 32 | return math.Float64bits(f) |
| 33 | } |
| 34 | |
| 35 | func rawToFloat64(r uint64) float64 { |
| 36 | return math.Float64frombits(r) |
| 37 | } |