Skip to content

Commit

Permalink
[pdata] Expose pcommon.Value.AsRaw/FromRaw methods (#6092)
Browse files Browse the repository at this point in the history
  • Loading branch information
dmitryax authored Sep 15, 2022
1 parent 3b334e5 commit 4cf5f82
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
- Delete deprecated `config.Unmarshalable` interface. (#6084)
- Delete deprecated `p[metric|log|trace].MarshalerSizer` interfaces (#6083)

### 💡 Enhancements 💡

- Expose `AsRaw` and `FromRaw` `pcommon.Value` methods (#6090)

## v0.60.0 Beta

### 🛑 Breaking changes 🛑
Expand Down
12 changes: 6 additions & 6 deletions pdata/pcommon/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (v Value) getOrig() *otlpcommon.AnyValue {
return internal.GetOrigValue(internal.Value(v))
}

func (v Value) fromRaw(iv interface{}) {
func (v Value) FromRaw(iv interface{}) {
switch tv := iv.(type) {
case nil:
v.getOrig().Value = nil
Expand Down Expand Up @@ -504,7 +504,7 @@ func float64AsString(f float64) string {
return string(b)
}

func (v Value) asRaw() interface{} {
func (v Value) AsRaw() interface{} {
switch v.Type() {
case ValueTypeEmpty:
return nil
Expand Down Expand Up @@ -1019,7 +1019,7 @@ func (m Map) CopyTo(dest Map) {
func (m Map) AsRaw() map[string]interface{} {
rawMap := make(map[string]interface{})
m.Range(func(k string, v Value) bool {
rawMap[k] = v.asRaw()
rawMap[k] = v.AsRaw()
return true
})
return rawMap
Expand All @@ -1035,7 +1035,7 @@ func (m Map) FromRaw(rawMap map[string]interface{}) {
ix := 0
for k, iv := range rawMap {
origs[ix].Key = k
newValue(&origs[ix].Value).fromRaw(iv)
newValue(&origs[ix].Value).FromRaw(iv)
ix++
}
*m.getOrig() = origs
Expand All @@ -1053,7 +1053,7 @@ func NewSliceFromRaw(rawSlice []interface{}) 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())
rawSlice = append(rawSlice, es.At(i).AsRaw())
}
return rawSlice
}
Expand All @@ -1066,7 +1066,7 @@ func (es Slice) FromRaw(rawSlice []interface{}) {
}
origs := make([]otlpcommon.AnyValue, len(rawSlice))
for ix, iv := range rawSlice {
newValue(&origs[ix]).fromRaw(iv)
newValue(&origs[ix]).FromRaw(iv)
}
*es.getOrig() = origs
}
Expand Down
6 changes: 3 additions & 3 deletions pdata/pcommon/common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,7 @@ func TestMap_Range(t *testing.T) {
assert.Equal(t, 1, calls)

am.Range(func(k string, v Value) bool {
assert.Equal(t, rawMap[k], v.asRaw())
assert.Equal(t, rawMap[k], v.AsRaw())
delete(rawMap, k)
return true
})
Expand Down Expand Up @@ -1047,7 +1047,7 @@ func TestValueAsRaw(t *testing.T) {
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
actual := test.input.asRaw()
actual := test.input.AsRaw()
assert.Equal(t, test.expected, actual)
})
}
Expand Down Expand Up @@ -1206,7 +1206,7 @@ func TestNewValueFromRaw(t *testing.T) {
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := NewValueEmpty()
actual.fromRaw(tt.input)
actual.FromRaw(tt.input)
assert.Equal(t, tt.expected, actual)
})
}
Expand Down

0 comments on commit 4cf5f82

Please sign in to comment.