buf: github.com/bufbuild/buf/internal/pkg/protodesc Index | Files

package protodesc

import "github.com/bufbuild/buf/internal/pkg/protodesc"

Package protodesc defines minimal interfaces for Protobuf descriptor types.

This is done so that the backing package can be swapped out easily.

All values that return SourceLocation can be nil.

Testing is currently implicitly done through the bufcheck packages, however if this were to be split out into a separate library, it would need a separate testing suite

Index

Package Files

alias_types.go descriptor.go enum.go enum_value.go extension_range.go field.go file.go file_builder.go file_import.go files.go location.go location_descriptor.go location_store.go message.go method.go named_descriptor.go oneof.go paths.go protodesc.go reserved_name.go reserved_range.go service.go

Constants

const (
    // FieldDescriptorProtoTypeDouble is an alias.
    FieldDescriptorProtoTypeDouble FieldDescriptorProtoType = 1
    // FieldDescriptorProtoTypeFloat is an alias.
    FieldDescriptorProtoTypeFloat FieldDescriptorProtoType = 2
    // FieldDescriptorProtoTypeInt64 is an alias.
    FieldDescriptorProtoTypeInt64 FieldDescriptorProtoType = 3
    // FieldDescriptorProtoTypeUint64 is an alias.
    FieldDescriptorProtoTypeUint64 FieldDescriptorProtoType = 4
    // FieldDescriptorProtoTypeInt32 is an alias.
    FieldDescriptorProtoTypeInt32 FieldDescriptorProtoType = 5
    // FieldDescriptorProtoTypeFixed64 is an alias.
    FieldDescriptorProtoTypeFixed64 FieldDescriptorProtoType = 6
    // FieldDescriptorProtoTypeFixed32 is an alias.
    FieldDescriptorProtoTypeFixed32 FieldDescriptorProtoType = 7
    // FieldDescriptorProtoTypeBool is an alias.
    FieldDescriptorProtoTypeBool FieldDescriptorProtoType = 8
    // FieldDescriptorProtoTypeString is an alias.
    FieldDescriptorProtoTypeString FieldDescriptorProtoType = 9
    // FieldDescriptorProtoTypeGroup is an alias.
    FieldDescriptorProtoTypeGroup FieldDescriptorProtoType = 10
    // FieldDescriptorProtoTypeMessage is an alias.
    FieldDescriptorProtoTypeMessage FieldDescriptorProtoType = 11
    // FieldDescriptorProtoTypeBytes is an alias.
    FieldDescriptorProtoTypeBytes FieldDescriptorProtoType = 12
    // FieldDescriptorProtoTypeUint32 is an alias.
    FieldDescriptorProtoTypeUint32 FieldDescriptorProtoType = 13
    // FieldDescriptorProtoTypeEnum is an alias.
    FieldDescriptorProtoTypeEnum FieldDescriptorProtoType = 14
    // FieldDescriptorProtoTypeSfixed32 is an alias.
    FieldDescriptorProtoTypeSfixed32 FieldDescriptorProtoType = 15
    // FieldDescriptorProtoTypeSfixed64 is an alias.
    FieldDescriptorProtoTypeSfixed64 FieldDescriptorProtoType = 16
    // FieldDescriptorProtoTypeSint32 is an alias.
    FieldDescriptorProtoTypeSint32 FieldDescriptorProtoType = 17
    // FieldDescriptorProtoTypeSint64 is an alias.
    FieldDescriptorProtoTypeSint64 FieldDescriptorProtoType = 18

    // FieldDescriptorProtoLabelOptional is an alias.
    FieldDescriptorProtoLabelOptional FieldDescriptorProtoLabel = 1
    // FieldDescriptorProtoLabelRequired is an alias.
    FieldDescriptorProtoLabelRequired FieldDescriptorProtoLabel = 2
    // FieldDescriptorProtoLabelRepeated is an alias.
    FieldDescriptorProtoLabelRepeated FieldDescriptorProtoLabel = 3

    // FieldOptionsCTypeString is an alias.
    FieldOptionsCTypeString FieldOptionsCType = 0
    // FieldOptionsCTypeCord is an alias.
    FieldOptionsCTypeCord FieldOptionsCType = 1
    // FieldOptionsCTypeStringPiece is an alias.
    FieldOptionsCTypeStringPiece FieldOptionsCType = 2

    // FieldOptionsJSTypeJSNormal is an alias.
    FieldOptionsJSTypeJSNormal FieldOptionsJSType = 0
    // FieldOptionsJSTypeJSString is an alias.
    FieldOptionsJSTypeJSString FieldOptionsJSType = 1
    // FieldOptionsJSTypeJSNumber is an alias.
    FieldOptionsJSTypeJSNumber FieldOptionsJSType = 2

    // FileOptionsOptimizeModeSpeed is an alias.
    FileOptionsOptimizeModeSpeed FileOptionsOptimizeMode = 1
    // FileOptionsOptimizeModeCodeSize is an alias.
    FileOptionsOptimizeModeCodeSize FileOptionsOptimizeMode = 2
    // FileOptionsOptimizeModeLiteRuntime is an alias.
    FileOptionsOptimizeModeLiteRuntime FileOptionsOptimizeMode = 3

    // MethodOptionsIdempotencyLevelIdempotencyUnknown is an alias.
    MethodOptionsIdempotencyLevelIdempotencyUnknown = 0
    // MethodOptionsIdempotencyLevelNoSideEffects is an alias.
    MethodOptionsIdempotencyLevelNoSideEffects = 1
    // MethodOptionsIdempotencyLevelIdempotent is an alias.
    MethodOptionsIdempotencyLevelIdempotent = 2
)

