1. 前言

2. 释义

Individual declarations in a .proto file can be annotated with a number of options. Options do not change the overall meaning of a declaration, but may affect the way it is handled in a particular context. The complete list of available options is defined in google/protobuf/descriptor.proto.

简单来说，这个Options功能是为了让一份proto文件能使用在多种语言背景中而提供的一些简单选项。举两个例子就很容易理解了：

2.1 deprecated

官方解释说明：

If set to true, indicates that the field is deprecated and should not be used by new code. In most languages this has no actual effect. In Java, this becomes a @Deprecated annotation. In the future, other language-specific code generators may generate deprecation annotations on the field’s accessors, which will in turn cause a warning to be emitted when compiling code which attempts to use the field.

2.2 jstype

The jstype option determines the JavaScript type used for values of the field. The option is permitted only for 64 bit integral and fixed types(int64, uint64, sint64, fixed64, sfixed64). A field with jstype JS_STRING is represented as JavaScript string, which avoids loss of precision that can happen when a large value is converted to a floating point JavaScript. Specifying JS_NUMBER for the jstype causes the generated JavaScript code to use the JavaScript “number” type. The behavior of the default option JS_NORMAL is implementation dependent.

3. 功能全集

The complete list of available options is defined in google/protobuf/descriptor.proto.

4. 自定义Option

当官方的Options不能满足需求的时候，还可以制作自定义的Option，官方文档描述如下：

Protocol Buffers also allows you to define and use your own options. This is an advanced feature which most people don’t need. If you do think you need to create your own options, see the Proto2 Language Guide for details. Note that creating custom options uses extensions, which are permitted only for custom options in proto3.