| 1 |
// Copyright The OpenTelemetry Authors |
| 2 |
// SPDX-License-Identifier: Apache-2.0 |
| 3 |
|
| 4 |
package ptrace // import "go.opentelemetry.io/collector/pdata/ptrace" |
| 5 |
|
| 6 |
var _ MarshalSizer = (*ProtoMarshaler)(nil) |
| 7 |
|
| 8 |
type ProtoMarshaler struct{} |
| 9 |
|
| 10 |
func (e *ProtoMarshaler) MarshalTraces(td Traces) ([]byte, error) { |
| 11 |
size := td.getOrig().SizeProto() |
| 12 |
buf := make([]byte, size) |
| 13 |
_ = td.getOrig().MarshalProto(buf) |
| 14 |
return buf, nil |
| 15 |
} |
| 16 |
|
| 17 |
func (e *ProtoMarshaler) TracesSize(td Traces) int { |
| 18 |
return td.getOrig().SizeProto() |
| 19 |
} |
| 20 |
|
| 21 |
func (e *ProtoMarshaler) ResourceSpansSize(td ResourceSpans) int { |
| 22 |
return td.orig.SizeProto() |
| 23 |
} |
| 24 |
|
| 25 |
func (e *ProtoMarshaler) ScopeSpansSize(td ScopeSpans) int { |
| 26 |
return td.orig.SizeProto() |
| 27 |
} |
| 28 |
|
| 29 |
func (e *ProtoMarshaler) SpanSize(td Span) int { |
| 30 |
return td.orig.SizeProto() |
| 31 |
} |
| 32 |
|
| 33 |
type ProtoUnmarshaler struct{} |
| 34 |
|
| 35 |
func (d *ProtoUnmarshaler) UnmarshalTraces(buf []byte) (Traces, error) { |
| 36 |
td := NewTraces() |
| 37 |
err := td.getOrig().UnmarshalProto(buf) |
| 38 |
if err != nil { |
| 39 |
return Traces{}, err |
| 40 |
} |
| 41 |
return td, nil |
| 42 |
} |