2021-09-04 11:48:23 -04:00
|
|
|
package v5cfg
|
|
|
|
|
|
|
|
import (
|
2021-09-05 10:37:26 -04:00
|
|
|
"context"
|
2021-09-04 11:48:23 -04:00
|
|
|
"encoding/json"
|
2021-10-28 06:34:19 -04:00
|
|
|
|
2021-09-04 11:48:23 -04:00
|
|
|
"github.com/golang/protobuf/proto"
|
2021-10-28 06:34:19 -04:00
|
|
|
|
2021-09-05 10:37:26 -04:00
|
|
|
"github.com/v2fly/v2ray-core/v4/common/environment/envctx"
|
|
|
|
"github.com/v2fly/v2ray-core/v4/common/environment/envimpl"
|
2021-09-04 11:48:23 -04:00
|
|
|
"github.com/v2fly/v2ray-core/v4/common/registry"
|
|
|
|
)
|
|
|
|
|
|
|
|
func loadHeterogeneousConfigFromRawJson(interfaceType, name string, rawJson json.RawMessage) (proto.Message, error) {
|
2021-09-05 10:37:26 -04:00
|
|
|
fsdef := envimpl.NewDefaultFileSystemDefaultImpl()
|
|
|
|
ctx := envctx.ContextWithEnvironment(context.TODO(), fsdef)
|
2021-09-07 07:29:40 -04:00
|
|
|
if rawJson == nil || len(rawJson) == 0 {
|
|
|
|
rawJson = []byte("{}")
|
|
|
|
}
|
2021-09-05 10:37:26 -04:00
|
|
|
return registry.LoadImplementationByAlias(ctx, interfaceType, name, []byte(rawJson))
|
2021-09-04 11:48:23 -04:00
|
|
|
}
|
2021-09-07 06:42:45 -04:00
|
|
|
|
|
|
|
// LoadHeterogeneousConfigFromRawJson private API
|
|
|
|
func LoadHeterogeneousConfigFromRawJson(ctx context.Context, interfaceType, name string, rawJson json.RawMessage) (proto.Message, error) {
|
|
|
|
return loadHeterogeneousConfigFromRawJson(interfaceType, name, rawJson)
|
|
|
|
}
|