protoutil

package
v0.0.0-...-6cf7a4f Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 14, 2024 License: Apache-2.0 Imports: 4 Imported by: 1

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

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

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

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

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

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

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL