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 IsZeroLocation(loc protoreflect.SourceLocation) bool
- func JSONName(name string) string
- func MapEntry(name string) string
- func PanicIfZero[Context comparable](with *With[Context])
- func TrimPrefix(str, prefix string) string
- type With
Constants ¶
const CanonicalHTTPFQN = "protowire.schema.v1.http"
CanonicalHTTPFQN is the fully-qualified name of the canonical `@http` annotation, declared in protowire/schema/v1/annotations.proto.
Two passes key on this name: the IR's RFC-001 §5.2 routing checks and the `fdp` lowering that emits the standard `google.api.http` extension. Keying on the resolved FQN leaves a user annotation that merely happens to be called `http` alone — but the two must agree, or routes get validated and never emitted (or emitted and never validated). Hence one spelling, in one place.
const Debug = false
const GoogleAPIHTTPField = 72295728
GoogleAPIHTTPField is the field number of the standard `google.api.http` extension on google.protobuf.MethodOptions.
`fdp` has the generated extension descriptor to ask, and does; `ir` does not link genproto and matches on the number alone. The two are pinned together by TestGoogleAPIHTTPFieldNumber.
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 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 PanicIfZero ¶
func PanicIfZero[Context comparable](with *With[Context])
PanicIfZero panics if a context is zero.
This is helpful for immediately panicking on function entry.
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 With ¶
type With[Context comparable] struct { // contains filtered or unexported fields }
With is an embeddable helper for providing Context and Nil methods.
func NewWith ¶
func NewWith[Context comparable](c Context) With[Context]
NewWith wraps some value in a With.
The ctx field in With is not exported specifically so that when embedding With, it does not become exported in the embedding type.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package arena defines an Arena type with compressed pointers.
|
Package arena defines an Arena type with compressed pointers. |
|
Package bufext builds buf's SourceCodeInfo extension (buf.descriptor.v1.buf_source_code_info_extension) without importing buf's generated code, which lives in modules hosted on buf.build (#266).
|
Package bufext builds buf's SourceCodeInfo extension (buf.descriptor.v1.buf_source_code_info_extension) without importing buf's generated code, which lives in modules hosted on buf.build (#266). |
|
Package cases provides functions for inter-converting between different case styles.
|
Package cases provides functions for inter-converting between different case styles. |
|
cmd
|
|
|
genaliases
command
genaliases writes a Go file that re-exports every exported identifier of another package: a type alias for each type, and a copy of each constant and variable.
|
genaliases writes a Go file that re-exports every exported identifier of another package: a type alias for each type, and a copy of each constant and variable. |
|
Package cycle contains internal helpers for dealing with dependency cycles.
|
Package cycle contains internal helpers for dealing with dependency cycles. |
|
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 descsrc renders a descriptorpb.FileDescriptorProto back into Protobuf source text.
|
Package descsrc renders a descriptorpb.FileDescriptorProto back into Protobuf source text. |
|
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. |
|
Package erredition defines common diagnostics for issuing errors about the wrong edition being used.
|
Package erredition defines common diagnostics for issuing errors about the wrong edition being used. |
|
Package errtoken contains standard diagnostics involving tokens, usually emitted by the lexer.
|
Package errtoken contains standard diagnostics involving tokens, usually emitted by the lexer. |
|
Package exphook is the minimal contract between the root `protocompile` package and the `experimentalcompile` package.
|
Package exphook is the minimal contract between the root `protocompile` package and the `experimentalcompile` package. |
|
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 just adds a "justification" helper for diagnostics.
|
package just adds a "justification" helper for diagnostics. |
|
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
|
|
|
Package taxa (plural of taxon, an element of a taxonomy) provides support for classifying Protobuf syntax productions for use in the parser and in diagnostics.
|
Package taxa (plural of taxon, an element of a taxonomy) provides support for classifying Protobuf syntax productions for use in the parser and in diagnostics. |
|
testing
|
|
|
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
|
|
|
protoctest
Package protoctest wraps protocompile.Compiler behind a tiny abstraction the sweep harness can use.
|
Package protoctest wraps protocompile.Compiler behind a tiny abstraction the sweep harness can use. |
|
Package meta defines internal metadata types shared between the token package and the lexer.
|
Package meta defines internal metadata types shared between the token package and the lexer. |
|
Package toposort provides a generic topological sort implementation.
|
Package toposort provides a generic topological sort implementation. |