| 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 |
// switchDictionary updates the ValueType, switching its indices from one |
| 9 |
// dictionary to another. |
| 10 |
func (ms ValueType) switchDictionary(src, dst ProfilesDictionary) error { |
| 11 |
if ms.TypeStrindex() > 0 { |
| 12 |
if src.StringTable().Len() < int(ms.TypeStrindex()) { |
| 13 |
return fmt.Errorf("invalid type index %d", ms.TypeStrindex()) |
| 14 |
} |
| 15 |
|
| 16 |
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(ms.TypeStrindex()))) |
| 17 |
if err != nil { |
| 18 |
return fmt.Errorf("couldn't set type: %w", err) |
| 19 |
} |
| 20 |
ms.SetTypeStrindex(idx) |
| 21 |
} |
| 22 |
|
| 23 |
if ms.UnitStrindex() > 0 { |
| 24 |
if src.StringTable().Len() < int(ms.UnitStrindex()) { |
| 25 |
return fmt.Errorf("invalid unit index %d", ms.UnitStrindex()) |
| 26 |
} |
| 27 |
|
| 28 |
idx, err := SetString(dst.StringTable(), src.StringTable().At(int(ms.UnitStrindex()))) |
| 29 |
if err != nil { |
| 30 |
return fmt.Errorf("couldn't set unit: %w", err) |
| 31 |
} |
| 32 |
ms.SetUnitStrindex(idx) |
| 33 |
} |
| 34 |
|
| 35 |
return nil |
| 36 |
} |