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, these build-in descriptors cannot refer to their 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). All such links must instead be stringly typed. This limitation makes them much harder to use for doing interesting things with reflection.
Without this package, resolving references to types is particularly complex. For example, resolving a field's type, the message type an extension extends, or the request and response types of an RPC method all require searching through symbols defined not only in the file in which these elements are declared but also in its transitive closure of dependencies.
"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 ¶
- Constants
- func GetBoolExtension(pb proto.Message, ext interface{}, def bool) bool
- func GetExtension(pb proto.Message, ext interface{}) (interface{}, error)
- func LoadServiceDescriptors(s *grpc.Server) (map[string]*ServiceDescriptor, error)
- type Descriptor
- type EnumDescriptor
- func (ed *EnumDescriptor) FindValueByName(name string) *EnumValueDescriptor
- func (ed *EnumDescriptor) FindValueByNumber(num int32) *EnumValueDescriptor
- func (ed *EnumDescriptor) GetFile() *FileDescriptor
- func (ed *EnumDescriptor) GetFullyQualifiedName() string
- func (ed *EnumDescriptor) GetName() string
- func (ed *EnumDescriptor) GetParent() Descriptor
- func (ed *EnumDescriptor) GetValues() []*EnumValueDescriptor
- func (ed *EnumDescriptor) String() string
- type EnumValueDescriptor
- func (vd *EnumValueDescriptor) GetEnum() *EnumDescriptor
- func (vd *EnumValueDescriptor) GetFile() *FileDescriptor
- func (vd *EnumValueDescriptor) GetFullyQualifiedName() string
- func (vd *EnumValueDescriptor) GetName() string
- func (vd *EnumValueDescriptor) GetNumber() int32
- func (vd *EnumValueDescriptor) GetParent() Descriptor
- func (vd *EnumValueDescriptor) String() string
- type FieldDescriptor
- func (fd *FieldDescriptor) GetDefaultValue() interface{}
- func (fd *FieldDescriptor) GetEnumType() *EnumDescriptor
- func (fd *FieldDescriptor) GetFile() *FileDescriptor
- func (fd *FieldDescriptor) GetFullyQualifiedJSONName() string
- func (fd *FieldDescriptor) GetFullyQualifiedName() string
- func (fd *FieldDescriptor) GetJSONName() string
- 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) GetOwner() *MessageDescriptor
- func (fd *FieldDescriptor) GetParent() Descriptor
- 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) 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) GetFullyQualifiedName() string
- func (fd *FileDescriptor) GetMessageTypes() []*MessageDescriptor
- func (fd *FileDescriptor) GetName() string
- func (fd *FileDescriptor) GetPackage() string
- func (fd *FileDescriptor) GetParent() Descriptor
- func (fd *FileDescriptor) GetPublicDependencies() []*FileDescriptor
- func (fd *FileDescriptor) GetServices() []*ServiceDescriptor
- func (fd *FileDescriptor) GetWeakDependencies() []*FileDescriptor
- func (fd *FileDescriptor) IsProto3() bool
- func (fd *FileDescriptor) String() string
- type InterceptorInfo
- type InterceptorInfoEntry
- type MessageDescriptor
- func (md *MessageDescriptor) FindFieldByName(fieldName string) *FieldDescriptor
- func (md *MessageDescriptor) FindFieldByNumber(tagNumber int32) *FieldDescriptor
- func (md *MessageDescriptor) GetFields() []*FieldDescriptor
- func (md *MessageDescriptor) GetFile() *FileDescriptor
- func (md *MessageDescriptor) GetFullyQualifiedName() string
- 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) GetParent() Descriptor
- func (md *MessageDescriptor) IsMapEntry() bool
- func (md *MessageDescriptor) IsProto3() bool
- func (md *MessageDescriptor) String() string
- type MethodDescriptor
- func (md *MethodDescriptor) GetBoolExtension(ext interface{}, def bool) bool
- func (md *MethodDescriptor) GetExtension(ext interface{}) (extval interface{}, err error)
- func (md *MethodDescriptor) GetFile() *FileDescriptor
- func (md *MethodDescriptor) GetFullyQualifiedName() string
- func (md *MethodDescriptor) GetInputType() *MessageDescriptor
- func (md *MethodDescriptor) GetName() string
- func (md *MethodDescriptor) GetOutputType() *MessageDescriptor
- func (md *MethodDescriptor) GetParent() Descriptor
- func (md *MethodDescriptor) GetService() *ServiceDescriptor
- func (md *MethodDescriptor) IsClientStreaming() bool
- func (md *MethodDescriptor) IsServerStreaming() bool
- func (md *MethodDescriptor) RegisteredExtensions(desiredType interface{}) (extensions interface{}, err error)
- func (md *MethodDescriptor) String() string
- type OneOfDescriptor
- func (od *OneOfDescriptor) GetChoices() []*FieldDescriptor
- func (od *OneOfDescriptor) GetFile() *FileDescriptor
- func (od *OneOfDescriptor) GetFullyQualifiedName() string
- func (od *OneOfDescriptor) GetName() string
- func (od *OneOfDescriptor) GetOwner() *MessageDescriptor
- func (od *OneOfDescriptor) GetParent() Descriptor
- func (od *OneOfDescriptor) String() string
- type ServiceDescriptor
- func (sd *ServiceDescriptor) FindMethodByName(name string) *MethodDescriptor
- func (sd *ServiceDescriptor) GetBoolExtension(field int32, def bool) bool
- func (sd *ServiceDescriptor) GetExtension(field int32) (interface{}, error)
- func (sd *ServiceDescriptor) GetFile() *FileDescriptor
- func (sd *ServiceDescriptor) GetFullyQualifiedName() string
- func (sd *ServiceDescriptor) GetMethods() []*MethodDescriptor
- func (sd *ServiceDescriptor) GetName() string
- func (sd *ServiceDescriptor) GetParent() Descriptor
- func (sd *ServiceDescriptor) String() string
Constants ¶
const ( MaxTag = 536870911 // 2^29 - 1 SpecialReservedStart = 19000 SpecialReservedEnd = 19999 // NB: It would be nice to use constants from generated code instead of hard-coding these here. // But code-gen does not emit these as constants anywhere. The only places they appear in generated // code are struct tags on fields of the generated descriptor protos. File_packageTag = 2 File_dependencyTag = 3 File_messagesTag = 4 File_enumsTag = 5 File_servicesTag = 6 File_extensionsTag = 7 File_optionsTag = 8 File_syntaxTag = 12 Message_nameTag = 1 Message_fieldsTag = 2 Message_nestedMessagesTag = 3 Message_enumsTag = 4 Message_extensionRangeTag = 5 Message_extensionsTag = 6 Message_optionsTag = 7 Message_oneOfsTag = 8 Message_reservedRangeTag = 9 Message_reservedNameTag = 10 ExtensionRange_startTag = 1 ExtensionRange_endTag = 2 ExtensionRange_optionsTag = 3 ReservedRange_startTag = 1 ReservedRange_endTag = 2 Field_nameTag = 1 Field_extendeeTag = 2 Field_numberTag = 3 Field_labelTag = 4 Field_typeTag = 5 Field_defaultTag = 7 Field_optionsTag = 8 Field_jsonNameTag = 10 OneOf_nameTag = 1 OneOf_optionsTag = 2 Enum_nameTag = 1 Enum_valuesTag = 2 Enum_optionsTag = 3 EnumVal_nameTag = 1 EnumVal_numberTag = 2 EnumVal_optionsTag = 3 Service_nameTag = 1 Service_methodsTag = 2 Service_optionsTag = 3 Method_nameTag = 1 Method_inputTag = 2 Method_outputTag = 3 Method_optionsTag = 4 Method_inputStreamTag = 5 Method_outputStreamTag = 6 // All *Options messages use the same tag for the field // that stores uninterpreted options UninterpretedOptionsTag = 999 Uninterpreted_nameTag = 2 Uninterpreted_identTag = 3 Uninterpreted_posIntTag = 4 Uninterpreted_negIntTag = 5 Uninterpreted_doubleTag = 6 Uninterpreted_stringTag = 7 Uninterpreted_aggregateTag = 8 UninterpretedName_nameTag = 1 )
Variables ¶
This section is empty.
Functions ¶
func GetExtension ¶
func LoadServiceDescriptors ¶
func LoadServiceDescriptors(s *grpc.Server) (map[string]*ServiceDescriptor, error)
LoadServiceDescriptors loads the service descriptors for all services exposed by the given GRPC server.
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 }
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) 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) GetFile ¶
func (ed *EnumDescriptor) GetFile() *FileDescriptor
func (*EnumDescriptor) GetFullyQualifiedName ¶
func (ed *EnumDescriptor) GetFullyQualifiedName() string
func (*EnumDescriptor) GetName ¶
func (ed *EnumDescriptor) GetName() string
func (*EnumDescriptor) GetParent ¶
func (ed *EnumDescriptor) GetParent() Descriptor
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) GetEnum ¶
func (vd *EnumValueDescriptor) GetEnum() *EnumDescriptor
GetEnum returns the enum in which this enum value is defined.
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) GetParent ¶
func (vd *EnumValueDescriptor) GetParent() Descriptor
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 (*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) 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) 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) 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) 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(fileDescriptorProto proto.Message, 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(fileDescriptorSet proto.Message) (*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) 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) 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) 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) 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 InterceptorInfo ¶
type InterceptorInfo struct {
// contains filtered or unexported fields
}
func LoadInterceptorInfo ¶
func LoadInterceptorInfo(svr *grpc.Server) (*InterceptorInfo, error)
func (*InterceptorInfo) Get ¶
func (info *InterceptorInfo) Get(fqn string) *InterceptorInfoEntry
type InterceptorInfoEntry ¶
type InterceptorInfoEntry struct { Service *ServiceDescriptor Method *MethodDescriptor }
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) 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) 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) 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) GetParent ¶
func (md *MessageDescriptor) GetParent() Descriptor
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) GetBoolExtension ¶
func (md *MethodDescriptor) GetBoolExtension(ext interface{}, def bool) bool
func (*MethodDescriptor) GetExtension ¶
func (md *MethodDescriptor) GetExtension(ext interface{}) (extval interface{}, err error)
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) GetName ¶
func (md *MethodDescriptor) GetName() string
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) 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) RegisteredExtensions ¶
func (md *MethodDescriptor) RegisteredExtensions(desiredType interface{}) (extensions interface{}, err error)
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) 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) 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) 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 LoadServiceDescriptor ¶
func LoadServiceDescriptor(svc *grpc.ServiceDesc) (*ServiceDescriptor, error)
LoadServiceDescriptor loads a rich descriptor for a given service description generated by protoc-gen-gogo. Generated code contains an unexported symbol with a name like "_<Service>_serviceDesc" which is the service's description. It is used internally to register a service implementation with a GRPC server. But it can also be used by this package to retrieve the rich descriptor for the service.
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) GetBoolExtension ¶
func (sd *ServiceDescriptor) GetBoolExtension(field int32, def bool) bool
func (*ServiceDescriptor) GetExtension ¶
func (sd *ServiceDescriptor) GetExtension(field int32) (interface{}, error)
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) GetParent ¶
func (sd *ServiceDescriptor) GetParent() Descriptor
func (*ServiceDescriptor) String ¶
func (sd *ServiceDescriptor) String() string