func DirPathToFiles Uses

func DirPathToFiles(files ...File) (map[string][]File, error)

DirPathToFiles maps the Files to a map from directory to the slice of Files in that directory.

Returns error if file paths are not unique. Directories are normalized.

Files will be sorted by FilePath.

func ExtensionRangeString Uses

func ExtensionRangeString(extensionRange ExtensionRange) string

ExtensionRangeString returns the string representation of the extension range.

func FilePathToFile Uses

func FilePathToFile(files ...File) (map[string]File, error)

FilePathToFile maps the Files to a map from FilePath() to File.

Returns error if file paths are not unique.

func ForEachEnum Uses

func ForEachEnum(f func(Enum) error, containerDescriptor ContainerDescriptor) error

ForEachEnum calls f on each Enum in the given ContainerDescriptor, including nested Enums.

Returns error and stops iterating if f returns error Never returns error unless f returns error.

func ForEachMessage Uses

func ForEachMessage(f func(Message) error, containerDescriptor ContainerDescriptor) error

ForEachMessage calls f on each Message in the given ContainerDescriptor, including nested Messages.

Returns error and stops iterating if f returns error Never returns error unless f returns error.

func FullNameToEnum Uses

func FullNameToEnum(files ...File) (map[string]Enum, error)

FullNameToEnum maps the Enums in the Files to a map from full name to enum.

Returns error if the Enums do not have unique full names within the Files, which should generally never happen for properly-formed Files.

func FullNameToMessage Uses

func FullNameToMessage(files ...File) (map[string]Message, error)

FullNameToMessage maps the Messages in the Files to a map from full name to message.

Returns error if the Messages do not have unique full names within the Files, which should generally never happen for properly-formed Files.

func FullNameToMethod Uses

func FullNameToMethod(files ...File) (map[string]Method, error)

FullNameToMethod maps the Methods in the Files to a map from full name to Method.

Returns error if Methods do not have unique full names within the Files, which should generally never happen for properly-formed Files.

func FullNameToService Uses

func FullNameToService(files ...File) (map[string]Service, error)

FullNameToService maps the Services in the Files to a map from full name to Service.

Returns error if Services do not have unique full names within the Files, which should generally never happen for properly-formed Files.

func NameInReservedNames Uses

func NameInReservedNames(name string, reservedNames ...ReservedName) bool

NameInReservedNames returns true if the name is in one of the ReservedNames.

func NameToEnumValue Uses

func NameToEnumValue(enum Enum) (map[string]EnumValue, error)

NameToEnumValue maps the EnumValues in the Enum to a map from name to EnumValue.

Returns error if the EnumValues do not have unique names within the Enum, which should generally never happen for properly-formed Enums.

func NameToMessageOneof Uses

func NameToMessageOneof(message Message) (map[string]Oneof, error)

NameToMessageOneof maps the Oneofs in the Message to a map from name to Oneof.

Returns error if the Oneofs do not have unique names within the Message, which should generally never happen for properly-formed Messages.

func NameToMethod Uses

func NameToMethod(service Service) (map[string]Method, error)

NameToMethod maps the Methods in the Service to a map from name to Method.

Returns error if Methods do not have unique names within the Service, which should generally never happen for properly-formed Services.

func NameToService Uses

func NameToService(file File) (map[string]Service, error)

NameToService maps the Services in the File to a map from name to Service.

Returns error if Services do not have unique names within the File, which should generally never happen for properly-formed Files.

func NestedNameToEnum Uses

func NestedNameToEnum(containerDescriptor ContainerDescriptor) (map[string]Enum, error)

