func (p *plugin) Generate(file *generator.FileDescriptor) { for _, msg := range file.Messages() { for _, os := range overwriters { possible := true for _, overwriter := range os { if overwriter(file.FileDescriptorProto, msg.DescriptorProto) { possible = false } } if possible { p.checkOverwrite(msg, os) } } p.checkNameSpace(msg) for _, field := range msg.GetField() { if gogoproto.IsEmbed(field) && gogoproto.IsCustomName(field) { fmt.Fprintf(os.Stderr, "ERROR: field %v with custom name %v cannot be embedded", *field.Name, gogoproto.GetCustomName(field)) os.Exit(1) } } p.checkRepeated(msg) } for _, e := range file.GetExtension() { if gogoproto.IsEmbed(e) { fmt.Fprintf(os.Stderr, "ERROR: extended field %v cannot be embedded", generator.CamelCase(*e.Name)) os.Exit(1) } } }
func (g *Generator) GetFieldName(message *Descriptor, field *descriptor.FieldDescriptorProto) string { goTyp, _ := g.GoType(message, field) fieldname := CamelCase(*field.Name) if gogoproto.IsCustomName(field) { fieldname = gogoproto.GetCustomName(field) } if gogoproto.IsEmbed(field) { fieldname = EmbedFieldName(goTyp) } if field.OneofIndex != nil { fieldname = message.OneofDecl[int(*field.OneofIndex)].GetName() fieldname = CamelCase(fieldname) } for _, f := range methodNames { if f == fieldname { return fieldname + "_" } } if !gogoproto.IsProtoSizer(message.file, message.DescriptorProto) { if fieldname == "Size" { return fieldname + "_" } } return fieldname }