Documentation
¶
Overview ¶
Package fdp provides functionality for lowering the IR to a FileDescriptorSet.
Options encoding on in-memory descriptors ¶
User-written options — `deprecated`, features, custom options — are serialized into their options message's unknown-field bytes, not its typed fields. This keeps the output byte-exact with protoc for arbitrary options without resolving option descriptors, but it means typed accessors on the descriptors returned by DescriptorProto read as unset (`GetOptions().GetDeprecated()` is false even when set in source, and proto.GetExtension misses custom options) until the descriptor round-trips through proto.Marshal/proto.Unmarshal, which folds the bytes into typed fields. DescriptorSetBytes and DescriptorProtoBytes output is unaffected: parsing it performs that fold.
Four categories are exempt and always typed in memory: the protowire.schema.v1 carrier extensions (AnnotationList, SourceMap, file-scope declaration lists); `options.map_entry` on synthetic map-entry messages, which reflection consumers such as google.golang.org/protobuf/reflect/protodesc.NewFile need for map classification; and the `google.api.http` rule the compiler itself lowers `@http` into (see EmitGoogleAPIHTTP); and the feature pin on a generated `_null` mask in an editions file (see ir.Session.NullMask). All four are compiler-synthesized rather than author-written, which is why they are set as typed extensions and not folded into the option bytes.
Index ¶
- func DescriptorProto(file *ir.File, options ...DescriptorOption) (*descriptorpb.FileDescriptorProto, error)
- func DescriptorProtoBytes(file *ir.File, options ...DescriptorOption) ([]byte, error)
- func DescriptorSetBytes(files []*ir.File, options ...DescriptorOption) ([]byte, error)
- type DescriptorOption
- type DescriptorPath
- type Excluder
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DescriptorProto ¶
func DescriptorProto(file *ir.File, options ...DescriptorOption) (*descriptorpb.FileDescriptorProto, error)
DescriptorProto generates a single *descriptorpb.FileDescriptorProto for the given *ir.File.
User-written options on the result are encoded in unknown-field bytes rather than typed fields; round-trip through proto.Marshal/proto.Unmarshal before reading them reflectively. See the package documentation for the exact contract.
func DescriptorProtoBytes ¶
func DescriptorProtoBytes(file *ir.File, options ...DescriptorOption) ([]byte, error)
DescriptorProtoBytes generates a single FileDescriptorProto for file, and returns the result as an encoded byte slice.
The resulting FileDescriptorProto is fully linked: all names are fully-qualified.
func DescriptorSetBytes ¶
func DescriptorSetBytes(files []*ir.File, options ...DescriptorOption) ([]byte, error)
DescriptorSetBytes generates a FileDescriptorSet for the given files, and returns the result as an encoded byte slice.
The resulting FileDescriptorSet is always fully linked: it contains every file named as a dependency of a file in it, well-known types included, unless ExcludeFiles leaves it out, and all names are fully-qualified. A file with a generated `_null` mask depends on google/protobuf/field_mask.proto whether or not it imports it (see ir.Session.NullMask).
Types ¶
type DescriptorOption ¶
type DescriptorOption interface {
// contains filtered or unexported methods
}
DescriptorOption is an option to pass to DescriptorSetBytes, DescriptorProtoBytes, or DescriptorProto.
func EmitGoogleAPIHTTP ¶ added in v0.24.0
func EmitGoogleAPIHTTP(flag bool) DescriptorOption
EmitGoogleAPIHTTP sets whether the routing skeleton of the canonical `@http` annotation is also lowered to the standard `google.api.http` extension on MethodOptions (RFC-001 §5.2, protowire#213). The annotation carrier is emitted either way; this only controls the second, standard spelling that off-the-shelf REST binders read.
Emission is on by default — the zero Options emits.
func ExcludeFiles ¶
func ExcludeFiles(exclude Excluder) DescriptorOption
ExcludeFiles excludes the given files from the output of DescriptorSetBytes and DescriptorProto.
func GenerateExtraOptionLocations ¶
func GenerateExtraOptionLocations(flag bool) DescriptorOption
GenerateExtraOptionLocations set whether or not to generate additional locations for elements inside of message literals in option values. This option is a no-op if IncludeSourceCodeInfo is not set.
func IncludeSourceCodeInfo ¶
func IncludeSourceCodeInfo(flag bool) DescriptorOption
IncludeSourceCodeInfo sets whether or not to include google.protobuf.SourceCodeInfo in the output.
type DescriptorPath ¶
DescriptorPath is the parsed form of a source-map entry's descriptor_path. See descpath.Path, which holds the grammar and the formatter.
func ParseDescriptorPath ¶
func ParseDescriptorPath(s string) (DescriptorPath, error)
ParseDescriptorPath parses a canonical descriptor_path string. See descpath.Parse.
type Excluder ¶
Excluder is used with ExcludeFiles.
This is an interface, rather than a function, so that implementations can be comparable for use in queries.
type Options ¶
type Options struct {
// contains filtered or unexported fields
}
Options records a set of [DescriptorOptions].
This type is intended for making options comparable, such as for use in queries.
func (*Options) Apply ¶
func (o *Options) Apply(options ...DescriptorOption) *Options
Apply applies the given DescriptorOption to this *Options.
Nil values are ignored; does nothing if opt is nil.