protointernal

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: 10 Imported by: 1

Documentation

Index

Constants

View Source
const (
	// MaxNormalTag is the maximum allowed tag number for a field in a normal message.
	MaxNormalTag = 536870911 // 2^29 - 1

	// MaxMessageSetTag is the maximum allowed tag number of a field in a message that
	// uses the message set wire format.
	MaxMessageSetTag = math.MaxInt32 - 1

	// MaxTag is the maximum allowed tag number. (It is the same as MaxMessageSetTag
	// since that is the absolute highest allowed.)
	MaxTag = MaxMessageSetTag

	// SpecialReservedStart is the first tag in a range that is reserved and not
	// allowed for use in message definitions.
	SpecialReservedStart = 19000
	// SpecialReservedEnd is the last tag in a range that is reserved and not
	// allowed for use in message definitions.
	SpecialReservedEnd = 19999

	// FilePackageTag is the tag number of the package element in a file
	// descriptor proto.
	FilePackageTag = 2
	// FileDependencyTag is the tag number of the dependencies element in a
	// file descriptor proto.
	FileDependencyTag = 3
	// FileMessagesTag is the tag number of the messages element in a file
	// descriptor proto.
	FileMessagesTag = 4
	// FileEnumsTag is the tag number of the enums element in a file descriptor
	// proto.
	FileEnumsTag = 5
	// FileServicesTag is the tag number of the services element in a file
	// descriptor proto.
	FileServicesTag = 6
	// FileExtensionsTag is the tag number of the extensions element in a file
	// descriptor proto.
	FileExtensionsTag = 7
	// FileOptionsTag is the tag number of the options element in a file
	// descriptor proto.
	FileOptionsTag = 8
	// FileSourceCodeInfoTag is the tag number of the source code info element
	// in a file descriptor proto.
	FileSourceCodeInfoTag = 9
	// FilePublicDependencyTag is the tag number of the public dependency element
	// in a file descriptor proto.
	FilePublicDependencyTag = 10
	// FileWeakDependencyTag is the tag number of the weak dependency element
	// in a file descriptor proto.
	FileWeakDependencyTag = 11
	// FileSyntaxTag is the tag number of the syntax element in a file
	// descriptor proto.
	FileSyntaxTag = 12
	// FileEditionTag is the tag number of the edition element in a file
	// descriptor proto.
	FileEditionTag = 14
	// MessageNameTag is the tag number of the name element in a message
	// descriptor proto.
	MessageNameTag = 1
	// MessageFieldsTag is the tag number of the fields element in a message
	// descriptor proto.
	MessageFieldsTag = 2
	// MessageNestedMessagesTag is the tag number of the nested messages
	// element in a message descriptor proto.
	MessageNestedMessagesTag = 3
	// MessageEnumsTag is the tag number of the enums element in a message
	// descriptor proto.
	MessageEnumsTag = 4
	// MessageExtensionRangesTag is the tag number of the extension ranges
	// element in a message descriptor proto.
	MessageExtensionRangesTag = 5
	// MessageExtensionsTag is the tag number of the extensions element in a
	// message descriptor proto.
	MessageExtensionsTag = 6
	// MessageOptionsTag is the tag number of the options element in a message
	// descriptor proto.
	MessageOptionsTag = 7
	// MessageOneofsTag is the tag number of the one-ofs element in a message
	// descriptor proto.
	MessageOneofsTag = 8
	// MessageReservedRangesTag is the tag number of the reserved ranges element
	// in a message descriptor proto.
	MessageReservedRangesTag = 9
	// MessageReservedNamesTag is the tag number of the reserved names element
	// in a message descriptor proto.
	MessageReservedNamesTag = 10
	// ExtensionRangeStartTag is the tag number of the start index in an
	// extension range proto.
	ExtensionRangeStartTag = 1
	// ExtensionRangeEndTag is the tag number of the end index in an
	// extension range proto.
	ExtensionRangeEndTag = 2
	// ExtensionRangeOptionsTag is the tag number of the options element in an
	// extension range proto.
	ExtensionRangeOptionsTag = 3
	// ReservedRangeStartTag is the tag number of the start index in a reserved
	// range proto. This field number is the same for both "flavors" of reserved
	// ranges: DescriptorProto.ReservedRange and EnumDescriptorProto.EnumReservedRange.
	ReservedRangeStartTag = 1
	// ReservedRangeEndTag is the tag number of the end index in a reserved
	// range proto. This field number is the same for both "flavors" of reserved
	// ranges: DescriptorProto.ReservedRange and EnumDescriptorProto.EnumReservedRange.
	ReservedRangeEndTag = 2
	// FieldNameTag is the tag number of the name element in a field descriptor
	// proto.
	FieldNameTag = 1
	// FieldExtendeeTag is the tag number of the extendee element in a field
	// descriptor proto.
	FieldExtendeeTag = 2
	// FieldNumberTag is the tag number of the number element in a field
	// descriptor proto.
	FieldNumberTag = 3
	// FieldLabelTag is the tag number of the label element in a field
	// descriptor proto.
	FieldLabelTag = 4
	// FieldTypeTag is the tag number of the type element in a field descriptor
	// proto.
	FieldTypeTag = 5
	// FieldTypeNameTag is the tag number of the type name element in a field
	// descriptor proto.
	FieldTypeNameTag = 6
	// FieldDefaultTag is the tag number of the default value element in a
	// field descriptor proto.
	FieldDefaultTag = 7
	// FieldOptionsTag is the tag number of the options element in a field
	// descriptor proto.
	FieldOptionsTag = 8
	// FieldOneofIndexTag is the tag number of the oneof index element in a
	// field descriptor proto.
	FieldOneofIndexTag = 9
	// FieldJSONNameTag is the tag number of the JSON name element in a field
	// descriptor proto.
	FieldJSONNameTag = 10
	// FieldProto3OptionalTag is the tag number of the proto3_optional element
	// in a descriptor proto.
	FieldProto3OptionalTag = 17
	// OneofNameTag is the tag number of the name element in a one-of
	// descriptor proto.
	OneofNameTag = 1
	// OneofOptionsTag is the tag number of the options element in a one-of
	// descriptor proto.
	OneofOptionsTag = 2
	// EnumNameTag is the tag number of the name element in an enum descriptor
	// proto.
	EnumNameTag = 1
	// EnumValuesTag is the tag number of the values element in an enum
	// descriptor proto.
	EnumValuesTag = 2
	// EnumOptionsTag is the tag number of the options element in an enum
	// descriptor proto.
	EnumOptionsTag = 3
	// EnumReservedRangesTag is the tag number of the reserved ranges element in
	// an enum descriptor proto.
	EnumReservedRangesTag = 4
	// EnumReservedNamesTag is the tag number of the reserved names element in
	// an enum descriptor proto.
	EnumReservedNamesTag = 5
	// EnumValNameTag is the tag number of the name element in an enum value
	// descriptor proto.
	EnumValNameTag = 1
	// EnumValNumberTag is the tag number of the number element in an enum
	// value descriptor proto.
	EnumValNumberTag = 2
	// EnumValOptionsTag is the tag number of the options element in an enum
	// value descriptor proto.
	EnumValOptionsTag = 3
	// ServiceNameTag is the tag number of the name element in a service
	// descriptor proto.
	ServiceNameTag = 1
	// ServiceMethodsTag is the tag number of the methods element in a service
	// descriptor proto.
	ServiceMethodsTag = 2
	// ServiceOptionsTag is the tag number of the options element in a service
	// descriptor proto.
	ServiceOptionsTag = 3
	// MethodNameTag is the tag number of the name element in a method
	// descriptor proto.
	MethodNameTag = 1
	// MethodInputTag is the tag number of the input type element in a method
	// descriptor proto.
	MethodInputTag = 2
	// MethodOutputTag is the tag number of the output type element in a method
	// descriptor proto.
	MethodOutputTag = 3
	// MethodOptionsTag is the tag number of the options element in a method
	// descriptor proto.
	MethodOptionsTag = 4
	// MethodInputStreamTag is the tag number of the input stream flag in a
	// method descriptor proto.
	MethodInputStreamTag = 5
	// MethodOutputStreamTag is the tag number of the output stream flag in a
	// method descriptor proto.
	MethodOutputStreamTag = 6

	// UninterpretedOptionsTag is the tag number of the uninterpreted options
	// element. All *Options messages use the same tag for the field that stores
	// uninterpreted options.
	UninterpretedOptionsTag = 999

	// UninterpretedNameTag is the tag number of the name element in an
	// uninterpreted options proto.
	UninterpretedNameTag = 2
	// UninterpretedIdentTag is the tag number of the identifier value in an
	// uninterpreted options proto.
	UninterpretedIdentTag = 3
	// UninterpretedPosIntTag is the tag number of the positive int value in an
	// uninterpreted options proto.
	UninterpretedPosIntTag = 4
	// UninterpretedNegIntTag is the tag number of the negative int value in an
	// uninterpreted options proto.
	UninterpretedNegIntTag = 5
	// UninterpretedDoubleTag is the tag number of the double value in an
	// uninterpreted options proto.
	UninterpretedDoubleTag = 6
	// UninterpretedStringTag is the tag number of the string value in an
	// uninterpreted options proto.
	UninterpretedStringTag = 7
	// UninterpretedAggregateTag is the tag number of the aggregate value in an
	// uninterpreted options proto.
	UninterpretedAggregateTag = 8
	// UninterpretedNameNameTag is the tag number of the name element in an
	// uninterpreted option name proto.
	UninterpretedNameNameTag = 1

	// AnyTypeURLTag is the tag number of the type_url field of the Any proto.
	AnyTypeURLTag = 1
	// AnyValueTag is the tag number of the value field of the Any proto.
	AnyValueTag = 2
)

Variables

Functions

func CanPack

func CanPack(k protoreflect.Kind) bool

CanPack returns true if a repeated field of the given kind can use packed encoding.

func ComputeSourcePath

func ComputeSourcePath(d protoreflect.Descriptor) (protoreflect.SourcePath, bool)

ComputeSourcePath computes the source location path for the given descriptor. The boolean value indicates whether the result is valid. If the path cannot be computed for d, the function returns nil, false.

func CreatePrefixList

func CreatePrefixList(pkg string) []string

CreatePrefixList returns a list of package prefixes to search when resolving a symbol name. If the given package is blank, it returns only the empty string. If the given package contains only one token, e.g. "foo", it returns that token and the empty string, e.g. ["foo", ""]. Otherwise, it returns successively shorter prefixes of the package and then the empty string. For example, for a package named "foo.bar.baz" it will return the following list:

["foo.bar.baz", "foo.bar", "foo", ""]

func FindFirstOption

func FindFirstOption(res hasOptionNode, handler *reporter.Handler, scope string, opts []*descriptorpb.UninterpretedOption, name string) (int, error)

func FindOption

func FindOption(res hasOptionNode, handler *reporter.Handler, scope string, opts []*descriptorpb.UninterpretedOption, name string) (int, error)

func InitCap

func InitCap(name string) string

