VictoriaMetrics/vendor/go.opentelemetry.io/collector/pdata/pmetric/pb.go
2023-09-07 12:35:42 +02:00

32 lines
868 B
Go

// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0
package pmetric // import "go.opentelemetry.io/collector/pdata/pmetric"
import (
"go.opentelemetry.io/collector/pdata/internal"
otlpmetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/metrics/v1"
)
var _ MarshalSizer = (*ProtoMarshaler)(nil)
type ProtoMarshaler struct{}
func (e *ProtoMarshaler) MarshalMetrics(md Metrics) ([]byte, error) {
pb := internal.MetricsToProto(internal.Metrics(md))
return pb.Marshal()
}
func (e *ProtoMarshaler) MetricsSize(md Metrics) int {
pb := internal.MetricsToProto(internal.Metrics(md))
return pb.Size()
}
type ProtoUnmarshaler struct{}
func (d *ProtoUnmarshaler) UnmarshalMetrics(buf []byte) (Metrics, error) {
pb := otlpmetrics.MetricsData{}
err := pb.Unmarshal(buf)
return Metrics(internal.MetricsFromProto(pb)), err
}