What does 'option' keyword in a .proto file means?
Asked Answered
G

1

10

I have a sample helloworld.proto file and use Python. I am not getting what does this option keyword has to do in the compilation phase?

syntax = "proto3";
package services.helloworld;

option go_package = "github.com/xyz/api/go/services/helloworld";
Gavelkind answered 8/4, 2020 at 5:38 Comment(0)
I
5

To a python user? Probably not a lot. Options are parsed into the DSL object model (FileDescriptorSet), and can be used by whatever tool is processing the schema. The "go" processor presumably uses that option to determine a package/namespace/etc. The python processor, on the other hand, probably isn't remotely interested. There is no "py" equivalent, so I presume it isn't needed for python. As for what is does: from descriptor.proto:


  // Sets the Go package where structs generated from this .proto will be
  // placed. If omitted, the Go package will be derived from the following:
  //   - The basename of the package import path, if provided.
  //   - Otherwise, the package statement in the .proto file, if present.
  //   - Otherwise, the basename of the .proto file, without extension.
  optional string go_package = 11;

Different options do different things; descriptor.proto is usually the best source for what inbuilt options exist (and what they do), however custom options can be defined by 3rd party tools.

Incapacitate answered 8/4, 2020 at 7:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.