mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 14:57:44 -05:00
support v4 json pb output
This commit is contained in:
parent
2df4fa39e3
commit
28c36019b2
@ -37,11 +37,11 @@ func DumpJsonPb(config proto.Message, w io.Writer) error {
|
||||
return dumpJsonPb(config, w)
|
||||
}
|
||||
|
||||
const FormatProtobufJSON = "jsonpb"
|
||||
const FormatProtobufJSONPB = "jsonpb"
|
||||
|
||||
func init() {
|
||||
common.Must(core.RegisterConfigLoader(&core.ConfigFormat{
|
||||
Name: []string{FormatProtobufJSON},
|
||||
Name: []string{FormatProtobufJSONPB},
|
||||
Extension: []string{".pb.json", ".pbjson"},
|
||||
Loader: func(input interface{}) (*core.Config, error) {
|
||||
switch v := input.(type) {
|
||||
|
@ -3,6 +3,7 @@ package jsonv4
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/json"
|
||||
"github.com/v2fly/v2ray-core/v4/infra/conf/jsonpb"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
@ -123,6 +124,26 @@ func executeConvert(cmd *base.Command, args []string) {
|
||||
if err != nil {
|
||||
base.Fatalf("failed to convert to protobuf: %s", err)
|
||||
}
|
||||
case jsonpb.FormatProtobufJSONPB:
|
||||
data, err := json.Marshal(m)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to marshal json: %s", err)
|
||||
}
|
||||
r := bytes.NewReader(data)
|
||||
cf, err := serial.DecodeJSONConfig(r)
|
||||
if err != nil {
|
||||
base.Fatalf("failed to decode json: %s", err)
|
||||
}
|
||||
pbConfig, err := cf.Build()
|
||||
if err != nil {
|
||||
base.Fatalf(err.Error())
|
||||
}
|
||||
w := bytes.NewBuffer(nil)
|
||||
err = jsonpb.DumpJsonPb(pbConfig, w)
|
||||
if err != nil {
|
||||
base.Fatalf(err.Error())
|
||||
}
|
||||
out = w.Bytes()
|
||||
default:
|
||||
base.Errorf("invalid output format: %s", outputFormat)
|
||||
base.Errorf("Run '%s help %s' for details.", base.CommandEnv.Exec, cmd.LongName())
|
||||
|
Loading…
Reference in New Issue
Block a user