NestedNameToEnum maps the Enums in the ContainerDescriptor to a map from nested name to Enum.

Returns error if Enums do not have unique nested names within the ContainerDescriptor, which should generally never happen for properly-formed ContainerDescriptors.

func NestedNameToMessage Uses

func NestedNameToMessage(containerDescriptor ContainerDescriptor) (map[string]Message, error)

NestedNameToMessage maps the Messages in the ContainerDescriptor to a map from nested name to Message.

Returns error if Messages do not have unique nested names within the ContainerDescriptor, which should generally never happen for properly-formed files.

func NumberInReservedRanges Uses

func NumberInReservedRanges(number int, reservedRanges ...ReservedRange) bool

NumberInReservedRanges returns true if the number is in one of the ReservedRanges.

func NumberToEnumValue Uses

func NumberToEnumValue(enum Enum) (map[int]EnumValue, error)

NumberToEnumValue maps the EnumValues in the Enum to a map from number to EnumValue.

Returns error if the EnumValues do not have unique numbers within the Enum, which should generally never happen for properly-formed Enums.

func NumberToMessageField Uses

func NumberToMessageField(message Message) (map[int]Field, error)

NumberToMessageField maps the Fields in the Message to a map from number to Field.

TODO: is this right? Includes extensions.

Returns error if the Fields do not have unique numbers within the Message, which should generally never happen for properly-formed Messages.

func PackageToFiles Uses

func PackageToFiles(files ...File) (map[string][]File, error)

PackageToFiles maps the Files to a map from Protobuf package to the slice of Files in that package.

Returns error if file paths are not unique.

Files will be sorted by Path.

func PackageToNameToService Uses

func PackageToNameToService(files ...File) (map[string]map[string]Service, error)

PackageToNameToService maps the Services in the Files to a map from package to name to Service.

Returns error if the Services do not have unique names within the packages, which should generally never happen for properly-formed Files.

func PackageToNestedNameToEnum Uses

func PackageToNestedNameToEnum(files ...File) (map[string]map[string]Enum, error)

PackageToNestedNameToEnum maps the Enums in the Files to a map from package to nested name to Enum.

Returns error if the Enums do not have unique nested names within the packages, which should generally never happen for properly-formed Files.

func PackageToNestedNameToMessage Uses

func PackageToNestedNameToMessage(files ...File) (map[string]map[string]Message, error)

PackageToNestedNameToMessage maps the Messages in the Files to a map from package to nested name to Message.

Returns error if the Messages do not have unique nested names within the packages, which should generally never happen for properly-formed Files.

func ReservedRangeString Uses

func ReservedRangeString(reservedRange ReservedRange) string

ReservedRangeString returns the string representation of the reserved range.

func SortFiles Uses

func SortFiles(files []File)

SortFiles sorts the Files by FilePath.

func StringToExtensionRange Uses

func StringToExtensionRange(message Message) map[string]ExtensionRange

StringToExtensionRange maps the ExtensionRanges in the Message to a map from string string to ExtensionRange.

Ignores duplicates.

func StringToReservedRange Uses

func StringToReservedRange(reservedDescriptor ReservedDescriptor) map[string]ReservedRange

StringToReservedRange maps the ReservedRanges in the ReservedDescriptor to a map from string string to ReservedRange.

Ignores duplicates.

func ValueToReservedName Uses

func ValueToReservedName(reservedDescriptor ReservedDescriptor) map[string]ReservedName

ValueToReservedName maps the ReservedNames in the ReservedDescriptor to a map from string value to ReservedName.

Ignores duplicates.

type ContainerDescriptor Uses

type ContainerDescriptor interface {
    Enums() []Enum
    Messages() []Message
}

ContainerDescriptor contains Enums and Messages.

type Descriptor Uses

type Descriptor interface {
    // FilePath returns the associated file path as returned by the Protobuf compiler.
    //
    // This will be relative to the input proto_paths.
    // Normalized.
    // Always non-empty.
    FilePath() string
    // Package returns the associated package.
    //
    // Can be empty.
    Package() string
}

Descriptor is the base interface for a descriptor type.

type Enum Uses

type Enum interface {
    NamedDescriptor
    ReservedDescriptor

    Values() []EnumValue

    AllowAlias() bool
    AllowAliasLocation() Location
}

Enum is an enum descriptor.

type EnumValue Uses

type EnumValue interface {
    NamedDescriptor

    Enum() Enum
    Number() int

    NumberLocation() Location
}

EnumValue is an enum value descriptor.

type ExtensionRange Uses

type ExtensionRange interface {
    LocationDescriptor

    Start() int
    End() int
}

