protodesc

package
v8.1.1+incompatible Latest Latest
Warning

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

Go to latest
Published: Nov 29, 2021 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package protodesc provides functionality for converting FileDescriptorProto messages to/from protoreflect.FileDescriptor values.

The google.protobuf.FileDescriptorProto is a protobuf message that describes the type information for a .proto file in a form that is easily serializable. The protoreflect.FileDescriptor is a more structured representation of the FileDescriptorProto message where references and remote dependencies can be directly followed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewFile

NewFile creates a new protoreflect.FileDescriptor from the provided file descriptor message. See FileOptions.New for more information.

func NewFiles

NewFiles creates a new protoregistry.Files from the provided FileDescriptorSet message. See FileOptions.NewFiles for more information.

func ToDescriptorProto

func ToDescriptorProto(message protoreflect.MessageDescriptor) *descriptorpb.DescriptorProto

ToDescriptorProto copies a protoreflect.MessageDescriptor into a google.protobuf.DescriptorProto message.

func ToEnumDescriptorProto

func ToEnumDescriptorProto(enum protoreflect.EnumDescriptor) *descriptorpb.EnumDescriptorProto

ToEnumDescriptorProto copies a protoreflect.EnumDescriptor into a google.protobuf.EnumDescriptorProto message.

func ToEnumValueDescriptorProto

func ToEnumValueDescriptorProto(value protoreflect.EnumValueDescriptor) *descriptorpb.EnumValueDescriptorProto

ToEnumValueDescriptorProto copies a protoreflect.EnumValueDescriptor into a google.protobuf.EnumValueDescriptorProto message.

func ToFieldDescriptorProto

func ToFieldDescriptorProto(field protoreflect.FieldDescriptor) *descriptorpb.FieldDescriptorProto

ToFieldDescriptorProto copies a protoreflect.FieldDescriptor into a google.protobuf.FieldDescriptorProto message.

func ToFileDescriptorProto

func ToFileDescriptorProto(file protoreflect.FileDescriptor) *descriptorpb.FileDescriptorProto

ToFileDescriptorProto copies a protoreflect.FileDescriptor into a google.protobuf.FileDescriptorProto message.

func ToMethodDescriptorProto

func ToMethodDescriptorProto(method protoreflect.MethodDescriptor) *descriptorpb.MethodDescriptorProto

ToMethodDescriptorProto copies a protoreflect.MethodDescriptor into a google.protobuf.MethodDescriptorProto message.

func ToOneofDescriptorProto

func ToOneofDescriptorProto(oneof protoreflect.OneofDescriptor) *descriptorpb.OneofDescriptorProto

ToOneofDescriptorProto copies a protoreflect.OneofDescriptor into a google.protobuf.OneofDescriptorProto message.

func ToServiceDescriptorProto

func ToServiceDescriptorProto(service protoreflect.ServiceDescriptor) *descriptorpb.ServiceDescriptorProto

ToServiceDescriptorProto copies a protoreflect.ServiceDescriptor into a google.protobuf.ServiceDescriptorProto message.

Types

type FileOptions

type FileOptions struct {
	pragma.NoUnkeyedLiterals

	// AllowUnresolvable configures New to permissively allow unresolvable
	// file, enum, or message dependencies. Unresolved dependencies are replaced
	// by placeholder equivalents.
	//
	// The following dependencies may be left unresolved:
	//	• Resolving an imported file.
	//	• Resolving the type for a message field or extension field.
	//	If the kind of the field is unknown, then a placeholder is used for both
	//	the Enum and Message accessors on the protoreflect.FieldDescriptor.
	//	• Resolving an enum value set as the default for an optional enum field.
	//	If unresolvable, the protoreflect.FieldDescriptor.Default is set to the
	//	first value in the associated enum (or zero if the also enum dependency
	//	is also unresolvable). The protoreflect.FieldDescriptor.DefaultEnumValue
	//	is populated with a placeholder.
	//	• Resolving the extended message type for an extension field.
	//	• Resolving the input or output message type for a service method.
	//
	// If the unresolved dependency uses a relative name,
	// then the placeholder will contain an invalid FullName with a "*." prefix,
	// indicating that the starting prefix of the full name is unknown.
	AllowUnresolvable bool
}

FileOptions configures the construction of file descriptors.

func (FileOptions) New

New creates a new protoreflect.FileDescriptor from the provided file descriptor message. The file must represent a valid proto file according to protobuf semantics. The returned descriptor is a deep copy of the input.

Any imported files, enum types, or message types referenced in the file are resolved using the provided registry. When looking up an import file path, the path must be unique. The newly created file descriptor is not registered back into the provided file registry.

func (FileOptions) NewFiles

NewFiles creates a new protoregistry.Files from the provided FileDescriptorSet message. The descriptor set must include only valid files according to protobuf semantics. The returned descriptors are a deep copy of the input.

type Resolver

type Resolver interface {
	FindFileByPath(string) (protoreflect.FileDescriptor, error)
	FindDescriptorByName(protoreflect.FullName) (protoreflect.Descriptor, error)
}

Resolver is the resolver used by NewFile to resolve dependencies. The enums and messages provided must belong to some parent file, which is also registered.

It is implemented by protoregistry.Files.

Jump to

Keyboard shortcuts

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