const generatedCodeVersion … type Plugin … type pluginSlice … func (ps pluginSlice) Len() int { … } func (ps pluginSlice) Less(i, j int) bool { … } func (ps pluginSlice) Swap(i, j int) { … } var plugins … // RegisterPlugin installs a (second-order) plugin to be run when the Go output is generated. // It is typically called during initialization. func RegisterPlugin(p Plugin) { … } type GoImportPath … func (p GoImportPath) String() string { … } type GoPackageName … type common … // GoImportPath is the import path of the Go package containing the type. func (c *common) GoImportPath() GoImportPath { … } func (c *common) File() *FileDescriptor { … } func fileIsProto3(file *descriptor.FileDescriptorProto) bool { … } func (c *common) proto3() bool { … } type Descriptor … // TypeName returns the elements of the dotted type name. // The package name is not part of this name. func (d *Descriptor) TypeName() []string { … } func (d *Descriptor) allowOneof() bool { … } type EnumDescriptor … // TypeName returns the elements of the dotted type name. // The package name is not part of this name. func (e *EnumDescriptor) TypeName() (s []string) { … } // alias provides the TypeName corrected for the application of any naming // extensions on the enum type. It should be used for generating references to // the Go types and for calculating prefixes. func (e *EnumDescriptor) alias() (s []string) { … } // Everything but the last element of the full type name, CamelCased. // The values of type Foo.Bar are call Foo_value1... not Foo_Bar_value1... . func (e *EnumDescriptor) prefix() string { … } // The integer value of the named constant in this enumerated type. func (e *EnumDescriptor) integerValueAsString(name string) string { … } type ExtensionDescriptor … // TypeName returns the elements of the dotted type name. // The package name is not part of this name. func (e *ExtensionDescriptor) TypeName() (s []string) { … } // DescName returns the variable name used for the generated descriptor. func (e *ExtensionDescriptor) DescName() string { … } type ImportedDescriptor … func (id *ImportedDescriptor) TypeName() []string { … } type FileDescriptor … // VarName is the variable name we'll use in the generated code to refer // to the compressed bytes of this descriptor. It is not exported, so // it is only valid inside the generated package. func (d *FileDescriptor) VarName() string { … } // goPackageOption interprets the file's go_package option. // If there is no go_package, it returns ("", "", false). // If there's a simple name, it returns ("", pkg, true). // If the option implies an import path, it returns (impPath, pkg, true). func (d *FileDescriptor) goPackageOption() (impPath GoImportPath, pkg GoPackageName, ok bool) { … } // goFileName returns the output name for the generated Go file. func (d *FileDescriptor) goFileName(pathType pathType) string { … } func (d *FileDescriptor) addExport(obj Object, sym symbol) { … } type symbol … type messageSymbol … type getterSymbol … func (ms *messageSymbol) GenerateAlias(g *Generator, filename string, pkg GoPackageName) { … } type enumSymbol … func (es enumSymbol) GenerateAlias(g *Generator, filename string, pkg GoPackageName) { … } type constOrVarSymbol … func (cs constOrVarSymbol) GenerateAlias(g *Generator, filename string, pkg GoPackageName) { … } type Object … type Generator … type pathType … const pathTypeImport … const pathTypeSourceRelative … // New creates a new generator and allocates the request and response protobufs. func New() *Generator { … } // Error reports a problem, including an error, and exits the program. func (g *Generator) Error(err error, msgs ...string) { … } // Fail reports a problem and exits the program. func (g *Generator) Fail(msgs ...string) { … } // 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 (g *Generator) CommandLineParameters(parameter string) { … } // 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 (g *Generator) DefaultPackageName(obj Object) string { … } // GoPackageName returns the name used for a package. func (g *Generator) GoPackageName(importPath GoImportPath) GoPackageName { … } // AddImport adds a package to the generated file's import section. // It returns the name used for the package. func (g *Generator) AddImport(importPath GoImportPath) GoPackageName { … } var globalPackageNames … // Create and remember a guaranteed unique package name. Pkg is the candidate name. // The FileDescriptor parameter is unused. func RegisterUniquePackageName(pkg string, f *FileDescriptor) string { … } var isGoKeyword … var isGoPredeclaredIdentifier … func cleanPackageName(name string) GoPackageName { … } // defaultGoPackage returns the package name to use, // derived from the import path of the package we're building code for. func (g *Generator) defaultGoPackage() GoPackageName { … } // 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 (g *Generator) SetPackageNames() { … } // 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. func (g *Generator) WrapTypes() { … } // Scan the descriptors in this file. For each one, build the slice of nested descriptors func (g *Generator) buildNestedDescriptors(descs []*Descriptor) { … } func (g *Generator) buildNestedEnums(descs []*Descriptor, enums []*EnumDescriptor) { … } // Construct the Descriptor func newDescriptor(desc *descriptor.DescriptorProto, parent *Descriptor, file *FileDescriptor, index int) *Descriptor { … } // Return a slice of all the Descriptors defined within this file func wrapDescriptors(file *FileDescriptor) []*Descriptor { … } // Wrap this Descriptor, recursively func wrapThisDescriptor(sl []*Descriptor, desc *descriptor.DescriptorProto, parent *Descriptor, file *FileDescriptor, index int) []*Descriptor { … } // Construct the EnumDescriptor func newEnumDescriptor(desc *descriptor.EnumDescriptorProto, parent *Descriptor, file *FileDescriptor, index int) *EnumDescriptor { … } // Return a slice of all the EnumDescriptors defined within this file func wrapEnumDescriptors(file *FileDescriptor, descs []*Descriptor) []*EnumDescriptor { … } // Return a slice of all the top-level ExtensionDescriptors defined within this file. func wrapExtensions(file *FileDescriptor) []*ExtensionDescriptor { … } // Return a slice of all the types that are publicly imported into this file. func wrapImported(file *FileDescriptor, g *Generator) (sl []*ImportedDescriptor) { … } func extractComments(file *FileDescriptor) { … } // 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 (g *Generator) BuildTypeNameMap() { … } // 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 (g *Generator) ObjectNamed(typeName string) Object { … } type AnnotatedAtoms … // Annotate records the file name and proto AST path of a list of atoms // so that a later call to P can emit a link from each atom to its origin. func Annotate(file *FileDescriptor, path string, atoms ...interface{ … } // printAtom prints the (atomic, non-annotation) argument to the generated output. func (g *Generator) printAtom(v interface{ … } // P prints the arguments to the generated output. It handles strings and int32s, plus // handling indirections because they may be *string, etc. Any inputs of type AnnotatedAtoms may emit // annotations in a .meta file in addition to outputting the atoms themselves (if g.annotateCode // is true). func (g *Generator) P(str ...interface{ … } // addInitf stores the given statement to be printed inside the file's init function. // The statement is given as a format specifier and arguments. func (g *Generator) addInitf(stmt string, a ...interface{ … } func (g *Generator) PrintImport(alias GoPackageName, pkg GoImportPath) { … } // In Indents the output one tab stop. func (g *Generator) In() { … } // Out unindents the output one tab stop. func (g *Generator) Out() { … } // GenerateAllFiles generates the output for all the files we're outputting. func (g *Generator) GenerateAllFiles() { … } // Run all the plugins associated with the file. func (g *Generator) runPlugins(file *FileDescriptor) { … } // Fill the response protocol buffer with the generated output for all the files we're // supposed to generate. func (g *Generator) generate(file *FileDescriptor) { … } // Generate the header, including package definition func (g *Generator) generateHeader() { … } var deprecationComment … // 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 (g *Generator) PrintComments(path string) bool { … } // makeComments generates the comment string for the field, no "\n" at the end func (g *Generator) makeComments(path string) (string, bool) { … } // Comments returns any comments from the source .proto file and empty string if comments not found. // The path is a comma-separated list of intergers. // See descriptor.proto for its format. func (g *Generator) Comments(path string) string { … } func (g *Generator) fileByName(filename string) *FileDescriptor { … } // weak returns whether the ith import of the current file is a weak import. func (g *Generator) weak(i int32) bool { … } // Generate the imports func (g *Generator) generateImports() { … } func (g *Generator) generateImported(id *ImportedDescriptor) { … } // Generate the enum definitions for this EnumDescriptor. func (g *Generator) generateEnum(enum *EnumDescriptor) { … } // The tag is a string like "varint,2,opt,name=fieldname,def=7" that // identifies details of the field for the protocol buffer marshaling and unmarshaling // code. The fields are: // wire encoding // protocol tag number // opt,req,rep for optional, required, or repeated // packed whether the encoding is "packed" (optional; repeated primitives only) // name= the original declared name // enum= the name of the enum type if it is an enum-typed field. // proto3 if this field is in a proto3 message // def= string representation of the default value, if any. // The default value must be in a representation that can be used at run-time // to generate the default value. Thus bools become 0 and 1, for instance. func (g *Generator) goTag(message *Descriptor, field *descriptor.FieldDescriptorProto, wiretype string) string { … } func needsStar(field *descriptor.FieldDescriptorProto, proto3 bool, allowOneOf bool) bool { … } // 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 (g *Generator) TypeName(obj Object) string { … } // GoType returns a string representing the type name, and the wire type func (g *Generator) GoType(message *Descriptor, field *descriptor.FieldDescriptorProto) (typ string, wire string) { … } type GoMapDescriptor … func (g *Generator) GoMapType(d *Descriptor, field *descriptor.FieldDescriptorProto) *GoMapDescriptor { … } func (g *Generator) RecordTypeUse(t string) { … } var methodNames … var wellKnownTypes … // getterDefault finds the default value for the field to return from a getter, // regardless of if it's a built in default or explicit from the source. Returns e.g. "nil", `""`, "Default_MessageType_FieldName" func (g *Generator) getterDefault(field *descriptor.FieldDescriptorProto, goMessageType, goTypeName string) string { … } // defaultConstantName builds the name of the default constant from the message // type name and the untouched field name, e.g. "Default_MessageType_FieldName" func (g *Generator) defaultConstantName(goMessageType, protoFieldName string) string { … } type msgCtx … type fieldCommon … // getProtoName gets the proto name of a field, e.g. "field_name" or "descriptor". func (f *fieldCommon) getProtoName() string { … } // getGoType returns the go type of the field as a string, e.g. "*int32". func (f *fieldCommon) getGoType() string { … } type simpleField … // decl prints the declaration of the field in the struct (if any). func (f *simpleField) decl(g *Generator, mc *msgCtx) { … } // getter prints the getter for the field. func (f *simpleField) getter(g *Generator, mc *msgCtx) { … } // setter prints the setter method of the field. func (f *simpleField) setter(g *Generator, mc *msgCtx) { … } // getProtoDef returns the default value explicitly stated in the proto file, e.g "yoshi" or "5". func (f *simpleField) getProtoDef() string { … } // getProtoTypeName returns the protobuf type name for the field as returned by field.GetTypeName(), e.g. ".google.protobuf.Duration". func (f *simpleField) getProtoTypeName() string { … } // getProtoType returns the *field.Type value, e.g. descriptor.FieldDescriptorProto_TYPE_FIXED64. func (f *simpleField) getProtoType() descriptor.FieldDescriptorProto_Type { … } func (f *simpleField) getProto() *descriptor.FieldDescriptorProto { … } type oneofSubField … // typedNil prints a nil casted to the pointer to this field. // - for XXX_OneofWrappers func (f *oneofSubField) typedNil(g *Generator) { … } // getProtoDef returns the default value explicitly stated in the proto file, e.g "yoshi" or "5". func (f *oneofSubField) getProtoDef() string { … } // getProtoTypeName returns the protobuf type name for the field as returned by field.GetTypeName(), e.g. ".google.protobuf.Duration". func (f *oneofSubField) getProtoTypeName() string { … } // getProtoType returns the *field.Type value, e.g. descriptor.FieldDescriptorProto_TYPE_FIXED64. func (f *oneofSubField) getProtoType() descriptor.FieldDescriptorProto_Type { … } func (f *oneofSubField) getProto() *descriptor.FieldDescriptorProto { … } type oneofField … // decl prints the declaration of the field in the struct (if any). func (f *oneofField) decl(g *Generator, mc *msgCtx) { … } // getter for a oneof field will print additional discriminators and interfaces for the oneof, // also it prints all the getters for the sub fields. func (f *oneofField) getter(g *Generator, mc *msgCtx) { … } // setter prints the setter method of the field. func (f *oneofField) setter(g *Generator, mc *msgCtx) { … } type topLevelField … type defField … // generateDefaultConstants adds constants for default values if needed, which is only if the default value is. // explicit in the proto. func (g *Generator) generateDefaultConstants(mc *msgCtx, topLevelFields []topLevelField) { … } // generateGet generates the getter for both the simpleField and oneofSubField. // We did not want to duplicate the code since it is quite intricate so we came // up with this ugly method. At least the logic is in one place. This can be reworked. func (g *Generator) generateGet(mc *msgCtx, protoField *descriptor.FieldDescriptorProto, protoType descriptor.FieldDescriptorProto_Type, oneof bool, fname, tname, uname, oneoftname, fullpath, gname, def string) { … } // generateInternalStructFields just adds the XXX_<something> fields to the message struct. func (g *Generator) generateInternalStructFields(mc *msgCtx, topLevelFields []topLevelField) { … } // generateOneofFuncs adds all the utility functions for oneof, including marshalling, unmarshalling and sizer. func (g *Generator) generateOneofFuncs(mc *msgCtx, topLevelFields []topLevelField) { … } func (g *Generator) generateOneofDecls(mc *msgCtx, topLevelFields []topLevelField) { … } // generateMessageStruct adds the actual struct with it's members (but not methods) to the output. func (g *Generator) generateMessageStruct(mc *msgCtx, topLevelFields []topLevelField) { … } // generateGetters adds getters for all fields, including oneofs and weak fields when applicable. func (g *Generator) generateGetters(mc *msgCtx, topLevelFields []topLevelField) { … } // generateSetters add setters for all fields, including oneofs and weak fields when applicable. func (g *Generator) generateSetters(mc *msgCtx, topLevelFields []topLevelField) { … } // generateCommonMethods adds methods to the message that are not on a per field basis. func (g *Generator) generateCommonMethods(mc *msgCtx) { … } // Generate the type and default constant definitions for this Descriptor. func (g *Generator) generateMessage(message *Descriptor) { … } type byTypeName … func (a byTypeName) Len() int { … } func (a byTypeName) Swap(i, j int) { … } func (a byTypeName) Less(i, j int) bool { … } // mapFieldKeys returns the keys of m in a consistent order. func mapFieldKeys(m map[*descriptor.FieldDescriptorProto]string) []*descriptor.FieldDescriptorProto { … } var escapeChars … // unescape reverses the "C" escaping that protoc does for default values of bytes fields. // It is best effort in that it effectively ignores malformed input. Seemingly invalid escape // sequences are conveyed, unmodified, into the decoded result. func unescape(s string) string { … } func (g *Generator) generateExtension(ext *ExtensionDescriptor) { … } func (g *Generator) generateInitFunction() { … } func (g *Generator) generateFileDescriptor(file *FileDescriptor) { … } func (g *Generator) generateEnumRegistration(enum *EnumDescriptor) { … } // Is c an ASCII lower-case letter? func isASCIILower(c byte) bool { … } // Is c an ASCII digit? func isASCIIDigit(c byte) bool { … } // 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 CamelCase(s string) string { … } // CamelCaseSlice is like CamelCase, but the argument is a slice of strings to // be joined with "_". func CamelCaseSlice(elem []string) string { … } // dottedSlice turns a sliced name into a dotted name. func dottedSlice(elem []string) string { … } // Is this field optional? func isOptional(field *descriptor.FieldDescriptorProto) bool { … } // Is this field required? func isRequired(field *descriptor.FieldDescriptorProto) bool { … } // Is this field repeated? func isRepeated(field *descriptor.FieldDescriptorProto) bool { … } // Is this field a scalar numeric type? func IsScalar(field *descriptor.FieldDescriptorProto) bool { … } // badToUnderscore is the mapping function used to generate Go names from package names, // which can be dotted in the input .proto file. It replaces non-identifier characters such as // dot or dash with underscore. func badToUnderscore(r rune) rune { … } // baseName returns the last path element of the name, with the last dotted suffix removed. func baseName(name string) string { … } const packagePath … const messagePath … const enumPath … const messageFieldPath … const messageMessagePath … const messageEnumPath … const messageOneofPath … const enumValuePath … var supportTypeAliases … func init() { … }