| 1 | // Copyright The OpenTelemetry Authors |
| 2 | // SPDX-License-Identifier: Apache-2.0 |
| 3 | |
| 4 | package sizer // import "go.opentelemetry.io/collector/exporter/exporterhelper/internal/sizer" |
| 5 | |
| 6 | import ( |
| 7 | math_bits "math/bits" |
| 8 | ) |
| 9 | |
| 10 | type protoDeltaSizer struct{} |
| 11 | |
| 12 | // DeltaSize() returns the delta size of a proto slice when a new item is added. |
| 13 | // Example: |
| 14 | // |
| 15 | // prevSize := proto1.Size() |
| 16 | // proto1.RepeatedField().AppendEmpty() = proto2 |
| 17 | // |
| 18 | // Then currSize of proto1 can be calculated as |
| 19 | // |
| 20 | // currSize := (prevSize + sizer.DeltaSize(proto2.Size())) |
| 21 | // |
| 22 | // This is derived from: |
| 23 | // - opentelemetry-collector/pdata/internal/data/protogen/metrics/v1/metrics.pb.go |
| 24 | // - opentelemetry-collector/pdata/internal/data/protogen/logs/v1/logs.pb.go |
| 25 | // - opentelemetry-collector/pdata/internal/data/protogen/traces/v1/traces.pb.go |
| 26 | // - opentelemetry-collector/pdata/internal/data/protogen/profiles/v1development/profiles.pb.go |
| 27 | // which is generated with gogo/protobuf. |
| 28 | func (s *protoDeltaSizer) DeltaSize(newItemSize int) int { |
| 29 | return 1 + newItemSize + sov(uint64(newItemSize)) |
| 30 | } |
| 31 | |
| 32 | func sov(x uint64) int { |
| 33 | return (math_bits.Len64(x|1) + 6) / 7 |
| 34 | } |