Documentation ¶
Overview ¶
Package desc contains "rich descriptors" for protocol buffers. The built-in descriptor types are simple protobuf messages, each one representing a different kind of element in the AST of a .proto source file.
Because of this inherent "tree" quality, a given message descriptor cannot refer to its enclosing file descriptor. Nor can a field descriptor refer to a message or enum descriptor that represents the field's type (for enum and nested message fields). This limitation makes them much harder to use for doing interesting things with reflection.
Without this package, resolving references to types is particularly nasty -- like resolving a field's type, the message type an extension extends, the request and response types of an RPC method, etc. They are simply strings, and can even be relative type references, with their own lexical scoping and resolution rules.
"Rich descriptors" avoid the need to deal with the complexities described above. A rich descriptor has all type references resolved and provides methods to access other rich descriptors for all referenced elements. Each rich descriptor has a usefully broad API, but does not try to mimic the full interface of the underlying descriptor proto. Instead, every rich descriptor provides access to that underlying proto, for extracting descriptor properties that are not immediately accessible through rich descriptor's methods.
Rich descriptors can be accessed in similar ways as their "poor" cousins (descriptor protos). Instead of using proto.FileDescriptor, use desc.LoadFileDescriptor. Message descriptors and extension field descriptors can also be easily accessed using desc.LoadMessageDescriptor and desc.LoadFieldDescriptorForExtension, respectively.
It is also possible create rich descriptors for proto messages that a given Go program doesn't even know about. For example, they could be loaded from a FileDescriptorSet file (which can be generated by protoc) or loaded from a server. This enables interesting things like dynamic clients: where a Go program can be an RPC client of a service it wasn't compiled to know about.
Also see the grpcreflect, dynamic, and grpcdynamic packages in this same repo to see just how useful rich descriptors really are.
Index ¶
- func CreateFileDescriptors(fds []*dpb.FileDescriptorProto) (map[string]*FileDescriptor, error)
- type Descriptor
- type EnumDescriptor
- func (ed *EnumDescriptor) AsEnumDescriptorProto() *dpb.EnumDescriptorProto
- func (ed *EnumDescriptor) AsProto() proto.Message
- func (ed *EnumDescriptor) FindValueByName(name string) *EnumValueDescriptor
- func (ed *EnumDescriptor) FindValueByNumber(num int32) *EnumValueDescriptor
- func (ed *EnumDescriptor) GetEnumOptions() *dpb.EnumOptions
- func (ed *EnumDescriptor) GetFile() *FileDescriptor
- func (ed *EnumDescriptor) GetFullyQualifiedName() string
- func (ed *EnumDescriptor) GetName() string
- func (ed *EnumDescriptor) GetOptions() proto.Message
- func (ed *EnumDescriptor) GetParent() Descriptor
- func (ed *EnumDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
- func (ed *EnumDescriptor) GetValues() []*EnumValueDescriptor
- func (ed *EnumDescriptor) String() string
- type EnumValueDescriptor
- func (vd *EnumValueDescriptor) AsEnumValueDescriptorProto() *dpb.EnumValueDescriptorProto
- func (vd *EnumValueDescriptor) AsProto() proto.Message
- func (vd *EnumValueDescriptor) GetEnum() *EnumDescriptor
- func (vd *EnumValueDescriptor) GetEnumValueOptions() *dpb.EnumValueOptions
- func (vd *EnumValueDescriptor) GetFile() *FileDescriptor
- func (vd *EnumValueDescriptor) GetFullyQualifiedName() string
- func (vd *EnumValueDescriptor) GetName() string
- func (vd *EnumValueDescriptor) GetNumber() int32
- func (vd *EnumValueDescriptor) GetOptions() proto.Message
- func (vd *EnumValueDescriptor) GetParent() Descriptor
- func (vd *EnumValueDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
- func (vd *EnumValueDescriptor) String() string
- type FieldDescriptor
- func (fd *FieldDescriptor) AsFieldDescriptorProto() *dpb.FieldDescriptorProto
- func (fd *FieldDescriptor) AsProto() proto.Message
- func (fd *FieldDescriptor) GetDefaultValue() interface{}
- func (fd *FieldDescriptor) GetEnumType() *EnumDescriptor
- func (fd *FieldDescriptor) GetFieldOptions() *dpb.FieldOptions
- func (fd *FieldDescriptor) GetFile() *FileDescriptor
- func (fd *FieldDescriptor) GetFullyQualifiedJSONName() string
- func (fd *FieldDescriptor) GetFullyQualifiedName() string
- func (fd *FieldDescriptor) GetJSONName() string
- func (fd *FieldDescriptor) GetLabel() dpb.FieldDescriptorProto_Label
- func (fd *FieldDescriptor) GetMapKeyType() *FieldDescriptor
- func (fd *FieldDescriptor) GetMapValueType() *FieldDescriptor
- func (fd *FieldDescriptor) GetMessageType() *MessageDescriptor
- func (fd *FieldDescriptor) GetName() string
- func (fd *FieldDescriptor) GetNumber() int32
- func (fd *FieldDescriptor) GetOneOf() *OneOfDescriptor
- func (fd *FieldDescriptor) GetOptions() proto.Message
- func (fd *FieldDescriptor) GetOwner() *MessageDescriptor
- func (fd *FieldDescriptor) GetParent() Descriptor
- func (fd *FieldDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
- func (fd *FieldDescriptor) GetType() dpb.FieldDescriptorProto_Type
- func (fd *FieldDescriptor) IsExtension() bool
- func (fd *FieldDescriptor) IsMap() bool
- func (fd *FieldDescriptor) IsRepeated() bool
- func (fd *FieldDescriptor) IsRequired() bool
- func (fd *FieldDescriptor) String() string
- type FileDescriptor
- func (fd *FileDescriptor) AsFileDescriptorProto() *dpb.FileDescriptorProto
- func (fd *FileDescriptor) AsProto() proto.Message
- func (fd *FileDescriptor) FindEnum(enumName string) *EnumDescriptor
- func (fd *FileDescriptor) FindExtension(extendeeName string, tagNumber int32) *FieldDescriptor
- func (fd *FileDescriptor) FindExtensionByName(extName string) *FieldDescriptor
- func (fd *FileDescriptor) FindMessage(msgName string) *MessageDescriptor
- func (fd *FileDescriptor) FindService(serviceName string) *ServiceDescriptor
- func (fd *FileDescriptor) FindSymbol(symbol string) Descriptor
- func (fd *FileDescriptor) GetDependencies() []*FileDescriptor
- func (fd *FileDescriptor) GetEnumTypes() []*EnumDescriptor
- func (fd *FileDescriptor) GetExtensions() []*FieldDescriptor
- func (fd *FileDescriptor) GetFile() *FileDescriptor
- func (fd *FileDescriptor) GetFileOptions() *dpb.FileOptions
- func (fd *FileDescriptor) GetFullyQualifiedName() string
- func (fd *FileDescriptor) GetMessageTypes() []*MessageDescriptor
- func (fd *FileDescriptor) GetName() string
- func (fd *FileDescriptor) GetOptions() proto.Message
- func (fd *FileDescriptor) GetPackage() string
- func (fd *FileDescriptor) GetParent() Descriptor
- func (fd *FileDescriptor) GetPublicDependencies() []*FileDescriptor
- func (fd *FileDescriptor) GetServices() []*ServiceDescriptor
- func (fd *FileDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
- func (fd *FileDescriptor) GetWeakDependencies() []*FileDescriptor
- func (fd *FileDescriptor) IsProto3() bool
- func (fd *FileDescriptor) String() string
- type MessageDescriptor
- func (md *MessageDescriptor) AsDescriptorProto() *dpb.DescriptorProto
- func (md *MessageDescriptor) AsProto() proto.Message
- func (md *MessageDescriptor) FindFieldByJSONName(jsonName string) *FieldDescriptor
- func (md *MessageDescriptor) FindFieldByName(fieldName string) *FieldDescriptor
- func (md *MessageDescriptor) FindFieldByNumber(tagNumber int32) *FieldDescriptor
- func (md *MessageDescriptor) GetExtensionRanges() []proto.ExtensionRange
- func (md *MessageDescriptor) GetFields() []*FieldDescriptor
- func (md *MessageDescriptor) GetFile() *FileDescriptor
- func (md *MessageDescriptor) GetFullyQualifiedName() string
- func (md *MessageDescriptor) GetMessageOptions() *dpb.MessageOptions
- func (md *MessageDescriptor) GetName() string
- func (md *MessageDescriptor) GetNestedEnumTypes() []*EnumDescriptor
- func (md *MessageDescriptor) GetNestedExtensions() []*FieldDescriptor
- func (md *MessageDescriptor) GetNestedMessageTypes() []*MessageDescriptor
- func (md *MessageDescriptor) GetOneOfs() []*OneOfDescriptor
- func (md *MessageDescriptor) GetOptions() proto.Message
- func (md *MessageDescriptor) GetParent() Descriptor
- func (md *MessageDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
- func (md *MessageDescriptor) IsExtendable() bool
- func (md *MessageDescriptor) IsExtension(tagNumber int32) bool
- func (md *MessageDescriptor) IsMapEntry() bool
- func (md *MessageDescriptor) IsProto3() bool
- func (md *MessageDescriptor) String() string
- type MethodDescriptor
- func (md *MethodDescriptor) AsMethodDescriptorProto() *dpb.MethodDescriptorProto
- func (md *MethodDescriptor) AsProto() proto.Message
- func (md *MethodDescriptor) GetFile() *FileDescriptor
- func (md *MethodDescriptor) GetFullyQualifiedName() string
- func (md *MethodDescriptor) GetInputType() *MessageDescriptor
- func (md *MethodDescriptor) GetMethodOptions() *dpb.MethodOptions
- func (md *MethodDescriptor) GetName() string
- func (md *MethodDescriptor) GetOptions() proto.Message
- func (md *MethodDescriptor) GetOutputType() *MessageDescriptor
- func (md *MethodDescriptor) GetParent() Descriptor
- func (md *MethodDescriptor) GetService() *ServiceDescriptor
- func (md *MethodDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
- func (md *MethodDescriptor) IsClientStreaming() bool
- func (md *MethodDescriptor) IsServerStreaming() bool
- func (md *MethodDescriptor) String() string
- type OneOfDescriptor
- func (od *OneOfDescriptor) AsOneofDescriptorProto() *dpb.OneofDescriptorProto
- func (od *OneOfDescriptor) AsProto() proto.Message
- func (od *OneOfDescriptor) GetChoices() []*FieldDescriptor
- func (od *OneOfDescriptor) GetFile() *FileDescriptor
- func (od *OneOfDescriptor) GetFullyQualifiedName() string
- func (od *OneOfDescriptor) GetName() string
- func (od *OneOfDescriptor) GetOneOfOptions() *dpb.OneofOptions
- func (od *OneOfDescriptor) GetOptions() proto.Message
- func (od *OneOfDescriptor) GetOwner() *MessageDescriptor
- func (od *OneOfDescriptor) GetParent() Descriptor
- func (od *OneOfDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
- func (od *OneOfDescriptor) String() string
- type ServiceDescriptor
- func (sd *ServiceDescriptor) AsProto() proto.Message
- func (sd *ServiceDescriptor) AsServiceDescriptorProto() *dpb.ServiceDescriptorProto
- func (sd *ServiceDescriptor) FindMethodByName(name string) *MethodDescriptor
- func (sd *ServiceDescriptor) GetFile() *FileDescriptor
- func (sd *ServiceDescriptor) GetFullyQualifiedName() string
- func (sd *ServiceDescriptor) GetMethods() []*MethodDescriptor
- func (sd *ServiceDescriptor) GetName() string
- func (sd *ServiceDescriptor) GetOptions() proto.Message
- func (sd *ServiceDescriptor) GetParent() Descriptor
- func (sd *ServiceDescriptor) GetServiceOptions() *dpb.ServiceOptions
- func (sd *ServiceDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
- func (sd *ServiceDescriptor) String() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateFileDescriptors ¶
func CreateFileDescriptors(fds []*dpb.FileDescriptorProto) (map[string]*FileDescriptor, error)
CreateFileDescriptors constructs a set of descriptors, one for each of the given descriptor protos. The given set of descriptor protos must include all transitive dependencies for every file.
Types ¶
type Descriptor ¶
type Descriptor interface { // GetName returns the name of the object described by the descriptor. This will // be a base name that does not include enclosing message names or the package name. // For file descriptors, this indicates the path and name to the described file. GetName() string // GetFullyQualifiedName returns the fully-qualified name of the object described by // the descriptor. This will include the package name and any enclosing message names. // For file descriptors, this returns the path and name to the described file (same as // GetName). GetFullyQualifiedName() string // GetParent returns the enclosing element in a proto source file. If the described // object is a top-level object, this returns the file descriptor. Otherwise, it returns // the element in which the described object was declared. File descriptors have no // parent and return nil. GetParent() Descriptor // GetFile returns the file descriptor in which this element was declared. File // descriptors return themselves. GetFile() *FileDescriptor // GetOptions returns the options proto containing options for the described element. GetOptions() proto.Message // GetSourceInfo returns any source code information that was present in the file // descriptor. Source code info is optional. If no source code info is available for // the element (including if there is none at all in the file descriptor) then this // returns nil GetSourceInfo() *dpb.SourceCodeInfo_Location // AsProto returns the underlying descriptor proto for this descriptor. AsProto() proto.Message }
Descriptor is the common interface implemented by all descriptor objects.
type EnumDescriptor ¶
type EnumDescriptor struct {
// contains filtered or unexported fields
}
EnumDescriptor describes an enum declared in a proto file.
func LoadEnumDescriptorForEnum ¶
func LoadEnumDescriptorForEnum(enum protoEnum) (*EnumDescriptor, error)
LoadEnumDescriptorForEnum loads descriptor using the encoded descriptor proto returned by enum.EnumDescriptor().
func LoadEnumDescriptorForType ¶
func LoadEnumDescriptorForType(enumType reflect.Type) (*EnumDescriptor, error)
LoadEnumDescriptorForType loads descriptor using the encoded descriptor proto returned by enum.EnumDescriptor() for the given enum type.
func (*EnumDescriptor) AsEnumDescriptorProto ¶
func (ed *EnumDescriptor) AsEnumDescriptorProto() *dpb.EnumDescriptorProto
func (*EnumDescriptor) AsProto ¶
func (ed *EnumDescriptor) AsProto() proto.Message
func (*EnumDescriptor) FindValueByName ¶
func (ed *EnumDescriptor) FindValueByName(name string) *EnumValueDescriptor
FindValueByName finds the enum value with the given name. If no such value exists then nil is returned.
func (*EnumDescriptor) FindValueByNumber ¶
func (ed *EnumDescriptor) FindValueByNumber(num int32) *EnumValueDescriptor
FindValueByNumber finds the value with the given numeric value. If no such value exists then nil is returned. If aliases are allowed and multiple values have the given number, the first declared value is returned.
func (*EnumDescriptor) GetEnumOptions ¶
func (ed *EnumDescriptor) GetEnumOptions() *dpb.EnumOptions
func (*EnumDescriptor) GetFile ¶
func (ed *EnumDescriptor) GetFile() *FileDescriptor
func (*EnumDescriptor) GetFullyQualifiedName ¶
func (ed *EnumDescriptor) GetFullyQualifiedName() string
func (*EnumDescriptor) GetName ¶
func (ed *EnumDescriptor) GetName() string
func (*EnumDescriptor) GetOptions ¶
func (ed *EnumDescriptor) GetOptions() proto.Message
func (*EnumDescriptor) GetParent ¶
func (ed *EnumDescriptor) GetParent() Descriptor
func (*EnumDescriptor) GetSourceInfo ¶
func (ed *EnumDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
func (*EnumDescriptor) GetValues ¶
func (ed *EnumDescriptor) GetValues() []*EnumValueDescriptor
GetValues returns all of the allowed values defined for this enum.
func (*EnumDescriptor) String ¶
func (ed *EnumDescriptor) String() string
type EnumValueDescriptor ¶
type EnumValueDescriptor struct {
// contains filtered or unexported fields
}
EnumValueDescriptor describes an allowed value of an enum declared in a proto file.
func (*EnumValueDescriptor) AsEnumValueDescriptorProto ¶
func (vd *EnumValueDescriptor) AsEnumValueDescriptorProto() *dpb.EnumValueDescriptorProto
func (*EnumValueDescriptor) AsProto ¶
func (vd *EnumValueDescriptor) AsProto() proto.Message
func (*EnumValueDescriptor) GetEnum ¶
func (vd *EnumValueDescriptor) GetEnum() *EnumDescriptor
GetEnum returns the enum in which this enum value is defined.
func (*EnumValueDescriptor) GetEnumValueOptions ¶
func (vd *EnumValueDescriptor) GetEnumValueOptions() *dpb.EnumValueOptions
func (*EnumValueDescriptor) GetFile ¶
func (vd *EnumValueDescriptor) GetFile() *FileDescriptor
func (*EnumValueDescriptor) GetFullyQualifiedName ¶
func (vd *EnumValueDescriptor) GetFullyQualifiedName() string
func (*EnumValueDescriptor) GetName ¶
func (vd *EnumValueDescriptor) GetName() string
func (*EnumValueDescriptor) GetNumber ¶
func (vd *EnumValueDescriptor) GetNumber() int32
GetNumber returns the numeric value associated with this enum value.
func (*EnumValueDescriptor) GetOptions ¶
func (vd *EnumValueDescriptor) GetOptions() proto.Message
func (*EnumValueDescriptor) GetParent ¶
func (vd *EnumValueDescriptor) GetParent() Descriptor
func (*EnumValueDescriptor) GetSourceInfo ¶
func (vd *EnumValueDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
func (*EnumValueDescriptor) String ¶
func (vd *EnumValueDescriptor) String() string
type FieldDescriptor ¶
type FieldDescriptor struct {
// contains filtered or unexported fields
}
FieldDescriptor describes a field of a protocol buffer message.
func LoadFieldDescriptorForExtension ¶
func LoadFieldDescriptorForExtension(ext *proto.ExtensionDesc) (*FieldDescriptor, error)
LoadFieldDescriptorForExtension loads the field descriptor that corresponds to the given extension description.
func (*FieldDescriptor) AsFieldDescriptorProto ¶
func (fd *FieldDescriptor) AsFieldDescriptorProto() *dpb.FieldDescriptorProto
func (*FieldDescriptor) AsProto ¶
func (fd *FieldDescriptor) AsProto() proto.Message
func (*FieldDescriptor) GetDefaultValue ¶
func (fd *FieldDescriptor) GetDefaultValue() interface{}
GetDefaultValue returns the default value for this field.
If this field represents a message type, this method always returns nil (even though for proto2 files, the default value should be a default instance of the message type). If the field represents an enum type, this method returns an int32 corresponding to the enum value. If this field is a map, it returns a nil map[interface{}]interface{}. If this field is repeated (and not a map), it returns a nil []interface{}.
Otherwise, it returns the declared default value for the field or a zero value, if no default is declared or if the file is proto3. The type of said return value corresponds to the type of the field:
|-------------------------| | Declared Type | Go Type | |---------------+---------| | int32 | | | sint32 | int32 | | sfixed32 | | |---------------+---------| | uint32 | uint32 | | fixed32 | | |---------------+---------| | int64 | | | sint64 | int64 | | sfixed64 | | |---------------+---------| | uint64 | uint64 | | fixed64 | | |---------------+---------| | float | float32 | |---------------+---------| | double | float64 | |---------------+---------| | bool | bool | |---------------+---------| | bytes | []byte | |---------------+---------| | string | string | |-------------------------|
func (*FieldDescriptor) GetEnumType ¶
func (fd *FieldDescriptor) GetEnumType() *EnumDescriptor
GetEnumType returns the type of this field if it is an enum type. If this field is not an enum type, it returns nil.
func (*FieldDescriptor) GetFieldOptions ¶
func (fd *FieldDescriptor) GetFieldOptions() *dpb.FieldOptions
func (*FieldDescriptor) GetFile ¶
func (fd *FieldDescriptor) GetFile() *FileDescriptor
func (*FieldDescriptor) GetFullyQualifiedJSONName ¶
func (fd *FieldDescriptor) GetFullyQualifiedJSONName() string
func (*FieldDescriptor) GetFullyQualifiedName ¶
func (fd *FieldDescriptor) GetFullyQualifiedName() string
func (*FieldDescriptor) GetJSONName ¶
func (fd *FieldDescriptor) GetJSONName() string
func (*FieldDescriptor) GetLabel ¶
func (fd *FieldDescriptor) GetLabel() dpb.FieldDescriptorProto_Label
GetLabel returns the label for this field. The label can be required (proto2-only), optional (default for proto3), or required.
func (*FieldDescriptor) GetMapKeyType ¶
func (fd *FieldDescriptor) GetMapKeyType() *FieldDescriptor
GetMapKeyType returns the type of the key field if this is a map field. If it is not a map field, nil is returned.
func (*FieldDescriptor) GetMapValueType ¶
func (fd *FieldDescriptor) GetMapValueType() *FieldDescriptor
GetMapValueType returns the type of the value field if this is a map field. If it is not a map field, nil is returned.
func (*FieldDescriptor) GetMessageType ¶
func (fd *FieldDescriptor) GetMessageType() *MessageDescriptor
GetMessageType returns the type of this field if it is a message type. If this field is not a message type, it returns nil.
func (*FieldDescriptor) GetName ¶
func (fd *FieldDescriptor) GetName() string
func (*FieldDescriptor) GetNumber ¶
func (fd *FieldDescriptor) GetNumber() int32
GetNumber returns the tag number of this field.
func (*FieldDescriptor) GetOneOf ¶
func (fd *FieldDescriptor) GetOneOf() *OneOfDescriptor
GetOneOf returns the one-of field set to which this field belongs. If this field is not part of a one-of then this method returns nil.
func (*FieldDescriptor) GetOptions ¶
func (fd *FieldDescriptor) GetOptions() proto.Message
func (*FieldDescriptor) GetOwner ¶
func (fd *FieldDescriptor) GetOwner() *MessageDescriptor
GetOwner returns the message type that this field belongs to. If this is a normal field then this is the same as GetParent. But for extensions, this will be the extendee message whereas GetParent refers to where the extension was declared.
func (*FieldDescriptor) GetParent ¶
func (fd *FieldDescriptor) GetParent() Descriptor
func (*FieldDescriptor) GetSourceInfo ¶
func (fd *FieldDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
func (*FieldDescriptor) GetType ¶
func (fd *FieldDescriptor) GetType() dpb.FieldDescriptorProto_Type
GetType returns the type of this field. If the type indicates an enum, the enum type can be queried via GetEnumType. If the type indicates a message, the message type can be queried via GetMessageType.
func (*FieldDescriptor) IsExtension ¶
func (fd *FieldDescriptor) IsExtension() bool
IsExtension returns true if this is an extension field.
func (*FieldDescriptor) IsMap ¶
func (fd *FieldDescriptor) IsMap() bool
IsMap returns true if this is a map field. If so, it will have the "repeated" label its type will be a message that represents a map entry. The map entry message will have exactly two fields: tag #1 is the key and tag #2 is the value.
func (*FieldDescriptor) IsRepeated ¶
func (fd *FieldDescriptor) IsRepeated() bool
IsRepeated returns true if this field has the "repeated" label.
func (*FieldDescriptor) IsRequired ¶
func (fd *FieldDescriptor) IsRequired() bool
IsRequired returns true if this field has the "required" label.
func (*FieldDescriptor) String ¶
func (fd *FieldDescriptor) String() string
type FileDescriptor ¶
type FileDescriptor struct {
// contains filtered or unexported fields
}
FileDescriptor describes a proto source file.
func CreateFileDescriptor ¶
func CreateFileDescriptor(fd *dpb.FileDescriptorProto, deps ...*FileDescriptor) (*FileDescriptor, error)
CreateFileDescriptor instantiates a new file descriptor for the given descriptor proto. The file's direct dependencies must be provided. If the given dependencies do not include all of the file's dependencies or if the contents of the descriptors are internally inconsistent (e.g. contain unresolvable symbols) then an error is returned.
func CreateFileDescriptorFromSet ¶
func CreateFileDescriptorFromSet(fds *dpb.FileDescriptorSet) (*FileDescriptor, error)
CreateFileDescriptorFromSet creates a descriptor from the given file descriptor set. The set's *last* file will be the returned descriptor. The set's remaining files must comprise the full set of transitive dependencies of that last file. This is the same format and order used by protoc when emitting a FileDescriptorSet file with an invocation like so:
protoc --descriptor_set_out=./test.protoset --include_imports -I. test.proto
func LoadFileDescriptor ¶
func LoadFileDescriptor(file string) (*FileDescriptor, error)
LoadFileDescriptor creates a file descriptor using the bytes returned by proto.FileDescriptor. Descriptors are cached so that they do not need to be re-processed if the same file is fetched again later.
func (*FileDescriptor) AsFileDescriptorProto ¶
func (fd *FileDescriptor) AsFileDescriptorProto() *dpb.FileDescriptorProto
func (*FileDescriptor) AsProto ¶
func (fd *FileDescriptor) AsProto() proto.Message
func (*FileDescriptor) FindEnum ¶
func (fd *FileDescriptor) FindEnum(enumName string) *EnumDescriptor
FindEnum finds the enum with the given fully-qualified name. If no such element exists in this file then nil is returned.
func (*FileDescriptor) FindExtension ¶
func (fd *FileDescriptor) FindExtension(extendeeName string, tagNumber int32) *FieldDescriptor
FindExtension finds the extension field for the given extended type name and tag number. If no such element exists in this file then nil is returned.
func (*FileDescriptor) FindExtensionByName ¶
func (fd *FileDescriptor) FindExtensionByName(extName string) *FieldDescriptor
FindExtensionByName finds the extension field with the given fully-qualified name. If no such element exists in this file then nil is returned.
func (*FileDescriptor) FindMessage ¶
func (fd *FileDescriptor) FindMessage(msgName string) *MessageDescriptor
FindMessage finds the message with the given fully-qualified name. If no such element exists in this file then nil is returned.
func (*FileDescriptor) FindService ¶
func (fd *FileDescriptor) FindService(serviceName string) *ServiceDescriptor
FindService finds the service with the given fully-qualified name. If no such element exists in this file then nil is returned.
func (*FileDescriptor) FindSymbol ¶
func (fd *FileDescriptor) FindSymbol(symbol string) Descriptor
FindSymbol returns the descriptor contained within this file for the element with the given fully-qualified symbol name. If no such element exists then this method returns nil.
func (*FileDescriptor) GetDependencies ¶
func (fd *FileDescriptor) GetDependencies() []*FileDescriptor
GetDependencies returns all of this file's dependencies. These correspond to import statements in the file.
func (*FileDescriptor) GetEnumTypes ¶
func (fd *FileDescriptor) GetEnumTypes() []*EnumDescriptor
GetEnumTypes returns all top-level enums declared in this file.
func (*FileDescriptor) GetExtensions ¶
func (fd *FileDescriptor) GetExtensions() []*FieldDescriptor
GetExtensions returns all top-level extensions declared in this file.
func (*FileDescriptor) GetFile ¶
func (fd *FileDescriptor) GetFile() *FileDescriptor
func (*FileDescriptor) GetFileOptions ¶
func (fd *FileDescriptor) GetFileOptions() *dpb.FileOptions
func (*FileDescriptor) GetFullyQualifiedName ¶
func (fd *FileDescriptor) GetFullyQualifiedName() string
func (*FileDescriptor) GetMessageTypes ¶
func (fd *FileDescriptor) GetMessageTypes() []*MessageDescriptor
GetMessageTypes returns all top-level messages declared in this file.
func (*FileDescriptor) GetName ¶
func (fd *FileDescriptor) GetName() string
func (*FileDescriptor) GetOptions ¶
func (fd *FileDescriptor) GetOptions() proto.Message
func (*FileDescriptor) GetPackage ¶
func (fd *FileDescriptor) GetPackage() string
func (*FileDescriptor) GetParent ¶
func (fd *FileDescriptor) GetParent() Descriptor
func (*FileDescriptor) GetPublicDependencies ¶
func (fd *FileDescriptor) GetPublicDependencies() []*FileDescriptor
GetPublicDependencies returns all of this file's public dependencies. These correspond to public import statements in the file.
func (*FileDescriptor) GetServices ¶
func (fd *FileDescriptor) GetServices() []*ServiceDescriptor
GetServices returns all services declared in this file.
func (*FileDescriptor) GetSourceInfo ¶
func (fd *FileDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
func (*FileDescriptor) GetWeakDependencies ¶
func (fd *FileDescriptor) GetWeakDependencies() []*FileDescriptor
GetWeakDependencies returns all of this file's weak dependencies. These correspond to weak import statements in the file.
func (*FileDescriptor) IsProto3 ¶
func (fd *FileDescriptor) IsProto3() bool
IsProto3 returns true if the file declares a syntax of "proto3".
func (*FileDescriptor) String ¶
func (fd *FileDescriptor) String() string
type MessageDescriptor ¶
type MessageDescriptor struct {
// contains filtered or unexported fields
}
MessageDescriptor describes a protocol buffer message.
func LoadMessageDescriptor ¶
func LoadMessageDescriptor(message string) (*MessageDescriptor, error)
LoadMessageDescriptor loads descriptor using the encoded descriptor proto returned by Message.Descriptor() for the given message type. If the given type is not recognized, then a nil descriptor is returned.
func LoadMessageDescriptorForMessage ¶
func LoadMessageDescriptorForMessage(message proto.Message) (*MessageDescriptor, error)
LoadMessageDescriptorForMessage loads descriptor using the encoded descriptor proto returned by message.Descriptor(). If the given type is not recognized, then a nil descriptor is returned.
func LoadMessageDescriptorForType ¶
func LoadMessageDescriptorForType(messageType reflect.Type) (*MessageDescriptor, error)
LoadMessageDescriptorForType loads descriptor using the encoded descriptor proto returned by message.Descriptor() for the given message type. If the given type is not recognized, then a nil descriptor is returned.
func (*MessageDescriptor) AsDescriptorProto ¶
func (md *MessageDescriptor) AsDescriptorProto() *dpb.DescriptorProto
func (*MessageDescriptor) AsProto ¶
func (md *MessageDescriptor) AsProto() proto.Message
func (*MessageDescriptor) FindFieldByJSONName ¶
func (md *MessageDescriptor) FindFieldByJSONName(jsonName string) *FieldDescriptor
FindFieldByJSONName finds the field with the given JSON field name. If no such field exists then nil is returned. Only regular fields are returned, not extensions.
func (*MessageDescriptor) FindFieldByName ¶
func (md *MessageDescriptor) FindFieldByName(fieldName string) *FieldDescriptor
FindFieldByName finds the field with the given name. If no such field exists then nil is returned. Only regular fields are returned, not extensions.
func (*MessageDescriptor) FindFieldByNumber ¶
func (md *MessageDescriptor) FindFieldByNumber(tagNumber int32) *FieldDescriptor
FindFieldByNumber finds the field with the given tag number. If no such field exists then nil is returned. Only regular fields are returned, not extensions.
func (*MessageDescriptor) GetExtensionRanges ¶
func (md *MessageDescriptor) GetExtensionRanges() []proto.ExtensionRange
GetExtensionRanges returns the ranges of extension field numbers for this message.
func (*MessageDescriptor) GetFields ¶
func (md *MessageDescriptor) GetFields() []*FieldDescriptor
GetFields returns all of the fields for this message.
func (*MessageDescriptor) GetFile ¶
func (md *MessageDescriptor) GetFile() *FileDescriptor
func (*MessageDescriptor) GetFullyQualifiedName ¶
func (md *MessageDescriptor) GetFullyQualifiedName() string
func (*MessageDescriptor) GetMessageOptions ¶
func (md *MessageDescriptor) GetMessageOptions() *dpb.MessageOptions
func (*MessageDescriptor) GetName ¶
func (md *MessageDescriptor) GetName() string
func (*MessageDescriptor) GetNestedEnumTypes ¶
func (md *MessageDescriptor) GetNestedEnumTypes() []*EnumDescriptor
GetNestedEnumTypes returns all of the enums declared inside this message.
func (*MessageDescriptor) GetNestedExtensions ¶
func (md *MessageDescriptor) GetNestedExtensions() []*FieldDescriptor
GetNestedExtensions returns all of the extensions declared inside this message.
func (*MessageDescriptor) GetNestedMessageTypes ¶
func (md *MessageDescriptor) GetNestedMessageTypes() []*MessageDescriptor
GetNestedMessageTypes returns all of the message types declared inside this message.
func (*MessageDescriptor) GetOneOfs ¶
func (md *MessageDescriptor) GetOneOfs() []*OneOfDescriptor
GetOneOfs returns all of the one-of field sets declared inside this message.
func (*MessageDescriptor) GetOptions ¶
func (md *MessageDescriptor) GetOptions() proto.Message
func (*MessageDescriptor) GetParent ¶
func (md *MessageDescriptor) GetParent() Descriptor
func (*MessageDescriptor) GetSourceInfo ¶
func (md *MessageDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
func (*MessageDescriptor) IsExtendable ¶
func (md *MessageDescriptor) IsExtendable() bool
IsExtendable returns true if this message has any extension ranges.
func (*MessageDescriptor) IsExtension ¶
func (md *MessageDescriptor) IsExtension(tagNumber int32) bool
IsExtension returns true if the given tag number is within any of this message's extension ranges.
func (*MessageDescriptor) IsMapEntry ¶
func (md *MessageDescriptor) IsMapEntry() bool
IsMapEntry returns true if this is a synthetic message type that represents an entry in a map field.
func (*MessageDescriptor) IsProto3 ¶
func (md *MessageDescriptor) IsProto3() bool
IsProto3 returns true if the file in which this message is defined declares a syntax of "proto3".
func (*MessageDescriptor) String ¶
func (md *MessageDescriptor) String() string
type MethodDescriptor ¶
type MethodDescriptor struct {
// contains filtered or unexported fields
}
MethodDescriptor describes an RPC method declared in a proto file.
func (*MethodDescriptor) AsMethodDescriptorProto ¶
func (md *MethodDescriptor) AsMethodDescriptorProto() *dpb.MethodDescriptorProto
func (*MethodDescriptor) AsProto ¶
func (md *MethodDescriptor) AsProto() proto.Message
func (*MethodDescriptor) GetFile ¶
func (md *MethodDescriptor) GetFile() *FileDescriptor
func (*MethodDescriptor) GetFullyQualifiedName ¶
func (md *MethodDescriptor) GetFullyQualifiedName() string
func (*MethodDescriptor) GetInputType ¶
func (md *MethodDescriptor) GetInputType() *MessageDescriptor
GetInputType returns the input type, or request type, of the RPC method.
func (*MethodDescriptor) GetMethodOptions ¶
func (md *MethodDescriptor) GetMethodOptions() *dpb.MethodOptions
func (*MethodDescriptor) GetName ¶
func (md *MethodDescriptor) GetName() string
func (*MethodDescriptor) GetOptions ¶
func (md *MethodDescriptor) GetOptions() proto.Message
func (*MethodDescriptor) GetOutputType ¶
func (md *MethodDescriptor) GetOutputType() *MessageDescriptor
GetOutputType returns the output type, or response type, of the RPC method.
func (*MethodDescriptor) GetParent ¶
func (md *MethodDescriptor) GetParent() Descriptor
func (*MethodDescriptor) GetService ¶
func (md *MethodDescriptor) GetService() *ServiceDescriptor
GetService returns the RPC service in which this method is declared.
func (*MethodDescriptor) GetSourceInfo ¶
func (md *MethodDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
func (*MethodDescriptor) IsClientStreaming ¶
func (md *MethodDescriptor) IsClientStreaming() bool
IsClientStreaming returns true if this is a client-streaming method.
func (*MethodDescriptor) IsServerStreaming ¶
func (md *MethodDescriptor) IsServerStreaming() bool
IsServerStreaming returns true if this is a server-streaming method.
func (*MethodDescriptor) String ¶
func (md *MethodDescriptor) String() string
type OneOfDescriptor ¶
type OneOfDescriptor struct {
// contains filtered or unexported fields
}
OneOfDescriptor describes a one-of field set declared in a protocol buffer message.
func (*OneOfDescriptor) AsOneofDescriptorProto ¶
func (od *OneOfDescriptor) AsOneofDescriptorProto() *dpb.OneofDescriptorProto
func (*OneOfDescriptor) AsProto ¶
func (od *OneOfDescriptor) AsProto() proto.Message
func (*OneOfDescriptor) GetChoices ¶
func (od *OneOfDescriptor) GetChoices() []*FieldDescriptor
GetChoices returns the fields that are part of the one-of field set. At most one of these fields may be set for a given message.
func (*OneOfDescriptor) GetFile ¶
func (od *OneOfDescriptor) GetFile() *FileDescriptor
func (*OneOfDescriptor) GetFullyQualifiedName ¶
func (od *OneOfDescriptor) GetFullyQualifiedName() string
func (*OneOfDescriptor) GetName ¶
func (od *OneOfDescriptor) GetName() string
func (*OneOfDescriptor) GetOneOfOptions ¶
func (od *OneOfDescriptor) GetOneOfOptions() *dpb.OneofOptions
func (*OneOfDescriptor) GetOptions ¶
func (od *OneOfDescriptor) GetOptions() proto.Message
func (*OneOfDescriptor) GetOwner ¶
func (od *OneOfDescriptor) GetOwner() *MessageDescriptor
GetOwner returns the message to which this one-of field set belongs.
func (*OneOfDescriptor) GetParent ¶
func (od *OneOfDescriptor) GetParent() Descriptor
func (*OneOfDescriptor) GetSourceInfo ¶
func (od *OneOfDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
func (*OneOfDescriptor) String ¶
func (od *OneOfDescriptor) String() string
type ServiceDescriptor ¶
type ServiceDescriptor struct {
// contains filtered or unexported fields
}
ServiceDescriptor describes an RPC service declared in a proto file.
func (*ServiceDescriptor) AsProto ¶
func (sd *ServiceDescriptor) AsProto() proto.Message
func (*ServiceDescriptor) AsServiceDescriptorProto ¶
func (sd *ServiceDescriptor) AsServiceDescriptorProto() *dpb.ServiceDescriptorProto
func (*ServiceDescriptor) FindMethodByName ¶
func (sd *ServiceDescriptor) FindMethodByName(name string) *MethodDescriptor
FindMethodByName finds the method with the given name. If no such method exists then nil is returned.
func (*ServiceDescriptor) GetFile ¶
func (sd *ServiceDescriptor) GetFile() *FileDescriptor
func (*ServiceDescriptor) GetFullyQualifiedName ¶
func (sd *ServiceDescriptor) GetFullyQualifiedName() string
func (*ServiceDescriptor) GetMethods ¶
func (sd *ServiceDescriptor) GetMethods() []*MethodDescriptor
GetMethods returns all of the RPC methods for this service.
func (*ServiceDescriptor) GetName ¶
func (sd *ServiceDescriptor) GetName() string
func (*ServiceDescriptor) GetOptions ¶
func (sd *ServiceDescriptor) GetOptions() proto.Message
func (*ServiceDescriptor) GetParent ¶
func (sd *ServiceDescriptor) GetParent() Descriptor
func (*ServiceDescriptor) GetServiceOptions ¶
func (sd *ServiceDescriptor) GetServiceOptions() *dpb.ServiceOptions
func (*ServiceDescriptor) GetSourceInfo ¶
func (sd *ServiceDescriptor) GetSourceInfo() *dpb.SourceCodeInfo_Location
func (*ServiceDescriptor) String ¶
func (sd *ServiceDescriptor) String() string
Directories ¶
Path | Synopsis |
---|---|
Package builder contains a means of building and modifying proto descriptors programmatically.
|
Package builder contains a means of building and modifying proto descriptors programmatically. |
Package protoparse provides functionality for parsing *.proto source files into descriptors that can be used with other protoreflect packages, like dynamic messages and dynamic GRPC clients.
|
Package protoparse provides functionality for parsing *.proto source files into descriptors that can be used with other protoreflect packages, like dynamic messages and dynamic GRPC clients. |