-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
pb.go
31 lines (23 loc) · 847 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 ptrace // import "go.opentelemetry.io/collector/pdata/ptrace"
import (
"go.opentelemetry.io/collector/pdata/internal"
otlptrace "go.opentelemetry.io/collector/pdata/internal/data/protogen/trace/v1"
)
var _ MarshalSizer = (*ProtoMarshaler)(nil)
type ProtoMarshaler struct{}
func (e *ProtoMarshaler) MarshalTraces(td Traces) ([]byte, error) {
pb := internal.TracesToProto(internal.Traces(td))
return pb.Marshal()
}
func (e *ProtoMarshaler) TracesSize(td Traces) int {
pb := internal.TracesToProto(internal.Traces(td))
return pb.Size()
}
type ProtoUnmarshaler struct{}
func (d *ProtoUnmarshaler) UnmarshalTraces(buf []byte) (Traces, error) {
pb := otlptrace.TracesData{}
err := pb.Unmarshal(buf)
return Traces(internal.TracesFromProto(pb)), err
}