ExtensionRange is a extension range for a message.

type Field Uses

type Field interface {
    NamedDescriptor

    Message() Message
    Number() int
    Label() FieldDescriptorProtoLabel
    Type() FieldDescriptorProtoType
    TypeName() string
    OneofIndex() (int, bool)
    JSONName() string
    JSType() FieldOptionsJSType
    CType() FieldOptionsCType
    // Set vs unset matters for packed
    // See the comments on descriptor.proto
    Packed() *bool

    NumberLocation() Location
    TypeLocation() Location
    TypeNameLocation() Location
    JSONNameLocation() Location
    JSTypeLocation() Location
    CTypeLocation() Location
    PackedLocation() Location
}

Field is a field descriptor.

type FieldDescriptorProtoLabel Uses

type FieldDescriptorProtoLabel int32

FieldDescriptorProtoLabel aliases protobufdescriptor.FieldDescriptorProto_Label.

func (FieldDescriptorProtoLabel) String Uses

func (l FieldDescriptorProtoLabel) String() string

String returns the string representation of the FieldDescriptorProtoLabel.

type FieldDescriptorProtoType Uses

type FieldDescriptorProtoType int32

FieldDescriptorProtoType aliases protobufdescriptor.FieldDescriptorProto_Type.

func (FieldDescriptorProtoType) String Uses

func (t FieldDescriptorProtoType) String() string

String returns the string representation of the FieldDescriptorProtoType.

type FieldOptionsCType Uses

type FieldOptionsCType int32

FieldOptionsCType aliases protobufdescriptor.FieldOptions_CType.

func (FieldOptionsCType) String Uses

func (c FieldOptionsCType) String() string

String returns the string representation of the FieldOptionsCType.

type FieldOptionsJSType Uses

type FieldOptionsJSType int32

FieldOptionsJSType aliases protobufdescriptor.FieldOptions_JSType.

func (FieldOptionsJSType) String Uses

func (j FieldOptionsJSType) String() string

String returns the string representation of the FieldOptionsJSType.

type File Uses

type File interface {
    Descriptor
    // Top-level only.
    ContainerDescriptor

    Syntax() Syntax
    FileImports() []FileImport
    Services() []Service

    CsharpNamespace() string
    GoPackage() string
    JavaMultipleFiles() bool
    JavaOuterClassname() string
    JavaPackage() string
    JavaStringCheckUtf8() bool
    ObjcClassPrefix() string
    PhpClassPrefix() string
    PhpNamespace() string
    PhpMetadataNamespace() string
    RubyPackage() string
    SwiftPrefix() string

    OptimizeFor() FileOptionsOptimizeMode
    CcGenericServices() bool
    JavaGenericServices() bool
    PyGenericServices() bool
    PhpGenericServices() bool
    CcEnableArenas() bool

    SyntaxLocation() Location
    PackageLocation() Location
    CsharpNamespaceLocation() Location
    GoPackageLocation() Location
    JavaMultipleFilesLocation() Location
    JavaOuterClassnameLocation() Location
    JavaPackageLocation() Location
    JavaStringCheckUtf8Location() Location
    ObjcClassPrefixLocation() Location
    PhpClassPrefixLocation() Location
    PhpNamespaceLocation() Location
    PhpMetadataNamespaceLocation() Location
    RubyPackageLocation() Location
    SwiftPrefixLocation() Location

    OptimizeForLocation() Location
    CcGenericServicesLocation() Location
    JavaGenericServicesLocation() Location
    PyGenericServicesLocation() Location
    PhpGenericServicesLocation() Location
    CcEnableArenasLocation() Location
}

File is a file descriptor.

func NewFile Uses

func NewFile(fileDescriptor protodescpb.FileDescriptor) (File, error)

NewFile returns a new File.

func NewFilesUnstable Uses

func NewFilesUnstable(ctx context.Context, fileDescriptors ...protodescpb.FileDescriptor) ([]File, error)

NewFilesUnstable converts the FileDescriptorSet into Files.

This may be done concurrently and the returned Files may not be in the same order as the input FileDescriptorProtos on the FileDescriptorSet. If ordering matters, use NewFile.

type FileImport Uses

type FileImport interface {
    LocationDescriptor

    Import() string
    IsPublic() bool
    IsWeak() bool
}

FileImport is a file import descriptor.

type FileOptionsOptimizeMode Uses

type FileOptionsOptimizeMode int32

FileOptionsOptimizeMode aliases protobufdescriptor.FileOptions_OptimizeMode.

func (FileOptionsOptimizeMode) String Uses

