Documentation ¶
Overview ¶
Package protoutil contains useful functions for interacting with descriptors. For now these include only functions for efficiently converting descriptors produced by the compiler to descriptor protos.
Despite the fact that descriptor protos are mutable, calling code should NOT mutate any of the protos returned from this package. For efficiency, some protos returned from this package may be part of internal state of a compiler result, and mutating the proto could corrupt or invalidate parts of that result.
Index ¶
- func ProtoFromDescriptor(d protoreflect.Descriptor) proto.Message
- func ProtoFromEnumDescriptor(d protoreflect.EnumDescriptor) *descriptorpb.EnumDescriptorProto
- func ProtoFromEnumValueDescriptor(d protoreflect.EnumValueDescriptor) *descriptorpb.EnumValueDescriptorProto
- func ProtoFromFieldDescriptor(d protoreflect.FieldDescriptor) *descriptorpb.FieldDescriptorProto
- func ProtoFromFileDescriptor(d protoreflect.FileDescriptor) *descriptorpb.FileDescriptorProto
- func ProtoFromMessageDescriptor(d protoreflect.MessageDescriptor) *descriptorpb.DescriptorProto
- func ProtoFromMethodDescriptor(d protoreflect.MethodDescriptor) *descriptorpb.MethodDescriptorProto
- func ProtoFromOneofDescriptor(d protoreflect.OneofDescriptor) *descriptorpb.OneofDescriptorProto
- func ProtoFromServiceDescriptor(d protoreflect.ServiceDescriptor) *descriptorpb.ServiceDescriptorProto
- type DescriptorProtoWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ProtoFromDescriptor ¶
func ProtoFromDescriptor(d protoreflect.Descriptor) proto.Message
ProtoFromDescriptor extracts a descriptor proto from the given "rich" descriptor. For descriptors generated by the compiler, this is an inexpensive and non-lossy operation. Descriptors from other sources however may be expensive (to re-create a proto) and even lossy.
func ProtoFromEnumDescriptor ¶
func ProtoFromEnumDescriptor(d protoreflect.EnumDescriptor) *descriptorpb.EnumDescriptorProto
ProtoFromEnumDescriptor extracts a descriptor proto from the given "rich" descriptor. For enum descriptors generated by the compiler, this is an inexpensive and non-lossy operation. Enum descriptors from other sources however may be expensive (to re-create a proto) and even lossy.
func ProtoFromEnumValueDescriptor ¶
func ProtoFromEnumValueDescriptor(d protoreflect.EnumValueDescriptor) *descriptorpb.EnumValueDescriptorProto
ProtoFromEnumValueDescriptor extracts a descriptor proto from the given "rich" descriptor. For enum value descriptors generated by the compiler, this is an inexpensive and non-lossy operation. Enum value descriptors from other sources however may be expensive (to re-create a proto) and even lossy.
func ProtoFromFieldDescriptor ¶
func ProtoFromFieldDescriptor(d protoreflect.FieldDescriptor) *descriptorpb.FieldDescriptorProto
ProtoFromFieldDescriptor extracts a descriptor proto from the given "rich" descriptor. For field descriptors generated by the compiler, this is an inexpensive and non-lossy operation. Field descriptors from other sources however may be expensive (to re-create a proto) and even lossy.
func ProtoFromFileDescriptor ¶
func ProtoFromFileDescriptor(d protoreflect.FileDescriptor) *descriptorpb.FileDescriptorProto
ProtoFromFileDescriptor extracts a descriptor proto from the given "rich" descriptor. For file descriptors generated by the compiler, this is an inexpensive and non-lossy operation. File descriptors from other sources however may be expensive (to re-create a proto) and even lossy.
func ProtoFromMessageDescriptor ¶
func ProtoFromMessageDescriptor(d protoreflect.MessageDescriptor) *descriptorpb.DescriptorProto
ProtoFromMessageDescriptor extracts a descriptor proto from the given "rich" descriptor. For message descriptors generated by the compiler, this is an inexpensive and non-lossy operation. Message descriptors from other sources however may be expensive (to re-create a proto) and even lossy.
func ProtoFromMethodDescriptor ¶
func ProtoFromMethodDescriptor(d protoreflect.MethodDescriptor) *descriptorpb.MethodDescriptorProto
ProtoFromMethodDescriptor extracts a descriptor proto from the given "rich" descriptor. For method descriptors generated by the compiler, this is an inexpensive and non-lossy operation. Method descriptors from other sources however may be expensive (to re-create a proto) and even lossy.
func ProtoFromOneofDescriptor ¶
func ProtoFromOneofDescriptor(d protoreflect.OneofDescriptor) *descriptorpb.OneofDescriptorProto
ProtoFromOneofDescriptor extracts a descriptor proto from the given "rich" descriptor. For oneof descriptors generated by the compiler, this is an inexpensive and non-lossy operation. Oneof descriptors from other sources however may be expensive (to re-create a proto) and even lossy.
func ProtoFromServiceDescriptor ¶
func ProtoFromServiceDescriptor(d protoreflect.ServiceDescriptor) *descriptorpb.ServiceDescriptorProto
ProtoFromServiceDescriptor extracts a descriptor proto from the given "rich" descriptor. For service descriptors generated by the compiler, this is an inexpensive and non-lossy operation. Service descriptors from other sources however may be expensive (to re-create a proto) and even lossy.
Types ¶
type DescriptorProtoWrapper ¶
type DescriptorProtoWrapper interface { protoreflect.Descriptor // AsProto returns the underlying descriptor proto. The concrete // type of the proto message depends on the type of this // descriptor: // Descriptor Type Proto Message Type // ---------------------+------------------------------------ // FileDescriptor | *descriptorpb.FileDescriptorProto // MessageDescriptor | *descriptorpb.DescriptorProto // FieldDescriptor | *descriptorpb.FieldDescriptorProto // OneofDescriptor | *descriptorpb.OneofDescriptorProto // EnumDescriptor | *descriptorpb.EnumDescriptorProto // EnumValueDescriptor | *descriptorpb.EnumValueDescriptorProto // ServiceDescriptor | *descriptorpb.ServiceDescriptorProto // MethodDescriptor | *descriptorpb.MethodDescriptorProto AsProto() proto.Message }
DescriptorProtoWrapper is a protoreflect.Descriptor that wraps an underlying descriptor proto. It provides the same interface as Descriptor but with one extra operation, to efficiently query for the underlying descriptor proto.
Descriptors that implement this will also implement another method whose specified return type is the concrete type returned by the AsProto method. The name of this method varies by the type of this descriptor:
Descriptor Type Other Method Name ---------------------+------------------------------------ FileDescriptor | FileDescriptorProto() MessageDescriptor | MessageDescriptorProto() FieldDescriptor | FieldDescriptorProto() OneofDescriptor | OneofDescriptorProto() EnumDescriptor | EnumDescriptorProto() EnumValueDescriptor | EnumValueDescriptorProto() ServiceDescriptor | ServiceDescriptorProto() MethodDescriptor | MethodDescriptorProto()
For example, a DescriptorProtoWrapper that implements FileDescriptor returns a *descriptorpb.FileDescriptorProto value from its AsProto method and also provides a method with the following signature:
FileDescriptorProto() *descriptorpb.FileDescriptorProto