func (t typeFinder) Find(name string) interface{} { if name == "" || name[0] != '.' { return nil } req := t.req() var pkg *desc.FileDescriptorProto for _, p := range req.GetProtoFile() { if p.Package == nil { continue } root := "." + p.GetPackage() prefix := root + "." if strings.HasPrefix(name, prefix) { pkg = p break } if name == root { return p } } if pkg == nil { return nil } for _, m := range pkg.GetMessageType() { if found := t.findType(m, name); found != nil { return found } } if e := t.findEnum(pkg.GetEnumType(), name); e != nil { return e } if e := t.findExtension(pkg.GetExtension(), name); e != nil { return e } // TODO: Services // TODO: Groups return nil }
func flatTypesForFile(pkg *desc.FileDescriptorProto, out *FlatTypes) *FlatTypes { if out == nil { out = &FlatTypes{ Files: make(map[string]*desc.FileDescriptorProto), Enums: make(map[string]*desc.EnumDescriptorProto), Messages: make(map[string]*desc.DescriptorProto), Extensions: make(map[string]*desc.FieldDescriptorProto), Services: make(map[string]*desc.ServiceDescriptorProto), } } out.File = pkg out.Files[pkg.GetName()] = pkg prefix := "." + pkg.GetPackage() + "." out.populateMessageTypes(pkg.GetMessageType(), prefix) out.populateEnums(pkg.GetEnumType(), prefix) out.populateExtensions(pkg.GetExtension(), prefix) out.populateServices(pkg.GetService(), prefix) return out }