Skip to content
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

Marshal/unmarshal custom options in JSON and add image convert command #87

Merged
merged 1 commit into from
Jun 22, 2020

Conversation

bufdev
Copy link
Member

@bufdev bufdev commented Jun 22, 2020

This PR does two things:

  1. Properly marshals/unmarshals custom options in JSON. This fixes Custom options are omitted from image json #50. For example:
syntax = "proto3";

import "google/protobuf/descriptor.proto";

extend google.protobuf.FieldOptions {
  int32 baz = 50007;
}

message Foo {
  string bar = 1 [(baz) = 42];
}

Running buf image build --exclude-imports --exclude-source-info -o -#format=json | jq results in:

{
  "file": [
    {
      "name": "a.proto",
      "dependency": [
        "google/protobuf/descriptor.proto"
      ],
      "messageType": [
        {
          "name": "Foo",
          "field": [
            {
              "name": "bar",
              "number": 1,
              "label": "LABEL_OPTIONAL",
              "type": "TYPE_STRING",
              "jsonName": "bar",
              "options": {
                "[baz]": 42
              }
            }
          ]
        }
      ],
      "extension": [
        {
          "name": "baz",
          "number": 50007,
          "label": "LABEL_OPTIONAL",
          "type": "TYPE_INT32",
          "extendee": ".google.protobuf.FieldOptions",
          "jsonName": "baz"
        }
      ],
      "syntax": "proto3"
    }
  ],
  "bufbuildImageExtension": {}
}
  1. Adds buf experimental image convert, that takes an Image as input, and outputs an Image, allowing conversion to/from binary/JSON, and filtering of imports and/or source code info. This fixes Add functionality to convert Image formats #44.

For example, the following command:

$ buf image build -o image.bin

Will produce the same file as:

$ buf image build -o - | buf experimental image convert -i - -o -#format=json | buf experimental image convert -i -#format=json -o image.bin

@bufdev bufdev merged commit fae7f6f into master Jun 22, 2020
@bufdev bufdev deleted the image-convert branch June 22, 2020 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Custom options are omitted from image json Add functionality to convert Image formats
1 participant