func (t FileOptionsOptimizeMode) String() string

String returns the string representation of the FileOptionsOptimizeMode.

type Location Uses

type Location interface {
    StartLine() int
    StartColumn() int
    EndLine() int
    EndColumn() int
    LeadingComments() string
    TrailingComments() string
    // NOT a copy. Do not modify.
    LeadingDetachedComments() []string
}

Location defines source code info location information.

May be extended in the future to include comments.

Note that unlike SourceCodeInfo_Location, these are not zero-indexed.

type LocationDescriptor Uses

type LocationDescriptor interface {
    Descriptor

    // Location returns the location of the entire descriptor.
    //
    // Can return nil, although will generally not be nil.
    Location() Location
}

LocationDescriptor is the base interface for a descriptor type with a location.

type Message Uses

type Message interface {
    NamedDescriptor
    // Only those directly nested under this message.
    ContainerDescriptor
    ReservedDescriptor

    // Includes fields in oneofs.
    Fields() []Field
    Extensions() []Field
    Oneofs() []Oneof
    ExtensionRanges() []ExtensionRange

    // Will return nil if this is a top-level message
    Parent() Message
    IsMapEntry() bool

    MessageSetWireFormat() bool
    NoStandardDescriptorAccessor() bool
    MessageSetWireFormatLocation() Location
    NoStandardDescriptorAccessorLocation() Location
}

Message is a message descriptor.

type Method Uses

type Method interface {
    NamedDescriptor

    Service() Service
    InputTypeName() string
    OutputTypeName() string
    ClientStreaming() bool
    ServerStreaming() bool
    InputTypeLocation() Location
    OutputTypeLocation() Location

    IdempotencyLevel() MethodOptionsIdempotencyLevel
    IdempotencyLevelLocation() Location
}

Method is a method descriptor.

type MethodOptionsIdempotencyLevel Uses

type MethodOptionsIdempotencyLevel int32

MethodOptionsIdempotencyLevel aliases protobufdescriptor.MethodOptions_IdempotencyLevel.

func (MethodOptionsIdempotencyLevel) String Uses

func (t MethodOptionsIdempotencyLevel) String() string

String returns the string representation of the MethodOptionsIdempotencyLevel.

type NamedDescriptor Uses

type NamedDescriptor interface {
    LocationDescriptor

    // FullName returns the fully-qualified name, i.e. some.pkg.Nested.Message.FooEnum.ENUM_VALUE.
    //
    // Always non-empty.
    FullName() string
    // NestedName returns the full nested name without the package, i.e. Nested.Message.FooEnum
    // or Nested.Message.FooEnum.ENUM_VALUE.
    //
    // Always non-empty.
    NestedName() string
    // Name returns the short name, or the name of a value or field, i.e. FooEnum or ENUM_VALUE.
    //
    // Always non-empty.
    Name() string
    // NameLocation returns the location of the name of the descriptor.
    //
    // If the backing descriptor does not have name-level resolution, this will
    // attempt to return a location of the entire descriptor.
    //
    // Can return nil.
    NameLocation() Location
}

NamedDescriptor is the base interface for a named descriptor type.

type Oneof Uses

type Oneof interface {
    NamedDescriptor

    Message() Message
}

Oneof is a oneof descriptor.

func FieldOneof Uses

func FieldOneof(field Field) (Oneof, error)

FieldOneof returns the Oneof for the field.

Returns nil if the field is not in a oneof. Returns error if the field is malformed.

type ReservedDescriptor Uses

type ReservedDescriptor interface {
    ReservedRanges() []ReservedRange
    ReservedNames() []ReservedName
}

ReservedDescriptor has reserved ranges and names.

type ReservedName Uses

type ReservedName interface {
    LocationDescriptor

    Value() string
}

ReservedName is a reserved name for an enum or message.

type ReservedRange Uses

type ReservedRange interface {
    LocationDescriptor

    Start() int
    End() int
    EndIsExclusive() bool
}

ReservedRange is a reserved range for an enum or message.

End is exclusive for Messages, inclusive for Enums.

type Service Uses

type Service interface {
    NamedDescriptor

    Methods() []Method
}

Service is a service descriptor.

type Syntax Uses

type Syntax int

Syntax is the syntax of a file.

const (
    // SyntaxProto2 represents the proto2 syntax.
    SyntaxProto2 Syntax = iota + 1
    // SyntaxProto3 represents the proto3 syntax.
    SyntaxProto3
)

func (Syntax) String Uses

func (s Syntax) String() string

String returns the string representation of s

Package protodesc imports 12 packages (graph). Updated 2019-12-13. Refresh now. Tools for package owners.