Skip to content

Commit cc43e01

Browse files
igrucciMrAlias
andauthored
chore: move functionality from internal/rawhelpers.go to attribute (#6578)
Resolve #6524 --------- Signed-off-by: igrucci <[email protected]> Co-authored-by: Tyler Yahn <[email protected]> Co-authored-by: Tyler Yahn <[email protected]>
1 parent a486ca5 commit cc43e01

File tree

4 files changed

+44
-56
lines changed

4 files changed

+44
-56
lines changed

attribute/rawhelpers.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
}

attribute/value.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010
"strconv"
1111

1212
attribute "go.opentelemetry.io/otel/attribute/internal"
13-
"go.opentelemetry.io/otel/internal"
1413
)
1514

1615
//go:generate stringer -type=Type
@@ -51,7 +50,7 @@ const (
5150
func BoolValue(v bool) Value {
5251
return Value{
5352
vtype: BOOL,
54-
numeric: internal.BoolToRaw(v),
53+
numeric: boolToRaw(v),
5554
}
5655
}
5756

@@ -82,7 +81,7 @@ func IntSliceValue(v []int) Value {
8281
func Int64Value(v int64) Value {
8382
return Value{
8483
vtype: INT64,
85-
numeric: internal.Int64ToRaw(v),
84+
numeric: int64ToRaw(v),
8685
}
8786
}
8887

@@ -95,7 +94,7 @@ func Int64SliceValue(v []int64) Value {
9594
func Float64Value(v float64) Value {
9695
return Value{
9796
vtype: FLOAT64,
98-
numeric: internal.Float64ToRaw(v),
97+
numeric: float64ToRaw(v),
9998
}
10099
}
101100

@@ -125,7 +124,7 @@ func (v Value) Type() Type {
125124
// AsBool returns the bool value. Make sure that the Value's type is
126125
// BOOL.
127126
func (v Value) AsBool() bool {
128-
return internal.RawToBool(v.numeric)
127+
return rawToBool(v.numeric)
129128
}
130129

131130
// AsBoolSlice returns the []bool value. Make sure that the Value's type is
@@ -144,7 +143,7 @@ func (v Value) asBoolSlice() []bool {
144143
// AsInt64 returns the int64 value. Make sure that the Value's type is
145144
// INT64.
146145
func (v Value) AsInt64() int64 {
147-
return internal.RawToInt64(v.numeric)
146+
return rawToInt64(v.numeric)
148147
}
149148

150149
// AsInt64Slice returns the []int64 value. Make sure that the Value's type is
@@ -163,7 +162,7 @@ func (v Value) asInt64Slice() []int64 {
163162
// AsFloat64 returns the float64 value. Make sure that the Value's
164163
// type is FLOAT64.
165164
func (v Value) AsFloat64() float64 {
166-
return internal.RawToFloat64(v.numeric)
165+
return rawToFloat64(v.numeric)
167166
}
168167

169168
// AsFloat64Slice returns the []float64 value. Make sure that the Value's type is

internal/gen.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright The OpenTelemetry Authors
22
// SPDX-License-Identifier: Apache-2.0
33

4+
// Package internal contains utility functions and internal implementations
45
package internal // import "go.opentelemetry.io/otel/internal"
56

67
//go:generate gotmpl --body=./shared/matchers/expectation.go.tmpl "--data={}" --out=matchers/expectation.go

internal/rawhelpers.go

Lines changed: 0 additions & 49 deletions
This file was deleted.

0 commit comments

Comments
 (0)