protoplugin

package
v1.36.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2019 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package protoplugin provides utilities for protoc plugins.

The only functions that should be called as of now is Main. The rest are not guaranteed to stay here.

This was HEAVILY adapted from github.com/grpc-ecosystem/grpc-gateway/protoc-gen-grpc-gateway.

Eventually, a rewrite of this to be simpler for what we need would be nice, but this was available to get us here, especially with handling go imports.

Note that "FQMN", "FQSN", etc stand for "Fully Qualified Message Name", "Fully Qualified Service Name", etc, which denotes the package and object name together.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Do added in v1.9.0

func Do(runner Runner, reader io.Reader, writer io.Writer) error

Do is a helper function for protobuf plugins.

func main() {
  if err := protoplugin.Do(runner, os.Stdin, os.Stdout); err != nil {
    log.Fatal(err)
  }
}

func ReadRequest added in v1.9.0

func ReadRequest(reader io.Reader) (*plugin_go.CodeGeneratorRequest, error)

ReadRequest reads the request from the reader.

func WriteResponse added in v1.9.0

func WriteResponse(writer io.Writer, response *plugin_go.CodeGeneratorResponse) error

WriteResponse writes the response to the writer.

Types

type Enum

type Enum struct {
	*descriptor.EnumDescriptorProto
	File *File
	// Outers is a list of outer messages if this enum is a nested type.
	Outers []string
	Index  int
}

Enum describes a protocol buffer enum type.

func (*Enum) FQEN

func (e *Enum) FQEN() string

FQEN returns a fully qualified enum name of this enum.

type Field

type Field struct {
	*descriptor.FieldDescriptorProto
	// Message is the message type which this field belongs to.
	Message *Message
	// FieldMessage is the message type of the field.
	FieldMessage *Message
}

Field wraps descriptor.FieldDescriptorProto for richer features.

type File

type File struct {
	*descriptor.FileDescriptorProto
	GoPackage              *GoPackage
	Messages               []*Message
	Enums                  []*Enum
	Services               []*Service
	TransitiveDependencies []*File
}

File wraps descriptor.FileDescriptorProto for richer features.

func (*File) SerializedFileDescriptor added in v1.35.0

func (f *File) SerializedFileDescriptor() ([]byte, error)

SerializedFileDescriptor returns a gzipped marshalled representation of the FileDescriptor.

type GoPackage

type GoPackage struct {
	Path string
	Name string
	// Alias is an alias of the package unique within the current invocation of the generator.
	Alias string
}

GoPackage represents a golang package.

func (*GoPackage) Standard

func (g *GoPackage) Standard() bool

Standard returns whether the import is a golang standard package.

func (*GoPackage) String

func (g *GoPackage) String() string

String returns a string representation of this package in the form of import line in golang.

type Message

type Message struct {
	*descriptor.DescriptorProto
	File *File
	// Outers is a list of outer messages if this message is a nested type.
	Outers []string
	Fields []*Field
	// Index is proto path index of this message in File.
	Index int
}

Message describes a protocol buffer message types.

func (*Message) FQMN

func (m *Message) FQMN() string

FQMN returns a fully qualified message name of this message.

func (*Message) GoType

func (m *Message) GoType(currentPackage string) string

GoType returns a go type name for the message type. It prefixes the type name with the package alias if its belonging package is not "currentPackage".

type Method

type Method struct {
	*descriptor.MethodDescriptorProto
	Service      *Service
	RequestType  *Message
	ResponseType *Message
}

Method wraps descriptor.MethodDescriptorProto for richer features.

type Runner added in v1.9.0

type Runner interface {
	Run(*plugin_go.CodeGeneratorRequest) *plugin_go.CodeGeneratorResponse
}

Runner runs the plugin logic.

func NewMultiRunner added in v1.28.0

func NewMultiRunner(runners ...Runner) Runner

NewMultiRunner returns a new Runner that executes all the given Runners and merges the resulting CodeGeneratorResponses.

func NewRunner added in v1.9.0

func NewRunner(
	tmpl *template.Template,
	templateInfoChecker func(*TemplateInfo) error,
	baseImports []string,
	fileToOutputFilename func(*File) (string, error),
	unknownFlagHandler func(key string, value string) error,
) Runner

NewRunner returns a new Runner.

type Service

type Service struct {
	*descriptor.ServiceDescriptorProto
	File    *File
	Methods []*Method
}

Service wraps descriptor.ServiceDescriptorProto for richer features.

func (*Service) FQSN

func (s *Service) FQSN() string

FQSN returns a fully qualified service name of this service.

type TemplateInfo

type TemplateInfo struct {
	*File
	Imports []*GoPackage
}

TemplateInfo is the info passed to a template.

Jump to

Keyboard shortcuts

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