Documentation
¶
Index ¶
- Constants
- Variables
- func CanPack(k protoreflect.Kind) bool
- func ComputePath(d protoreflect.Descriptor) (protoreflect.SourcePath, bool)
- func CreatePrefixList(pkg string) []string
- func DebugLog([]any, string, string, ...any)
- func EscapeBytes[B ~string | ~[]byte](data B) string
- func FindFirstOption(res hasOptionNode, handler errorHandler, scope string, ...) (int, error)
- func FindOption(res hasOptionNode, handler errorHandler, scope string, ...) (int, error)
- func IsZeroLocation(loc protoreflect.SourceLocation) bool
- func JSONName(name string) string
- func MapEntry(name string) string
- func RemoveOption(uo []*descriptorpb.UninterpretedOption, indexToRemove int) []*descriptorpb.UninterpretedOption
- func TrimPrefix(str, prefix string) string
- type MessageContext
- type ParsedFile
Constants ¶
const Debug = false
const IsRace = false
Variables ¶
var FieldTypes = map[string]descriptorpb.FieldDescriptorProto_Type{ "double": descriptorpb.FieldDescriptorProto_TYPE_DOUBLE, "float": descriptorpb.FieldDescriptorProto_TYPE_FLOAT, "int32": descriptorpb.FieldDescriptorProto_TYPE_INT32, "int64": descriptorpb.FieldDescriptorProto_TYPE_INT64, "uint32": descriptorpb.FieldDescriptorProto_TYPE_UINT32, "uint64": descriptorpb.FieldDescriptorProto_TYPE_UINT64, "sint32": descriptorpb.FieldDescriptorProto_TYPE_SINT32, "sint64": descriptorpb.FieldDescriptorProto_TYPE_SINT64, "fixed32": descriptorpb.FieldDescriptorProto_TYPE_FIXED32, "fixed64": descriptorpb.FieldDescriptorProto_TYPE_FIXED64, "sfixed32": descriptorpb.FieldDescriptorProto_TYPE_SFIXED32, "sfixed64": descriptorpb.FieldDescriptorProto_TYPE_SFIXED64, "bool": descriptorpb.FieldDescriptorProto_TYPE_BOOL, "string": descriptorpb.FieldDescriptorProto_TYPE_STRING, "bytes": descriptorpb.FieldDescriptorProto_TYPE_BYTES, }
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 ComputePath ¶
func ComputePath(d protoreflect.Descriptor) (protoreflect.SourcePath, bool)
ComputePath 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 ¶
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 EscapeBytes ¶
EscapeBytes escapes the value of a bytes field for use in a FieldDescriptorProto.default_value.
This implements the algorithm in protoc's C++ code, which is a port of absl::CEscape. See https://github.com/abseil/abseil-cpp/blob/934f613818ffcb26c942dff4a80be9a4031c662c/absl/strings/escaping.cc#L406.
func FindFirstOption ¶
func FindFirstOption(res hasOptionNode, handler errorHandler, scope string, opts []*descriptorpb.UninterpretedOption, name string) (int, error)
func FindOption ¶
func FindOption(res hasOptionNode, handler errorHandler, scope string, opts []*descriptorpb.UninterpretedOption, name string) (int, error)
func IsZeroLocation ¶
func IsZeroLocation(loc protoreflect.SourceLocation) bool
IsZeroLocation returns true if the given loc is a zero value (which is returned from queries that have no result).
func JSONName ¶
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 MapEntry ¶
MapEntry returns the map entry 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 TrimPrefix ¶
TrimPrefix is used to remove the given prefix from the given str. It does not require an exact match and ignores case and underscores. If the all non-underscore characters would be removed from str, str is returned unchanged. If str does not have the given prefix (even with the very lenient matching, in regard to case and underscores), then str is returned unchanged.
The algorithm is adapted from the protoc source:
https://github.com/protocolbuffers/protobuf/blob/v21.3/src/google/protobuf/descriptor.cc#L922
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 |
|---|---|
|
Package arena defines an Arena type with compressed pointers.
|
Package arena defines an Arena type with compressed pointers. |
|
Package cases provides functions for inter-converting between different case styles.
|
Package cases provides functions for inter-converting between different case styles. |
|
Package decimal provides a big decimal type, i.e., a version of big.Float which works on a base 10 exponent, rather than base 2, allowing it to represent values such as 0.1 exactly.
|
Package decimal provides a big decimal type, i.e., a version of big.Float which works on a base 10 exponent, rather than base 2, allowing it to represent values such as 0.1 exactly. |
|
Package editions contains helpers related to resolving features for Protobuf editions.
|
Package editions contains helpers related to resolving features for Protobuf editions. |
|
enum is a helper for generating boilerplate related to Go enums.
|
enum is a helper for generating boilerplate related to Go enums. |
|
ext
|
|
|
bigx
Package bigx provides direct access to arithmetic primitives from math/big.
|
Package bigx provides direct access to arithmetic primitives from math/big. |
|
bitsx
Package bitsx contains extensions to Go's package math/bits.
|
Package bitsx contains extensions to Go's package math/bits. |
|
cmpx
package cmpx contains extensions to Go's package cmp.
|
package cmpx contains extensions to Go's package cmp. |
|
iterx
Package iterx contains extensions to Go's package iter.
|
Package iterx contains extensions to Go's package iter. |
|
mapsx
package mapsx contains extensions to Go's package maps.
|
package mapsx contains extensions to Go's package maps. |
|
osx
Package osx contains extensions to the os package.
|
Package osx contains extensions to the os package. |
|
slicesx
Package slicesx contains extensions to Go's package slices.
|
Package slicesx contains extensions to Go's package slices. |
|
stringsx
Package stringsx contains extensions to Go's package strings.
|
Package stringsx contains extensions to Go's package strings. |
|
unsafex
Package unsafex contains extensions to Go's package unsafe.
|
Package unsafex contains extensions to Go's package unsafe. |
|
Package featuresext provides file descriptors for the "google/protobuf/cpp_features.proto" and "google/protobuf/java_features.proto" standard import files.
|
Package featuresext provides file descriptors for the "google/protobuf/cpp_features.proto" and "google/protobuf/java_features.proto" standard import files. |
|
gen
|
|
|
Package golden provides a framework for writing file-based golden tests.
|
Package golden provides a framework for writing file-based golden tests. |
|
Package intern provides an interning table abstraction to optimize symbol resolution.
|
Package intern provides an interning table abstraction to optimize symbol resolution. |
|
Package protoc contains some helpers for invoking protoc from tests.
|
Package protoc contains some helpers for invoking protoc from tests. |
|
Package tag contains all of the numeric field and enum value tag numbers from descriptor.proto.
|
Package tag contains all of the numeric field and enum value tag numbers from descriptor.proto. |
|
gen
command
|
|
|
testing
|
|
|
dualcompiler
Package dualcompiler provides a test abstraction layer for running tests with both the old protocompile.Compiler and the new experimental compiler.
|
Package dualcompiler provides a test abstraction layer for running tests with both the old protocompile.Compiler and the new experimental compiler. |
|
googleapis
Package googleapis makes a checked-in download of https://github.com/googleapis/googleapis available for use by tests.
|
Package googleapis makes a checked-in download of https://github.com/googleapis/googleapis available for use by tests. |
|
googleapis/gen
command
|
|
|
Package toposort provides a generic topological sort implementation.
|
Package toposort provides a generic topological sort implementation. |