Skip to content

Commit

Permalink
[pdata] Make Slice.AsRaw() method exported (#5311)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax authored May 10, 2022
1 parent 781b97c commit 79911de
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

### 💡 Enhancements 💡

- `pdata`: Expose `pcommon.NewSliceFromRay` and `pcommon.Slice.AsRaw` functions (#5298)

### 🧰 Bug fixes 🧰

- Fix Windows Event Logs ignoring user-specified logging options (#5298)
Expand Down
14 changes: 7 additions & 7 deletions pdata/internal/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func newValueFromRaw(iv interface{}) Value {
return mv
case []interface{}:
av := NewValueSlice()
newSliceFromRaw(tv).CopyTo(av.SliceVal())
NewSliceFromRaw(tv).CopyTo(av.SliceVal())
return av
default:
return NewValueString(fmt.Sprintf("<Invalid value type %T>", tv))
Expand Down Expand Up @@ -448,7 +448,7 @@ func (v Value) AsString() string {
return base64.StdEncoding.EncodeToString(v.BytesVal())

case ValueTypeSlice:
jsonStr, _ := json.Marshal(v.SliceVal().asRaw())
jsonStr, _ := json.Marshal(v.SliceVal().AsRaw())
return string(jsonStr)

default:
Expand Down Expand Up @@ -504,7 +504,7 @@ func (v Value) asRaw() interface{} {
case ValueTypeMap:
return v.MapVal().AsRaw()
case ValueTypeSlice:
return v.SliceVal().asRaw()
return v.SliceVal().AsRaw()
}
return fmt.Sprintf("<Unknown OpenTelemetry value type %q>", v.Type())
}
Expand Down Expand Up @@ -914,8 +914,8 @@ func (m Map) AsRaw() map[string]interface{} {
return rawMap
}

// newSliceFromRaw creates a Slice with values from the given []interface{}.
func newSliceFromRaw(rawSlice []interface{}) Slice {
// NewSliceFromRaw creates a Slice with values from the given []interface{}.
func NewSliceFromRaw(rawSlice []interface{}) Slice {
if len(rawSlice) == 0 {
v := []otlpcommon.AnyValue(nil)
return Slice{&v}
Expand All @@ -927,8 +927,8 @@ func newSliceFromRaw(rawSlice []interface{}) Slice {
return Slice{&origs}
}

// asRaw creates a slice out of a Slice.
func (es Slice) asRaw() []interface{} {
// AsRaw converts the Slice to a standard go slice.
func (es Slice) AsRaw() []interface{} {
rawSlice := make([]interface{}, 0, es.Len())
for i := 0; i < es.Len(); i++ {
rawSlice = append(rawSlice, es.At(i).asRaw())
Expand Down
2 changes: 1 addition & 1 deletion pdata/internal/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ func TestNewValueFromRaw(t *testing.T) {
input: []interface{}{"v1", "v2"},
expected: (func() Value {
s := NewValueSlice()
newSliceFromRaw([]interface{}{"v1", "v2"}).CopyTo(s.SliceVal())
NewSliceFromRaw([]interface{}{"v1", "v2"}).CopyTo(s.SliceVal())
return s
})(),
},
Expand Down

0 comments on commit 79911de

Please sign in to comment.