Documentation ¶
Overview ¶
Package gopoet_protogen implements caching and type resolution, supporting use of github.com/jhump/gopoet, to generate code as part of a protoc plugin, implemented using google.golang.org/protobuf/compiler/protogen.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FieldIsOptional ¶ added in v0.2.0
FieldIsOptional returns true if the field is optional.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache implements a type cache, that may be populated by feeding it protogen.File values, see also AddFile.
func (*Cache) AddFile ¶
AddFile loads the given file into the cache, note that it is not safe to call concurrently. It is recommended that all files (provided by protogen.Plugin) are loaded into the cache, prior to any generation activities that might use it.
func (*Cache) MessageFields ¶
MessageFields returns information for all the golang fields generated for a given message, where all fields must exist in the cache. Oneof fields are represented by a single value.
func (*Cache) MessageType ¶
func (x *Cache) MessageType(v protoreflect.MessageDescriptor) gopoet.TypeName
MessageType retrieves the gopoet type name for a given message from the cache, note that the type must be loaded into the cache (by using AddFile on the parent file) beforehand, otherwise it will panic.
type Field ¶
type Field interface { // Name is the name of the field. Name() string // OneOf will be non-nil for oneof fields. // Note that fields with the optional field rule will be represented as oneof fields. // Check the descriptor's IsSynthetic() method to handle that case, see also FieldIsOptional. OneOf() *protogen.Oneof // Fields are all the input protogen.Field values for this Field, typically there will be one, but there may // be more than one in the case of oneof fields. Fields() []*protogen.Field // Type returns the gopoet.TypeName for this field, which will be the unexported interface type in the case of // oneof fields (it's the return value of the getter method, in all cases). Type() gopoet.TypeName // Getter returns the gopoet.MethodType for the generated getter method (the generic one, for oneof fields). Getter() gopoet.MethodType // OneOfFields returns the same information as Type and Getter and Fields, for each of the actual oneof fields, // if any. OneOfFields() []OneOfField }
Field models the protobuf fields for a message, with oneof fields merged into a single value.
type OneOfField ¶
type OneOfField struct { // Field is the input protogen.Field for this OneOfField. Field *protogen.Field // Type returns the gopoet.TypeName for the actual golang field. Type gopoet.TypeName // Getter is the gopoet.MethodType for the generated getter method (it's return type is Type). Getter gopoet.MethodType }
OneOfField models the actual type information for a specific oneof field.