mirror of
https://github.com/hanzoai/telemetry.git
synced 2026-10-30 20:01:49 +00:00
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Fix off-by-one issue in dictionary lookups. <!-- Issue number if applicable --> #### Link to tracking issue Fixes # <!--Describe what testing was performed and which tests were added.--> #### Testing <!--Describe the documentation added.--> #### Documentation <!--Please delete paragraphs that you did not use before submitting.--> Signed-off-by: Florian Lehner <[email protected]>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
// Copyright The OpenTelemetry Authors
|
|
// SPDX-License-Identifier: Apache-2.0
|
|
|
|
package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"
|
|
|
|
import "fmt"
|
|
|
|
// Equal checks equality with another KeyValueAndUnit
|
|
// It assumes both structs refer to the same dictionary.
|
|
func (ms KeyValueAndUnit) Equal(val KeyValueAndUnit) bool {
|
|
return ms.KeyStrindex() == val.KeyStrindex() &&
|
|
ms.UnitStrindex() == val.UnitStrindex() &&
|
|
ms.Value().Equal(val.Value())
|
|
}
|
|
|
|
// switchDictionary updates the KeyValueAndUnit, switching its indices from one
|
|
// dictionary to another.
|
|
func (ms KeyValueAndUnit) switchDictionary(src, dst ProfilesDictionary) error {
|
|
if ms.KeyStrindex() > 0 {
|
|
if src.StringTable().Len() <= int(ms.KeyStrindex()) {
|
|
return fmt.Errorf("invalid key index %d", ms.KeyStrindex())
|
|
}
|
|
|
|
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(ms.KeyStrindex())))
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't set key: %w", err)
|
|
}
|
|
ms.SetKeyStrindex(idx)
|
|
}
|
|
|
|
if ms.UnitStrindex() > 0 {
|
|
if src.StringTable().Len() <= int(ms.UnitStrindex()) {
|
|
return fmt.Errorf("invalid unit index %d", ms.UnitStrindex())
|
|
}
|
|
|
|
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(ms.UnitStrindex())))
|
|
if err != nil {
|
|
return fmt.Errorf("couldn't set unit: %w", err)
|
|
}
|
|
ms.SetUnitStrindex(idx)
|
|
}
|
|
|
|
return nil
|
|
}
|