Skip to content

Commit 6bf6b56

Browse files
committed
Use the newly added proto marshaler/unmarshaler for the official proto Marshaler/Unmarshaler
Signed-off-by: Bogdan Drutu <[email protected]>
1 parent 9b90d9f commit 6bf6b56

File tree

4 files changed

+54
-44
lines changed

4 files changed

+54
-44
lines changed

pdata/plog/pb.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,41 +5,44 @@ package plog // import "go.opentelemetry.io/collector/pdata/plog"
55

66
import (
77
"go.opentelemetry.io/collector/pdata/internal"
8-
otlplogs "go.opentelemetry.io/collector/pdata/internal/data/protogen/logs/v1"
98
)
109

1110
var _ MarshalSizer = (*ProtoMarshaler)(nil)
1211

1312
type ProtoMarshaler struct{}
1413

1514
func (e *ProtoMarshaler) MarshalLogs(ld Logs) ([]byte, error) {
16-
pb := internal.LogsToProto(internal.Logs(ld))
17-
return pb.Marshal()
15+
size := internal.SizeProtoOrigExportLogsServiceRequest(ld.getOrig())
16+
buf := make([]byte, size)
17+
_ = internal.MarshalProtoOrigExportLogsServiceRequest(ld.getOrig(), buf)
18+
return buf, nil
1819
}
1920

2021
func (e *ProtoMarshaler) LogsSize(ld Logs) int {
21-
pb := internal.LogsToProto(internal.Logs(ld))
22-
return pb.Size()
22+
return internal.SizeProtoOrigExportLogsServiceRequest(ld.getOrig())
2323
}
2424

2525
func (e *ProtoMarshaler) ResourceLogsSize(rl ResourceLogs) int {
26-
return rl.orig.Size()
26+
return internal.SizeProtoOrigResourceLogs(rl.orig)
2727
}
2828

2929
func (e *ProtoMarshaler) ScopeLogsSize(sl ScopeLogs) int {
30-
return sl.orig.Size()
30+
return internal.SizeProtoOrigScopeLogs(sl.orig)
3131
}
3232

3333
func (e *ProtoMarshaler) LogRecordSize(lr LogRecord) int {
34-
return lr.orig.Size()
34+
return internal.SizeProtoOrigLogRecord(lr.orig)
3535
}
3636

3737
var _ Unmarshaler = (*ProtoUnmarshaler)(nil)
3838

3939
type ProtoUnmarshaler struct{}
4040

4141
func (d *ProtoUnmarshaler) UnmarshalLogs(buf []byte) (Logs, error) {
42-
pb := otlplogs.LogsData{}
43-
err := pb.Unmarshal(buf)
44-
return Logs(internal.LogsFromProto(pb)), err
42+
ld := NewLogs()
43+
err := internal.UnmarshalProtoOrigExportLogsServiceRequest(ld.getOrig(), buf)
44+
if err != nil {
45+
return Logs{}, err
46+
}
47+
return ld, nil
4548
}

pdata/pmetric/pb.go

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,55 +5,58 @@ package pmetric // import "go.opentelemetry.io/collector/pdata/pmetric"
55

66
import (
77
"go.opentelemetry.io/collector/pdata/internal"
8-
otlpmetrics "go.opentelemetry.io/collector/pdata/internal/data/protogen/metrics/v1"
98
)
109

1110
var _ MarshalSizer = (*ProtoMarshaler)(nil)
1211

1312
type ProtoMarshaler struct{}
1413

1514
func (e *ProtoMarshaler) MarshalMetrics(md Metrics) ([]byte, error) {
16-
pb := internal.MetricsToProto(internal.Metrics(md))
17-
return pb.Marshal()
15+
size := internal.SizeProtoOrigExportMetricsServiceRequest(md.getOrig())
16+
buf := make([]byte, size)
17+
_ = internal.MarshalProtoOrigExportMetricsServiceRequest(md.getOrig(), buf)
18+
return buf, nil
1819
}
1920

2021
func (e *ProtoMarshaler) MetricsSize(md Metrics) int {
21-
pb := internal.MetricsToProto(internal.Metrics(md))
22-
return pb.Size()
22+
return internal.SizeProtoOrigExportMetricsServiceRequest(md.getOrig())
2323
}
2424

2525
func (e *ProtoMarshaler) ResourceMetricsSize(rm ResourceMetrics) int {
26-
return rm.orig.Size()
26+
return internal.SizeProtoOrigResourceMetrics(rm.orig)
2727
}
2828

2929
func (e *ProtoMarshaler) ScopeMetricsSize(sm ScopeMetrics) int {
30-
return sm.orig.Size()
30+
return internal.SizeProtoOrigScopeMetrics(sm.orig)
3131
}
3232

3333
func (e *ProtoMarshaler) MetricSize(m Metric) int {
34-
return m.orig.Size()
34+
return internal.SizeProtoOrigMetric(m.orig)
3535
}
3636

3737
func (e *ProtoMarshaler) NumberDataPointSize(ndp NumberDataPoint) int {
38-
return ndp.orig.Size()
38+
return internal.SizeProtoOrigNumberDataPoint(ndp.orig)
3939
}
4040

4141
func (e *ProtoMarshaler) SummaryDataPointSize(sdps SummaryDataPoint) int {
42-
return sdps.orig.Size()
42+
return internal.SizeProtoOrigSummaryDataPoint(sdps.orig)
4343
}
4444

