Documentation ¶
Overview ¶
Package descutil contains utility functions for protobuf descriptor messages.
Index ¶
- Constants
- func At(descProto proto.Message, path []int32) (interface{}, error)
- func FindEnum(d *pb.DescriptorProto, name string) int
- func FindEnumForFile(f *pb.FileDescriptorProto, name string) int
- func FindEnumValue(e *pb.EnumDescriptorProto, name string) int
- func FindField(d *pb.DescriptorProto, name string) int
- func FindFile(s *pb.FileDescriptorSet, name string) int
- func FindMessage(d *pb.DescriptorProto, name string) int
- func FindMessageForFile(f *pb.FileDescriptorProto, name string) int
- func FindMethodForService(s *pb.ServiceDescriptorProto, name string) int
- func FindOneOf(d *pb.DescriptorProto, name string) int
- func FindService(s *pb.FileDescriptorSet, fullName string) (file *pb.FileDescriptorProto, serviceIndex int)
- func FindServiceForFile(f *pb.FileDescriptorProto, name string) int
- func FindValueByNumber(e *pb.EnumDescriptorProto, number int32) int
- func IndexSourceCodeInfo(f *pb.FileDescriptorProto) (map[interface{}]*pb.SourceCodeInfo_Location, error)
- func Repeated(f *pb.FieldDescriptorProto) bool
- func Required(f *pb.FieldDescriptorProto) bool
- func Resolve(s *pb.FileDescriptorSet, fullName string) (file *pb.FileDescriptorProto, obj interface{}, path []int)
Constants ¶
const ( // FileDescriptorProtoPackageTag is the number of package field // in FileDescriptorProto message. FileDescriptorProtoPackageTag = 2 // FileDescriptorProtoMessageTag is the number of message field // in FileDescriptorProto message. FileDescriptorProtoMessageTag = 4 // FileDescriptorProtoEnumTag is the number of enum field // in FileDescriptorProto message. FileDescriptorProtoEnumTag = 5 // FileDescriptorProtoServiceTag is the number of service field // in FileDescriptorProto message. FileDescriptorProtoServiceTag = 6 // ServiceDescriptorProtoMethodTag is the number of method field // in ServiceDescriptorProto message. ServiceDescriptorProtoMethodTag = 2 // DescriptorProtoFieldTag is the number of field field // in DescriptorProto message. DescriptorProtoFieldTag = 2 // DescriptorProtoNestedTypeTag is the number of nested_type field // in DescriptorProto message. DescriptorProtoNestedTypeTag = 3 // DescriptorProtoEnumTypeTag is the number of enum_type field // in DescriptorProto message. DescriptorProtoEnumTypeTag = 4 // DescriptorProtoOneOfTag is the number of oneof_decl field // in DescriptorProto message. DescriptorProtoOneOfTag = 8 // EnumDescriptorProtoValueTag is the number of value field // in EnumDescriptorProto message. EnumDescriptorProtoValueTag = 2 )
These constnats correspond to tag values in the respective "descriptor.proto" message types. These constants' tag matches are asserted in the "TestTagsMatchProto" unit test.
Variables ¶
This section is empty.
Functions ¶
func At ¶
At returns a descriptor proto or its field value at the given path. The path has same semantics as descriptor.SourceCodeInfo_Location.Path. See its comment for explanation.
For example, given a FileDescriptorProto and path [4, 2], At will return the 2nd top-level message DescriptorProto because 4 is FileDescriptorProto.MessageType field tag.
Does not supported uninterpreted options, returns (nil, nil).
func FindEnum ¶
func FindEnum(d *pb.DescriptorProto, name string) int
FindEnum searches for a nested EnumDescriptorProto by name.
func FindEnumForFile ¶
func FindEnumForFile(f *pb.FileDescriptorProto, name string) int
FindEnumForFile searches for an EnumDescriptorProto by name.
func FindEnumValue ¶
func FindEnumValue(e *pb.EnumDescriptorProto, name string) int
FindEnumValue searches for an EnumValueDescriptorProto by name.
func FindField ¶
func FindField(d *pb.DescriptorProto, name string) int
FindField searches for a FieldDescriptorProto by name.
func FindFile ¶
func FindFile(s *pb.FileDescriptorSet, name string) int
FindFile searches for a FileDescriptorProto by name.
func FindMessage ¶
func FindMessage(d *pb.DescriptorProto, name string) int
FindMessage searches for a nested DescriptorProto by name.
func FindMessageForFile ¶
func FindMessageForFile(f *pb.FileDescriptorProto, name string) int
FindMessageForFile searches for a DescriptorProto by name.
func FindMethodForService ¶
func FindMethodForService(s *pb.ServiceDescriptorProto, name string) int
FindMethodForService searches for a MethodDescriptorProto by name.
func FindOneOf ¶
func FindOneOf(d *pb.DescriptorProto, name string) int
FindOneOf searches for a nested OneofDescriptorProto by name.
func FindService ¶
func FindService(s *pb.FileDescriptorSet, fullName string) (file *pb.FileDescriptorProto, serviceIndex int)
FindService searches for a service by full name.
func FindServiceForFile ¶
func FindServiceForFile(f *pb.FileDescriptorProto, name string) int
FindServiceForFile searches for a FileDescriptorProto by name.
func FindValueByNumber ¶
func FindValueByNumber(e *pb.EnumDescriptorProto, number int32) int
FindValueByNumber searches for an EnumValueDescriptorProto by number.
func IndexSourceCodeInfo ¶
func IndexSourceCodeInfo(f *pb.FileDescriptorProto) (map[interface{}]*pb.SourceCodeInfo_Location, error)
IndexSourceCodeInfo returns a map that maps a pointer to the associated source code info, where the pointer points to a descriptor proto or its field, e.g. &myFieldDescriptorProto.Name.
IndexSourceCodeInfo can be used to retrieve comments.
Does not support whole-slice locations.
func Repeated ¶
func Repeated(f *pb.FieldDescriptorProto) bool
Repeated returns true if the field is repeated.
func Required ¶
func Required(f *pb.FieldDescriptorProto) bool
Required returns true if the field is required.
func Resolve ¶
func Resolve(s *pb.FileDescriptorSet, fullName string) (file *pb.FileDescriptorProto, obj interface{}, path []int)
Resolve searches for an object by full name. obj can be one of *ServiceDescriptorProto, *MethodDescriptorProto, *DescriptorProto, *FieldDescriptorProto, *DescriptorProto, *EnumDescriptorProto, *EnumValueDescriptorProto or nil
For path, see comment in SourceCodeInfo message.
Types ¶
This section is empty.