Documentation ¶
Overview ¶
* The code generator for the plugin for the protocol buffer compiler. * It generates Jspb code from the protocol buffer description files read * by the main routine. * * The implementation is a clone from htts://github.com/golang/protobuf. * * jspb uses the same 3-clause BSD license and keeps the original copyright * information from goprotobuf.
Index ¶
- Variables
- func CamelCase(s string) string
- func CamelCaseSlice(elem []string) string
- func RegisterUniquePackageName(pkg string, f *FileDescriptor) string
- type Descriptor
- type EnumDescriptor
- type FileDescriptor
- type Generator
- func (g *Generator) BuildTypeNameMap()
- func (g *Generator) CommandLineParameters(parameter string)
- func (g *Generator) DefaultPackageName(obj Object) string
- func (g *Generator) Error(err error, msgs ...string)
- func (g *Generator) Fail(msgs ...string)
- func (g *Generator) FileOf(fd *descriptor.FileDescriptorProto) *FileDescriptor
- func (g *Generator) GenerateAllFiles()
- func (g *Generator) In()
- func (g *Generator) JsType(message *Descriptor, field *descriptor.FieldDescriptorProto) (typ, eleTyp string, wire string)
- func (g *Generator) ObjectNamed(typeName string) Object
- func (g *Generator) Out()
- func (g *Generator) P(str ...interface{})
- func (g *Generator) PrintComments(path string) bool
- func (g *Generator) SetPackageNames()
- func (g *Generator) TypeName(obj Object) string
- func (g *Generator) TypeNameWithPackage(obj Object) string
- func (g *Generator) WrapTypes()
- type ImportedDescriptor
- type Object
Constants ¶
This section is empty.
Variables ¶
var ErrNoPackageDefined = errors.New("no package clause in proto file.")
Functions ¶
func CamelCase ¶
CamelCase returns the CamelCased name. If there is an interior underscore followed by a lower case letter, drop the underscore and convert the letter to upper case. There is a remote possibility of this rewrite causing a name collision, but it's so remote we're prepared to pretend it's nonexistent - since the C++ generator lowercases names, it's extremely unlikely to have two fields with different capitalizations. In short, _my_field_name_2 becomes XMyFieldName_2.
func CamelCaseSlice ¶
CamelCaseSlice is like CamelCase, but the argument is a slice of strings to be joined with "_".
func RegisterUniquePackageName ¶
func RegisterUniquePackageName(pkg string, f *FileDescriptor) string
Create and remember a guaranteed unique package name for this file descriptor. Pkg is the candidate name. If f is nil, it's a builtin package like "proto" and has no file descriptor.
Types ¶
type Descriptor ¶
type Descriptor struct { *descriptor.DescriptorProto // contains filtered or unexported fields }
Descriptor represents a protocol buffer message.
func (*Descriptor) File ¶
func (c *Descriptor) File() *descriptor.FileDescriptorProto
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) File ¶
func (c *EnumDescriptor) File() *descriptor.FileDescriptorProto
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 // The input. Response *plugin.CodeGeneratorResponse // The output. Param map[string]string // Command-line parameters. PkgPrefix string // String to prefix to imported package file names. Pkg map[string]string // The names under which we import support packages // 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 builds the map from fully qualified type names to objects. The key names for the map come from the input data, which puts a period at the beginning. It should be called after SetPackageNames and before GenerateAllFiles.
func (*Generator) CommandLineParameters ¶
CommandLineParameters breaks the comma-separated list of key=value pairs in the parameter (a member of the request protobuf) into a key/value map. It then sets file name mappings defined by those entries.
func (*Generator) DefaultPackageName ¶
DefaultPackageName returns the package name printed for the object. If its file is in a different package, it returns the package name we're using for this file, plus ".". Otherwise it returns the empty string.
func (*Generator) FileOf ¶
func (g *Generator) FileOf(fd *descriptor.FileDescriptorProto) *FileDescriptor
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) JsType ¶
func (g *Generator) JsType(message *Descriptor, field *descriptor.FieldDescriptorProto) (typ, eleTyp string, wire string)
JsType returns a string representing the type name, element type (empty if it's not an array of messages), and the wire type.
func (*Generator) ObjectNamed ¶
ObjectNamed, given a fully-qualified input type name as it appears in the input data, returns the descriptor for the message or enum with that name.
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) PrintComments ¶
PrintComments prints any comments from the source .proto file. The path is a comma-separated list of integers. It returns an indication of whether any comments were printed. See descriptor.proto for its format.
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. It also defines unique package names for all imported files.
func (*Generator) TypeName ¶
TypeName is the printed name appropriate for an item. If the object is in the current file, TypeName drops the package name and underscores the rest. Otherwise the object is from another package; and the result is the underscored package name followed by the item name. The result always has an initial capital.
func (*Generator) TypeNameWithPackage ¶
TypeNameWithPackage is like TypeName, but always includes the package name even if the object is in our own package.
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 ImportedDescriptor ¶
type ImportedDescriptor struct {
// contains filtered or unexported fields
}
ImportedDescriptor describes a type that has been publicly imported from another file.
func (*ImportedDescriptor) File ¶
func (c *ImportedDescriptor) File() *descriptor.FileDescriptorProto
func (*ImportedDescriptor) PackageName ¶
func (c *ImportedDescriptor) PackageName() string
PackageName is name in the package clause in the generated file.
func (*ImportedDescriptor) TypeName ¶
func (id *ImportedDescriptor) TypeName() []string
type Object ¶
type Object interface { PackageName() string // The name we use in our output (a_b_c), possibly renamed for uniqueness. TypeName() []string File() *descriptor.FileDescriptorProto }
Object is an interface abstracting the abilities shared by enums, messages, extensions and imported objects.