MCPcopy
hub / github.com/golang/protobuf / P

Method P

protoc-gen-go/generator/generator.go:1008–1042  ·  view source on GitHub ↗

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).

(str ...interface{})

Source from the content-addressed store, hash-verified

1006// annotations in a .meta file in addition to outputting the atoms themselves (if g.annotateCode
1007// is true).
1008func (g *Generator) P(str ...interface{}) {
1009 if !g.writeOutput {
1010 return
1011 }
1012 g.WriteString(g.indent)
1013 for _, v := range str {
1014 switch v := v.(type) {
1015 case *AnnotatedAtoms:
1016 begin := int32(g.Len())
1017 for _, v := range v.atoms {
1018 g.printAtom(v)
1019 }
1020 if g.annotateCode {
1021 end := int32(g.Len())
1022 var path []int32
1023 for _, token := range strings.Split(v.path, ",") {
1024 val, err := strconv.ParseInt(token, 10, 32)
1025 if err != nil {
1026 g.Fail("could not parse proto AST path: ", err.Error())
1027 }
1028 path = append(path, int32(val))
1029 }
1030 g.annotations = append(g.annotations, &descriptor.GeneratedCodeInfo_Annotation{
1031 Path: path,
1032 SourceFile: &v.source,
1033 Begin: &begin,
1034 End: &end,
1035 })
1036 }
1037 default:
1038 g.printAtom(v)
1039 }
1040 }
1041 g.WriteByte('\n')
1042}
1043
1044// addInitf stores the given statement to be printed inside the file's init function.
1045// The statement is given as a format specifier and arguments.

Callers 15

generateMethod · 0.95
generateHeaderMethod · 0.95
PrintCommentsMethod · 0.95
generateImportsMethod · 0.95
generateImportedMethod · 0.95
generateEnumMethod · 0.95
generateOneofFuncsMethod · 0.95
generateMessageStructMethod · 0.95
generateCommonMethodsMethod · 0.95
generateMessageMethod · 0.95

Calls 5

printAtomMethod · 0.95
FailMethod · 0.95
WriteByteMethod · 0.80
LenMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected