protodesc
packageThis package is not in the latest version of its module.
Details
Validgo.mod file
The Go module system was introduced in Go 1.11 and is the official dependency management solution for Go.
Redistributable license
Redistributable licenses place minimal restrictions on how software can be used, modified, and redistributed.
Tagged version
Modules with tagged versions give importers more predictable builds.
Stable version
When a project reaches major version v1 it is considered stable.
- Learn more about best practices
Repository
Links
Documentation¶
Overview¶
Package protodesc provides functionality for convertingFileDescriptorProto messages to/fromprotoreflect.FileDescriptor values.
The google.protobuf.FileDescriptorProto is a protobuf message that describesthe type information for a .proto file in a form that is easily serializable.Theprotoreflect.FileDescriptor is a more structured representation ofthe FileDescriptorProto message where references and remote dependenciescan be directly followed.
Index¶
- func NewFile(fd *descriptorpb.FileDescriptorProto, r Resolver) (protoreflect.FileDescriptor, error)
- func NewFiles(fd *descriptorpb.FileDescriptorSet) (*protoregistry.Files, error)
- func ToDescriptorProto(message protoreflect.MessageDescriptor) *descriptorpb.DescriptorProto
- func ToEnumDescriptorProto(enum protoreflect.EnumDescriptor) *descriptorpb.EnumDescriptorProto
- func ToEnumValueDescriptorProto(value protoreflect.EnumValueDescriptor) *descriptorpb.EnumValueDescriptorProto
- func ToFieldDescriptorProto(field protoreflect.FieldDescriptor) *descriptorpb.FieldDescriptorProto
- func ToFileDescriptorProto(file protoreflect.FileDescriptor) *descriptorpb.FileDescriptorProto
- func ToMethodDescriptorProto(method protoreflect.MethodDescriptor) *descriptorpb.MethodDescriptorProto
- func ToOneofDescriptorProto(oneof protoreflect.OneofDescriptor) *descriptorpb.OneofDescriptorProto
- func ToServiceDescriptorProto(service protoreflect.ServiceDescriptor) *descriptorpb.ServiceDescriptorProto
- type FileOptions
- type Resolver
Constants¶
This section is empty.
Variables¶
This section is empty.
Functions¶
funcNewFile¶
func NewFile(fd *descriptorpb.FileDescriptorProto, rResolver) (protoreflect.FileDescriptor,error)
NewFile creates a newprotoreflect.FileDescriptor from the providedfile descriptor message. SeeFileOptions.New for more information.
funcNewFiles¶added inv1.21.0
func NewFiles(fd *descriptorpb.FileDescriptorSet) (*protoregistry.Files,error)
NewFiles creates a newprotoregistry.Files from the providedFileDescriptorSet message. SeeFileOptions.NewFiles for more information.
funcToDescriptorProto¶
func ToDescriptorProto(messageprotoreflect.MessageDescriptor) *descriptorpb.DescriptorProto
ToDescriptorProto copies aprotoreflect.MessageDescriptor into agoogle.protobuf.DescriptorProto message.
funcToEnumDescriptorProto¶
func ToEnumDescriptorProto(enumprotoreflect.EnumDescriptor) *descriptorpb.EnumDescriptorProto
ToEnumDescriptorProto copies aprotoreflect.EnumDescriptor into agoogle.protobuf.EnumDescriptorProto message.
funcToEnumValueDescriptorProto¶
func ToEnumValueDescriptorProto(valueprotoreflect.EnumValueDescriptor) *descriptorpb.EnumValueDescriptorProto
ToEnumValueDescriptorProto copies aprotoreflect.EnumValueDescriptor into agoogle.protobuf.EnumValueDescriptorProto message.
funcToFieldDescriptorProto¶
func ToFieldDescriptorProto(fieldprotoreflect.FieldDescriptor) *descriptorpb.FieldDescriptorProto
ToFieldDescriptorProto copies aprotoreflect.FieldDescriptor into agoogle.protobuf.FieldDescriptorProto message.
funcToFileDescriptorProto¶
func ToFileDescriptorProto(fileprotoreflect.FileDescriptor) *descriptorpb.FileDescriptorProto
ToFileDescriptorProto copies aprotoreflect.FileDescriptor into agoogle.protobuf.FileDescriptorProto message.
funcToMethodDescriptorProto¶
func ToMethodDescriptorProto(methodprotoreflect.MethodDescriptor) *descriptorpb.MethodDescriptorProto
ToMethodDescriptorProto copies aprotoreflect.MethodDescriptor into agoogle.protobuf.MethodDescriptorProto message.
funcToOneofDescriptorProto¶
func ToOneofDescriptorProto(oneofprotoreflect.OneofDescriptor) *descriptorpb.OneofDescriptorProto
ToOneofDescriptorProto copies aprotoreflect.OneofDescriptor into agoogle.protobuf.OneofDescriptorProto message.
funcToServiceDescriptorProto¶
func ToServiceDescriptorProto(serviceprotoreflect.ServiceDescriptor) *descriptorpb.ServiceDescriptorProto
ToServiceDescriptorProto copies aprotoreflect.ServiceDescriptor into agoogle.protobuf.ServiceDescriptorProto message.
Types¶
typeFileOptions¶
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.AllowUnresolvablebool}FileOptions configures the construction of file descriptors.
func (FileOptions)New¶
func (oFileOptions) New(fd *descriptorpb.FileDescriptorProto, rResolver) (protoreflect.FileDescriptor,error)
New creates a newprotoreflect.FileDescriptor from the providedfile descriptor message. The file must represent a valid proto file accordingto protobuf semantics. The returned descriptor is a deep copy of the input.
Any imported files, enum types, or message types referenced in the file areresolved using the provided registry. When looking up an import file path,the path must be unique. The newly created file descriptor is not registeredback into the provided file registry.
func (FileOptions)NewFiles¶added inv1.21.0
func (oFileOptions) NewFiles(fds *descriptorpb.FileDescriptorSet) (*protoregistry.Files,error)
NewFiles creates a newprotoregistry.Files from the providedFileDescriptorSet message. The descriptor set must include onlyvalid files according to protobuf semantics. The returned descriptorsare a deep copy of the input.
typeResolver¶
type Resolver interface {FindFileByPath(string) (protoreflect.FileDescriptor,error)FindDescriptorByName(protoreflect.FullName) (protoreflect.Descriptor,error)}Resolver is the resolver used byNewFile to resolve dependencies.The enums and messages provided must belong to some parent file,which is also registered.
It is implemented byprotoregistry.Files.