InitCap returns the given field name, but with the first letter capitalized.

func IsZeroSourceLocation

func IsZeroSourceLocation(loc protoreflect.SourceLocation) bool

IsZeroSourceLocation returns true if the given loc is a zero value (which is returned from queries that have no result).

func JSONName

func JSONName(name string) string

JSONName returns the default JSON name for a field with the given name. This mirrors the algorithm in protoc:

https://github.com/protocolbuffers/protobuf/blob/v21.3/src/google/protobuf/descriptor.cc#L95

func RemoveOption

func RemoveOption(uo []*descriptorpb.UninterpretedOption, indexToRemove int) []*descriptorpb.UninterpretedOption

func WriteEscapedBytes

func WriteEscapedBytes(buf *bytes.Buffer, b []byte)

Types

type MessageContext

type MessageContext struct {
	// The relevant file
	File ParsedFile

	// The type and fully-qualified name of the element within the file.
	ElementType string
	ElementName string

	// If the element being processed is an option (or *in* an option)
	// on the named element above, this will be non-nil.
	Option *descriptorpb.UninterpretedOption
	// If the element being processed is inside a message literal in an
	// option value, this will be non-empty and represent a traversal
	// to the element in question.
	OptAggPath string
}

MessageContext provides information about the location in a descriptor hierarchy, for adding context to warnings and error messages.

func (*MessageContext) String

func (c *MessageContext) String() string

type ParsedFile

type ParsedFile interface {
	// AST returns the parsed abstract syntax tree. This returns nil if the
	// Result was created without an AST.
	AST() *ast.FileNode
	// FileDescriptorProto returns the file descriptor proto.
	FileDescriptorProto() *descriptorpb.FileDescriptorProto
}

ParsedFile wraps an optional AST and required FileDescriptorProto. This is used so types like parser.Result can be passed to this internal package avoiding circular imports. Additionally, it makes it less likely that users might specify one or the other.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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