| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile" |
| 5 |
|
| 6 |
import "fmt" |
| 7 |
|
| 8 |
// Equal checks equality with another KeyValueAndUnit |
| 9 |
// It assumes both structs refer to the same dictionary. |
| 10 |
func (ms KeyValueAndUnit) Equal(val KeyValueAndUnit) bool { |
| 11 |
return ms.KeyStrindex() == val.KeyStrindex() && |
| 12 |
ms.UnitStrindex() == val.UnitStrindex() && |
| 13 |
ms.Value().Equal(val.Value()) |
| 14 |
} |
| 15 |
|
| 16 |
// switchDictionary updates the KeyValueAndUnit, switching its indices from one |
| 17 |
// dictionary to another. |
| 18 |
func (ms KeyValueAndUnit) switchDictionary(src, dst ProfilesDictionary) error { |
| 19 |
if ms.KeyStrindex() > 0 { |
| 20 |
if src.StringTable().Len() < int(ms.KeyStrindex()) { |
| 21 |
return fmt.Errorf("invalid key index %d", ms.KeyStrindex()) |
| 22 |
} |
| 23 |
|
| 24 |
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(ms.KeyStrindex()))) |
| 25 |
if err != nil { |
| 26 |
return fmt.Errorf("couldn't set key: %w", err) |
| 27 |
} |
| 28 |
ms.SetKeyStrindex(idx) |
| 29 |
} |
| 30 |
|
| 31 |
if ms.UnitStrindex() > 0 { |
| 32 |
if src.StringTable().Len() < int(ms.UnitStrindex()) { |
| 33 |
return fmt.Errorf("invalid unit index %d", ms.UnitStrindex()) |
| 34 |
} |
| 35 |
|
| 36 |
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(ms.UnitStrindex()))) |
| 37 |
if err != nil { |
| 38 |
return fmt.Errorf("couldn't set unit: %w", err) |
| 39 |
} |
| 40 |
ms.SetUnitStrindex(idx) |
| 41 |
} |
| 42 |
|
| 43 |
return nil |
| 44 |
} |