4545
func (e *ProtoMarshaler) HistogramDataPointSize(hdp HistogramDataPoint) int {
46-
return hdp.orig.Size()
46+
return internal.SizeProtoOrigHistogramDataPoint(hdp.orig)
4747
}
4848

4949
func (e *ProtoMarshaler) ExponentialHistogramDataPointSize(ehdp ExponentialHistogramDataPoint) int {
50-
return ehdp.orig.Size()
50+
return internal.SizeProtoOrigExponentialHistogramDataPoint(ehdp.orig)
5151
}
5252

5353
type ProtoUnmarshaler struct{}
5454

5555
func (d *ProtoUnmarshaler) UnmarshalMetrics(buf []byte) (Metrics, error) {
56-
pb := otlpmetrics.MetricsData{}
57-
err := pb.Unmarshal(buf)
58-
return Metrics(internal.MetricsFromProto(pb)), err
56+
md := NewMetrics()
57+
err := internal.UnmarshalProtoOrigExportMetricsServiceRequest(md.getOrig(), buf)
58+
if err != nil {
59+
return Metrics{}, err
60+
}
61+
return md, nil
5962
}

pdata/pprofile/pb.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,42 @@ package pprofile // import "go.opentelemetry.io/collector/pdata/pprofile"
55

66
import (
77
"go.opentelemetry.io/collector/pdata/internal"
8-
otlpprofile "go.opentelemetry.io/collector/pdata/internal/data/protogen/profiles/v1development"
98
)
109

1110
var _ MarshalSizer = (*ProtoMarshaler)(nil)
1211

1312
type ProtoMarshaler struct{}
1413

1514
func (e *ProtoMarshaler) MarshalProfiles(pd Profiles) ([]byte, error) {
16-
pb := internal.ProfilesToProto(internal.Profiles(pd))
17-
return pb.Marshal()
15+
size := internal.SizeProtoOrigExportProfilesServiceRequest(pd.getOrig())
16+
buf := make([]byte, size)
17+
_ = internal.MarshalProtoOrigExportProfilesServiceRequest(pd.getOrig(), buf)
18+
return buf, nil
1819
}
1920

2021
func (e *ProtoMarshaler) ProfilesSize(pd Profiles) int {
21-
pb := internal.ProfilesToProto(internal.Profiles(pd))
22-
return pb.Size()
22+
return internal.SizeProtoOrigExportProfilesServiceRequest(pd.getOrig())
2323
}
2424

2525
func (e *ProtoMarshaler) ResourceProfilesSize(pd ResourceProfiles) int {
26-
return pd.orig.Size()
26+
return internal.SizeProtoOrigResourceProfiles(pd.orig)
2727
}
2828

2929
func (e *ProtoMarshaler) ScopeProfilesSize(pd ScopeProfiles) int {
30-
return pd.orig.Size()
30+
return internal.SizeProtoOrigScopeProfiles(pd.orig)
3131
}
3232

3333
func (e *ProtoMarshaler) ProfileSize(pd Profile) int {
34-
return pd.orig.Size()
34+
return internal.SizeProtoOrigProfile(pd.orig)
3535
}
3636

3737
type ProtoUnmarshaler struct{}
3838

3939
func (d *ProtoUnmarshaler) UnmarshalProfiles(buf []byte) (Profiles, error) {
40-
pb := otlpprofile.ProfilesData{}
41-
err := pb.Unmarshal(buf)
42-
return Profiles(internal.ProfilesFromProto(pb)), err
40+
pd := NewProfiles()
41+
err := internal.UnmarshalProtoOrigExportProfilesServiceRequest(pd.getOrig(), buf)
42+
if err != nil {
43+
return Profiles{}, err
44+
}
45+
return pd, nil
4346
}

pdata/ptrace/pb.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,25 +13,26 @@ var _ MarshalSizer = (*ProtoMarshaler)(nil)
1313
type ProtoMarshaler struct{}
1414

1515
func (e *ProtoMarshaler) MarshalTraces(td Traces) ([]byte, error) {
16-
pb := internal.TracesToProto(internal.Traces(td))
17-
return pb.Marshal()
16+
size := internal.SizeProtoOrigExportTraceServiceRequest(td.getOrig())
17+
buf := make([]byte, size)
18+
_ = internal.MarshalProtoOrigExportTraceServiceRequest(td.getOrig(), buf)
19+
return buf, nil
1820
}
1921

2022
func (e *ProtoMarshaler) TracesSize(td Traces) int {
21-
pb := internal.TracesToProto(internal.Traces(td))
22-
return pb.Size()
23+
return internal.SizeProtoOrigExportTraceServiceRequest(td.getOrig())
2324
}
2425

2526
func (e *ProtoMarshaler) ResourceSpansSize(rs ResourceSpans) int {
26-
return rs.orig.Size()
27+
return internal.SizeProtoOrigResourceSpans(rs.orig)
2728
}
2829

2930
func (e *ProtoMarshaler) ScopeSpansSize(ss ScopeSpans) int {
30-
return ss.orig.Size()
31+
return internal.SizeProtoOrigScopeSpans(ss.orig)
3132
}
3233

3334
func (e *ProtoMarshaler) SpanSize(span Span) int {
34-
return span.orig.Size()
35+
return internal.SizeProtoOrigSpan(span.orig)
3536
}
3637

3738
type ProtoUnmarshaler struct{}

0 commit comments

Comments
 (0)