Fill the response protocol buffer with the generated output for all the files we're supposed to generate.
(file *FileDescriptor)
| 1104 | // Fill the response protocol buffer with the generated output for all the files we're |
| 1105 | // supposed to generate. |
| 1106 | func (g *Generator) generate(file *FileDescriptor) { |
| 1107 | g.file = file |
| 1108 | g.usedPackages = make(map[GoImportPath]bool) |
| 1109 | g.packageNames = make(map[GoImportPath]GoPackageName) |
| 1110 | g.usedPackageNames = make(map[GoPackageName]bool) |
| 1111 | g.addedImports = make(map[GoImportPath]bool) |
| 1112 | for name := range globalPackageNames { |
| 1113 | g.usedPackageNames[name] = true |
| 1114 | } |
| 1115 | |
| 1116 | g.P("// This is a compile-time assertion to ensure that this generated file") |
| 1117 | g.P("// is compatible with the proto package it is being compiled against.") |
| 1118 | g.P("// A compilation error at this line likely means your copy of the") |
| 1119 | g.P("// proto package needs to be updated.") |
| 1120 | g.P("const _ = ", g.Pkg["proto"], ".ProtoPackageIsVersion", generatedCodeVersion, " // please upgrade the proto package") |
| 1121 | g.P() |
| 1122 | |
| 1123 | for _, td := range g.file.imp { |
| 1124 | g.generateImported(td) |
| 1125 | } |
| 1126 | for _, enum := range g.file.enum { |
| 1127 | g.generateEnum(enum) |
| 1128 | } |
| 1129 | for _, desc := range g.file.desc { |
| 1130 | // Don't generate virtual messages for maps. |
| 1131 | if desc.GetOptions().GetMapEntry() { |
| 1132 | continue |
| 1133 | } |
| 1134 | g.generateMessage(desc) |
| 1135 | } |
| 1136 | for _, ext := range g.file.ext { |
| 1137 | g.generateExtension(ext) |
| 1138 | } |
| 1139 | g.generateInitFunction() |
| 1140 | g.generateFileDescriptor(file) |
| 1141 | |
| 1142 | // Run the plugins before the imports so we know which imports are necessary. |
| 1143 | g.runPlugins(file) |
| 1144 | |
| 1145 | // Generate header and imports last, though they appear first in the output. |
| 1146 | rem := g.Buffer |
| 1147 | remAnno := g.annotations |
| 1148 | g.Buffer = new(bytes.Buffer) |
| 1149 | g.annotations = nil |
| 1150 | g.generateHeader() |
| 1151 | g.generateImports() |
| 1152 | if !g.writeOutput { |
| 1153 | return |
| 1154 | } |
| 1155 | // Adjust the offsets for annotations displaced by the header and imports. |
| 1156 | for _, anno := range remAnno { |
| 1157 | *anno.Begin += int32(g.Len()) |
| 1158 | *anno.End += int32(g.Len()) |
| 1159 | g.annotations = append(g.annotations, anno) |
| 1160 | } |
| 1161 | g.Write(rem.Bytes()) |
| 1162 | |
| 1163 | // Reformat generated code and patch annotation locations. |
no test coverage detected