Coder Social home page Coder Social logo

Comments (8)

bufdev avatar bufdev commented on September 18, 2024 1

Update: it turns out this is possible, and we have code that handles this situation. We'll be adding custom options marshalling for JSON in the near future, and the ability to convert to/from JSON/binary images.

from buf.

bufdev avatar bufdev commented on September 18, 2024

Hey,

JSON extensions are explicitly impossible:

https://github.com/protocolbuffers/protobuf/blob/master/java/util/src/main/java/com/google/protobuf/util/JsonFormat.java#L92

/**
 * Utility classes to convert protobuf messages to/from JSON format. The JSON
 * format follows Proto3 JSON specification and only proto3 features are
 * supported. Proto2 only features (e.g., extensions and unknown fields) will
 * be discarded in the conversion. That is, when converting proto2 messages
 * to JSON format, extensions and unknown fields will be treated as if they
 * do not exist. This applies to proto2 messages embedded in proto3 messages
 * as well.
 */

We'll keep this issue open unitl we update the documentation.

In general, as we said, it's much better to use the wire format than the JSON format when storing Protobuf messages. We don't do any comparisons with custom options for breaking change detection, so it is fine to store JSON messages to use in the breaking change detector, but for other use we would recommend you use the wire format.

from buf.

ChrisPenner avatar ChrisPenner commented on September 18, 2024

I think I might be misunderstanding a bit, the official docs say that extensions are explicitly still supported for the purpose of custom options in proto3 (even though that's the only place they're valid). https://developers.google.com/protocol-buffers/docs/proto3#custom_options

Is that not the case?

it's much better to use the wire format than the JSON format when storing Protobuf messages

I'm not actually storing messages, I'm attempting to run custom linting rules on custom options, I was under the impression buf is supposed to help make linting easier, but perhaps I misunderstand buf's goals.

Additional Context from the protocol buffers repo: protocolbuffers/protobuf#1460

from buf.

bufdev avatar bufdev commented on September 18, 2024

Extensions are supported for custom options for proto3, but are not encoded in JSON - the above link explains this, protobuf’s JSON encoders (which we do not maintain) do not support it.

We don’t explicitly support custom lint rules on purpose, but of course you are able to build off of our FileDescriptorSet output. However, protobuf does not appear to support custom option encoding in JSON.

from buf.

mgutz avatar mgutz commented on September 18, 2024

That is unfortunate. I'm using buf's JSON output to do code generation and the missing options details is a show stopper. The alternative is to use protobufjs/protobuf.js project's pbjs utility which emits options information.

from buf.

bufdev avatar bufdev commented on September 18, 2024

We are considering supporting this, stay tuned

from buf.

bufdev avatar bufdev commented on September 18, 2024

See #87

from buf.

bufdev avatar bufdev commented on September 18, 2024

Released as 0.18.0.

from buf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.