Description
What language does this apply to?
Golang (protocolbuffers/protobuf-go)
Describe the problem you are trying to solve.
As part of open-telemetry/opentelemetry-collector#7095 we would like to switch to the new Protobuf Opaque API to increase the performance of opentelemetry-collector (specifically when exporting telemetry as JSON).
We would like to use encoding/protojson for this, but the current implementation doesn't allow users to pass an io.Writer
.
The only method available to encode JSON is:
func Marshal(m proto.Message) ([]byte, error)
Describe the solution you'd like
We would like to see a solution similar to encoding/json
's Encoder
, where a new encoder can be created by passing an io.Writer
and we can call Encode(obj)
.
This will prevent the use of a buffer that will only impact the encoding performance.
func NewEncoder(w io.Writer) *Encoder
func (enc *Encoder) Encode(v any) error
Describe alternatives you've considered
None
Additional context
- [pdata] Find replacement for now deprecated gogo/protobuf open-telemetry/opentelemetry-collector#7095
- https://pkg.go.dev/google.golang.org/protobuf@v1.36.3/encoding/protojson
- https://pkg.go.dev/encoding/json#Encoder
cc/ @stapelberg, @els0r
Moved from protocolbuffers/protobuf#20049
Activity