Skip to content

Conversation

KobeArthurScofield
Copy link
Contributor

这么久了似乎没人发现用 xray convert pb config.json c1.json c2.json c3.json > mix.pb 这个方式出来的 proto 文件没法正常用的吗,看来现在用 proto 配置的没几个了

xray convert pb config.json c1.json c2.json c3.json > mix.pb 转换配置文件到 proto 文件的时候,这个操作其实是将控制台输出写到文件(期望的 proto),但是会将读取配置文件产生的 log (写到控制台)也一并写进文件,导致产生的文件不能用。 其实用十六进制编辑器或者什么的把头部的 log 去掉就好,但是依然比较麻烦

现增加一个选项 -outpbfile,直接将生成的 proto 直接写到指定文件位置,出来的 proto 文件直接就能用。
比如: xray convert pb -outpbfile output.pb config.json c1.json c2.json c3.json 将 config.json c1.json c2.json c3.json 合并后转换成 proto 并直接写入到 output.pb

功能描述要不要再调整,调用 core.LoadConfig 可以使用 JSON(C) YAML TOML 格式的配置

@vrnobody
Copy link
Contributor

或者删掉输出到 STDOUT 的功能吧,不然以后还是会有人踩坑。我想了一下,输出到 STDOUT 最终还是要生成文件,有点多余。

@KobeArthurScofield
Copy link
Contributor Author

KobeArthurScofield commented Aug 23, 2025

出 proto 基本是要写文件,出到 STDOUT 直接写入文件和复制粘贴到文件出来会是两种不同的数据流

出 debug JSON 那个是原样写在 STDOUT 还是给输出选项?虽然 debug JSON 也是没法直接用只能阅读

@KobeArthurScofield
Copy link
Contributor Author

KobeArthurScofield commented Aug 23, 2025

就这样吧, 文本文件前面多几行日志不影响结果,二进制才有问题

core 的 getFormatgetExtension 不是公开的真的有点怨念啊

@@ -52,6 +60,17 @@ func executeConvertConfigsToProtobuf(cmd *base.Command, args []string) {
unnamedArgs.Set(v)
}

if len(optFile) > 0 {
switch core.GetFormatByExtension(getFileExtension(optFile)){
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里能用 core.getFormat() 的话能这边能少写一点,就是得连带 core 包的代码得跟着改成 GetFormat()

@RPRX RPRX changed the title Command: Add -outpbfile to convert pb Commands: Add -outpbfile for convert pb Aug 27, 2025
@RPRX RPRX merged commit 11f0513 into XTLS:main Aug 27, 2025
39 checks passed
@KobeArthurScofield KobeArthurScofield deleted the pb-file-out branch August 29, 2025 14:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants