Defining custom options
ScalaPB allows you to define custom options you can use to annotate any element in a proto file, and access these annotations at run time.
Learn more about custom options.
#
Define your optionsIn my_opts.proto
:
Use the options like this:
Extensions that are defined at file scope are generated under the descriptor
proto (usually name FileNameProto
). Otherwise, the extension is defined in
the companion object of the containing class.
To access the option value of an element, you need to obtain its descriptor:
If you prefer to start with the descriptor, you use can the extension
method:
#
Example codeThe full source code of this example is available below: