-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
pb.go
31 lines (23 loc) · 868 Bytes
/
pb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
// 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
}