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
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/common/environment/envctx"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/environment/envimpl"
|
|
|
|
"github.com/v2fly/v2ray-core/v5/common/registry"
|
2021-09-04 11:48:23 -04:00
|
|
|
)
|
|
|
|
|
2021-11-27 04:16:41 -05:00
|
|
|
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-11-27 04:16:41 -05:00
|
|
|
if rawJSON == nil || len(rawJSON) == 0 {
|
|
|
|
rawJSON = []byte("{}")
|
2021-09-07 07:29:40 -04:00
|
|
|
}
|
2021-11-27 04:16:41 -05: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
|
|
|
|
2021-11-27 04:16:41 -05:00
|
|
|
// LoadHeterogeneousConfigFromRawJSON private API
|
|
|
|
func LoadHeterogeneousConfigFromRawJSON(ctx context.Context, interfaceType, name string, rawJSON json.RawMessage) (proto.Message, error) {
|
|
|
|
return loadHeterogeneousConfigFromRawJSON(interfaceType, name, rawJSON)
|
2021-09-07 06:42:45 -04:00
|
|
|
}
|