protogen package - google.golang.org/protobuf/compiler/protogen - Go Packages (original) (raw)
Package protogen provides support for writing protoc plugins.
Plugins for protoc, the Protocol Buffer compiler, are programs which read a pluginpb.CodeGeneratorRequest message from standard input and write a pluginpb.CodeGeneratorResponse message to standard output. This package provides support for writing plugins which generate Go code.
- type Annotation
- type CommentSet
- type Comments
- type Enum
- type EnumValue
- type Extension
- type Field
- type File
- type GeneratedFile
- func (g *GeneratedFile) Annotate(symbol string, loc Location)deprecated
- func (g *GeneratedFile) AnnotateSymbol(symbol string, info Annotation)
- func (g *GeneratedFile) Content() ([]byte, error)
- func (g *GeneratedFile) Import(importPath GoImportPath)
- func (g *GeneratedFile) InternalStripForEditionsDiff() bool
- func (g *GeneratedFile) P(v ...any)
- func (g *GeneratedFile) QualifiedGoIdent(ident GoIdent) string
- func (g *GeneratedFile) Skip()
- func (g *GeneratedFile) Unskip()
- func (g *GeneratedFile) Write(p []byte) (n int, err error)
- type GoIdent
- type GoImportPath
- type GoPackageName
- type Location
- type Message
- type Method
- type Oneof
- type Options
- type Plugin
- type Service
This section is empty.
This section is empty.
This section is empty.
An Annotation provides semantic detail for a generated proto element.
See the google.protobuf.GeneratedCodeInfo.Annotation documentation in descriptor.proto for details.
type CommentSet struct { }
CommentSet is a set of leading and trailing comments associated with a .proto descriptor declaration.
Comments is a comments string as provided by protoc.
String formats the comments by inserting // to the start of each line, ensuring that there is a trailing newline. An empty comment is formatted as an empty string.
An Enum describes an enum.
An EnumValue describes an enum value.
Extension is an alias of Field for documentation.
A Field describes a message field.
func (field *Field) BuilderFieldName() string
BuilderFieldName returns the name of this field in the corresponding _builder struct.
MethodName returns the (possibly mangled) name of the generated accessor method, along with the backwards-compatible name (if needed).
method must be one of Get, Set, Has, Clear. MethodName panics otherwise.
A File describes a .proto source file.
type GeneratedFile struct {
}
A GeneratedFile is a generated file.
Annotate associates a symbol in a generated Go file with a location in a source .proto file.
The symbol may refer to a type, constant, variable, function, method, or struct field. The "T.sel" syntax is used to identify the method or field 'sel' on type 'T'.
Deprecated: Use the GeneratedFile.AnnotateSymbol method instead.
func (g *GeneratedFile) AnnotateSymbol(symbol string, info Annotation)
AnnotateSymbol associates a symbol in a generated Go file with a location in a source .proto file and a semantic type.
The symbol may refer to a type, constant, variable, function, method, or struct field. The "T.sel" syntax is used to identify the method or field 'sel' on type 'T'.
func (*GeneratedFile) Content ¶
Content returns the contents of the generated file.
func (g *GeneratedFile) Import(importPath GoImportPath)
Import ensures a package is imported by the generated file.
Packages referenced by GeneratedFile.QualifiedGoIdent are automatically imported. Explicitly importing a package with Import is generally only necessary when the import will be blank (import _ "package").
func (g *GeneratedFile) InternalStripForEditionsDiff() bool
InternalStripForEditionsDiff returns true if the plugin should not emit certain parts of the generated code in order to make it possible to compare a proto2/proto3 file with its equivalent (according to proto spec) editions file. Primarily, this is the encoded descriptor.
This function is for internal use by Go Protobuf only. Do not use it, we might remove it at any time.
func (g *GeneratedFile) P(v ...any)
P prints a line to the generated output. It converts each parameter to a string following the same rules as fmt.Print. It never inserts spaces between parameters.
func (g *GeneratedFile) QualifiedGoIdent(ident GoIdent) string
QualifiedGoIdent returns the string to use for a Go identifier.
If the identifier is from a different Go package than the generated file, the returned name will be qualified (package.name) and an import statement for the identifier's package will be included in the file.
func (g *GeneratedFile) Skip()
Skip removes the generated file from the plugin output.
func (g *GeneratedFile) Unskip()
Unskip reverts a previous call to GeneratedFile.Skip, re-including the generated file in the plugin output.
type GoIdent struct { GoName string GoImportPath GoImportPath }
A GoIdent is a Go identifier, consisting of a name and import path. The name is a single identifier and may not be a dot-qualified selector.
A GoImportPath is the import path of a Go package. For example: "google.golang.org/protobuf/compiler/protogen"
Ident returns a GoIdent with s as the GoName and p as the GoImportPath.
A GoPackageName is the name of a Go package. e.g., "protobuf".
A Location is a location in a .proto source file.
See the google.protobuf.SourceCodeInfo documentation in descriptor.proto for details.
A Message describes a message.
A Method describes a method in a service.
A Oneof describes a message oneof.
MethodName returns the (possibly mangled) name of the generated accessor method.
method must be one of Has, Clear, Which. MethodName panics otherwise.
New returns a new Plugin.
A Plugin is a protoc plugin invocation.
func (gen *Plugin) Error(err error)
Error records an error in code generation. The generator will report the error back to protoc and will not produce output.
func (gen *Plugin) InternalStripForEditionsDiff() bool
InternalStripForEditionsDiff returns whether or not to strip non-functional codegen for editions diff testing.
This function is for internal use by Go Protobuf only. Do not use it, we might remove it at any time.
func (gen *Plugin) NewGeneratedFile(filename string, goImportPath GoImportPath) *GeneratedFile
NewGeneratedFile creates a new generated file with the given filename and import path.
Response returns the generator output.
A Service describes a service.