All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.opentelemetry.exporter.internal.otlp.metrics.ExponentialHistogramBucketsMarshaler Maven / Gradle / Ivy

There is a newer version: 1.44.1
Show newest version
/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.opentelemetry.exporter.internal.otlp.metrics;

import io.opentelemetry.exporter.internal.marshal.MarshalerUtil;
import io.opentelemetry.exporter.internal.marshal.MarshalerWithSize;
import io.opentelemetry.exporter.internal.marshal.Serializer;
import io.opentelemetry.proto.metrics.v1.internal.ExponentialHistogramDataPoint;
import io.opentelemetry.sdk.internal.PrimitiveLongList;
import io.opentelemetry.sdk.metrics.data.ExponentialHistogramBuckets;
import java.io.IOException;
import java.util.List;

/**
 * This class is internal and is hence not for public use. Its APIs are unstable and can change at
 * any time.
 */
public class ExponentialHistogramBucketsMarshaler extends MarshalerWithSize {
  private final int offset;
  private final List counts;

  static ExponentialHistogramBucketsMarshaler create(ExponentialHistogramBuckets buckets) {
    return new ExponentialHistogramBucketsMarshaler(buckets.getOffset(), buckets.getBucketCounts());
  }

  private ExponentialHistogramBucketsMarshaler(int offset, List counts) {
    super(calculateSize(offset, counts));
    this.offset = offset;
    this.counts = counts;
  }

  @Override
  protected void writeTo(Serializer output) throws IOException {
    output.serializeSInt32(ExponentialHistogramDataPoint.Buckets.OFFSET, offset);
    output.serializeRepeatedUInt64(
        ExponentialHistogramDataPoint.Buckets.BUCKET_COUNTS, PrimitiveLongList.toArray(counts));
  }

  private static int calculateSize(int offset, List counts) {
    int size = 0;
    size += MarshalerUtil.sizeSInt32(ExponentialHistogramDataPoint.Buckets.OFFSET, offset);
    size +=
        MarshalerUtil.sizeRepeatedUInt64(
            ExponentialHistogramDataPoint.Buckets.BUCKET_COUNTS, PrimitiveLongList.toArray(counts));
    return size;
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy