Exemple #1
0
func runXls2PbtMode() bool {
	// 输入协议二进制描述文件,通过protoc配合github.com/davyxu/pbmeta/protoc-gen-meta插件导出
	// 创建描述文件池
	pool, err := pbmeta.CreatePoolByFile(*paramPbFile)
	if err != nil {
		fmt.Println(err)
		return false
	}

	var patchFile *PatchFile

	if *paramPatch != "" {

		patchFile = NewPatchFile(pool)

		if !patchFile.Load(*paramPatch) {
			return false
		}

		log.Infof("patch file loaded: %s", *paramPatch)
	}

	return parallelWorker(flag.Args(), *paramPara, *paramOutDir, func(input, output string) bool {

		// 显示电子表格到导出文件

		sheetDataArray := exportSheetMsg(pool, input)

		if sheetDataArray == nil {
			return false
		}

		if patchFile != nil {
			patchFile.Patch(sheetDataArray)
		}

		return printFile(sheetDataArray, output)

	})

	return true
}
Exemple #2
0
func Run(param Parameter) bool {
	// 输入协议二进制描述文件,通过protoc配合github.com/davyxu/pbmeta/protoc-gen-meta插件导出
	// 创建描述文件池
	pool, err := pbmeta.CreatePoolByFile(param.PBFile)
	if err != nil {
		fmt.Println(err)
		return false
	}

	var patchFile *PatchFile

	if param.PatchFile != "" {

		patchFile = NewPatchFile(pool)

		if !patchFile.Load(param.PatchFile) {
			return false
		}

		log.Infof("patch file loaded: %s", param.PatchFile)
	}

	return util.ParallelWorker(param.InputFileList, param.ParaMode, func(in interface{}) bool {

		input := in.(string)

		var ext string
		var writer printer.IPrinter

		switch param.Format {
		case "pbt":
			ext = ".pbt"
			writer = printer.NewPBTWriter()
		case "json":
			ext = ".json"
			writer = printer.NewJsonWriter()

		case "lua":
			ext = ".lua"
			writer = printer.NewLuaWriter()

		default:
			log.Errorf("unknown format '%s'", param.Format)
			return false
		}

		// 使用指定的导出文件夹,并更换电子表格输入文件的后缀名为pbt作为输出文件
		outputFile := path.Join(param.OutDir, util.ChangeExtension(input, ext))

		// 显示电子表格到导出文件

		sheetDataArray := exportSheetMsg(pool, input)

		if sheetDataArray == nil {
			return false
		}

		if patchFile != nil {
			patchFile.Patch(sheetDataArray)
		}

		return printFile(sheetDataArray, outputFile, writer)

	})

}