Skip to content

Allow users to pass an io.Writer to protojson #20049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
denysvitali opened this issue Jan 20, 2025 · 2 comments
Closed

Allow users to pass an io.Writer to protojson #20049

denysvitali opened this issue Jan 20, 2025 · 2 comments
Labels
untriaged auto added to all issues by default when created.

Comments

@denysvitali
Copy link

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


cc/ @stapelberg, @els0r

@denysvitali denysvitali added the untriaged auto added to all issues by default when created. label Jan 20, 2025
@stapelberg
Copy link

I think this issue should have ended up in https://github.com/golang/protobuf/issues (the Go Protobuf issue tracker), but I lack permission to move it there.

@denysvitali Would you mind re-filing in the correct issue tracker please?

@denysvitali
Copy link
Author

Sure thing, will do :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
untriaged auto added to all issues by default when created.
Projects
None yet
Development

No branches or pull requests

2 participants