generator

package
v0.0.0-...-830501f Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2017 License: BSD-3-Clause Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CamelCase

func CamelCase(s string) string

CamelCase returns the CamelCased name. For example: a2b_cd becomes A2b_Cd

func CamelCaseSlice

func CamelCaseSlice(elem []string) string

CamelCaseSlice is like CamelCase, but the argument is a slice of strings to be joined with "_".

Types

type Descriptor

type Descriptor struct {
	*descriptor.DescriptorProto
	// contains filtered or unexported fields
}

Descriptor represents a protocol buffer message.

func (*Descriptor) PackageName

func (c *Descriptor) PackageName() string

PackageName is name in the package clause in the generated file.

func (*Descriptor) TypeName

func (d *Descriptor) TypeName() []string

TypeName returns the elements of the dotted type name. The package name is not part of this name.

type EnumDescriptor

type EnumDescriptor struct {
	*descriptor.EnumDescriptorProto
	// contains filtered or unexported fields
}

EnumDescriptor describes an enum. If it's at top level, its parent will be nil. Otherwise it will be the descriptor of the message in which it is defined.

func (*EnumDescriptor) PackageName

func (c *EnumDescriptor) PackageName() string

PackageName is name in the package clause in the generated file.

func (*EnumDescriptor) TypeName

func (e *EnumDescriptor) TypeName() (s []string)

TypeName returns the elements of the dotted type name. The package name is not part of this name.

type FileDescriptor

type FileDescriptor struct {
	*descriptor.FileDescriptorProto
	// contains filtered or unexported fields
}

FileDescriptor describes an protocol buffer descriptor file (.proto). It includes slices of all the messages and enums defined within it. Those slices are constructed by WrapTypes.

func (*FileDescriptor) PackageName

func (d *FileDescriptor) PackageName() string

PackageName is the package name we'll use in the generated code to refer to this file.

type Generator

type Generator struct {
	*bytes.Buffer

	Request  *plugin.CodeGeneratorRequest
	Response *plugin.CodeGeneratorResponse
	// contains filtered or unexported fields
}

Generator is the type whose methods generate the output, stored in the associated response structure.

func New

func New() *Generator

New creates a new generator and allocates the request and response protobufs.

func (*Generator) BuildTypeNameMap

func (g *Generator) BuildTypeNameMap()

BuildTypeNameMap populates g.typeNameToObject.

func (*Generator) Fail

func (g *Generator) Fail(msgs ...string)

Fail reports a problem and exits the program.

func (*Generator) FileOf

FileOf return the FileDescriptor for this FileDescriptorProto.

func (*Generator) GenerateAllFiles

func (g *Generator) GenerateAllFiles()

GenerateAllFiles generates the output for all the files we're outputting.

func (*Generator) In

func (g *Generator) In()

In Indents the output with two whitespaces.

func (*Generator) ObjectNamed

func (g *Generator) ObjectNamed(typeName string) Object

ObjectNamed returns an object found in g.typeNameToObject.

func (*Generator) Out

func (g *Generator) Out()

Out unindents the output with two whitespaces.

func (*Generator) P

func (g *Generator) P(str ...interface{})

P prints the arguments to the generated output. It handles strings and int32s, plus handling indirections because they may be *string, etc.

func (*Generator) SetPackageNames

func (g *Generator) SetPackageNames()

SetPackageNames sets the package name for this run. The package name must agree across all files being generated.

func (*Generator) WrapTypes

func (g *Generator) WrapTypes()

WrapTypes walks the incoming data, wrapping DescriptorProtos, EnumDescriptorProtos and FileDescriptorProtos into file-referenced objects within the Generator. It also creates the list of files to generate and so should be called before GenerateAllFiles.

type Object

type Object interface {
	PackageName() string
	TypeName() []string
}

Object is an interface abstracting the abilities shared by enums, messages, extensions and imported objects.

Jump to

Keyboard shortcuts

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