func GetDirPathToDescriptors(protoSet *file.ProtoSet) (map[string][]*FileDescriptor, error) {
	dirPathToDescriptors := make(map[string][]*FileDescriptor, len(protoSet.DirPathToFiles))
	for dirPath, protoFiles := range protoSet.DirPathToFiles {
		// skip those files not under the directory
		if !strings.HasPrefix(dirPath, protoSet.DirPath) {
			continue
		}
		descriptors := make([]*FileDescriptor, len(protoFiles))
		for i, protoFile := range protoFiles {
			file, err := os.Open(protoFile.Path)
			if err != nil {
				return nil, err
			}
			parser := proto.NewParser(file)
			parser.Filename(protoFile.DisplayPath)
			descriptor, err := parser.Parse()
			if err != nil {
				_ = file.Close()
				return nil, err
			}
			if _, err := file.Seek(0, 0); err != nil {
				_ = file.Close()
				return nil, err
			}
			fileData, err := ioutil.ReadAll(file)
			if err != nil {
				_ = file.Close()
				return nil, err
			}
			_ = file.Close()
			descriptors[i] = &FileDescriptor{
				Proto:    descriptor,
				ProtoSet: protoSet,
				FileData: string(fileData),
			}
		}
		dirPathToDescriptors[dirPath] = descriptors
	}
	return dirPathToDescriptors, nil
}
// GetDirPathToDescriptors is a convenience function that gets the
// descriptors for the given ProtoSet.
GetDirPathToDescriptors is a convenience function that gets the
descriptors for the given ProtoSet.
// GetDirPathToDescriptors is a convenience function that gets the // descriptors for the given ProtoSet .
func GetDirPathToDescriptors(protoSet *file.ProtoSet) (map[string][]*FileDescriptor, error) {
	dirPathToDescriptors := make(map[string][]*FileDescriptor, len(protoSet.DirPathToFiles))
	for dirPath, protoFiles := range protoSet.DirPathToFiles {
		if !strings.HasPrefix(dirPath, protoSet.DirPath) {
			continue
		}
		descriptors := make([]*FileDescriptor, len(protoFiles))
		for i, protoFile := range protoFiles {
			file, err := os.Open(protoFile.Path)
			if err != nil {
				return nil, err
			}
			parser := proto.NewParser(file)
			parser.Filename(protoFile.DisplayPath)
			descriptor, err := parser.Parse()
			if err != nil {
				_ = file.Close()
				return nil, err
			}
			if _, err := file.Seek(0, 0); err != nil {
				_ = file.Close()
				return nil, err
			}
			fileData, err := ioutil.ReadAll(file)
			if err != nil {
				_ = file.Close()
				return nil, err
			}
			_ = file.Close()
			descriptors[i] = &FileDescriptor{
				Proto:    descriptor,
				ProtoSet: protoSet,
				FileData: string(fileData),
			}
		}
		dirPathToDescriptors[dirPath] = descriptors
	}
	return dirPathToDescriptors, nil
}
func GetDirPathToDescriptors ( protoSet * file . ProtoSet ) ( map [ string ] [ ] * FileDescriptor , error ) { dirPathToDescriptors := make ( map [ string ] [ ] * FileDescriptor , len ( protoSet . DirPathToFiles ) ) for dirPath , protoFiles := range protoSet . DirPathToFiles { if ! strings . HasPrefix ( dirPath , protoSet . DirPath ) { continue } descriptors := make ( [ ] * FileDescriptor , len ( protoFiles ) ) for i , protoFile := range protoFiles { file , err := os . Open ( protoFile . Path ) if err != nil { return nil , err } parser := proto . NewParser ( file ) parser . Filename ( protoFile . DisplayPath ) descriptor , err := parser . Parse ( ) if err != nil { _ = file . Close ( ) return nil , err } if _ , err := file . Seek ( 0 , 0 ) ; err != nil { _ = file . Close ( ) return nil , err } fileData , err := ioutil . ReadAll ( file ) if err != nil { _ = file . Close ( ) return nil , err } _ = file . Close ( ) descriptors [ i ] = & FileDescriptor { Proto : descriptor , ProtoSet : protoSet , FileData : string ( fileData ) , } } dirPathToDescriptors [ dirPath ] = descriptors } return dirPathToDescriptors , nil }
GetDirPathToDescriptors is a convenience function that gets the
descriptors for the given ProtoSet.
GetDirPathToDescriptors is a convenience function that gets the descriptors for the given ProtoSet .
// skip those files not under the directory