mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-02-20 23:47:21 -05:00
add domain prefix to v2 types
This commit is contained in:
parent
a4e6fe5a94
commit
9d7e0d6f7a
@ -4,10 +4,13 @@ import (
|
|||||||
"errors"
|
"errors"
|
||||||
"google.golang.org/protobuf/types/known/anypb"
|
"google.golang.org/protobuf/types/known/anypb"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/golang/protobuf/proto"
|
"github.com/golang/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const V2RayTypeURLHeader = "types.v2fly.org/"
|
||||||
|
|
||||||
// ToTypedMessage converts a proto Message into TypedMessage.
|
// ToTypedMessage converts a proto Message into TypedMessage.
|
||||||
func ToTypedMessage(message proto.Message) *anypb.Any {
|
func ToTypedMessage(message proto.Message) *anypb.Any {
|
||||||
if message == nil {
|
if message == nil {
|
||||||
@ -15,7 +18,7 @@ func ToTypedMessage(message proto.Message) *anypb.Any {
|
|||||||
}
|
}
|
||||||
settings, _ := proto.Marshal(message)
|
settings, _ := proto.Marshal(message)
|
||||||
return &anypb.Any{
|
return &anypb.Any{
|
||||||
TypeUrl: GetMessageType(message),
|
TypeUrl: V2RayTypeURLHeader + GetMessageType(message),
|
||||||
Value: settings,
|
Value: settings,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -35,7 +38,7 @@ func GetInstance(messageType string) (interface{}, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func GetInstanceOf(v *anypb.Any) (proto.Message, error) {
|
func GetInstanceOf(v *anypb.Any) (proto.Message, error) {
|
||||||
instance, err := GetInstance(v.TypeUrl)
|
instance, err := GetInstance(V2TypeFromURL(v.TypeUrl))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
@ -50,7 +53,7 @@ func V2Type(v *anypb.Any) string {
|
|||||||
return V2TypeFromURL(v.TypeUrl)
|
return V2TypeFromURL(v.TypeUrl)
|
||||||
}
|
}
|
||||||
func V2TypeFromURL(string2 string) string {
|
func V2TypeFromURL(string2 string) string {
|
||||||
return string2
|
return strings.TrimPrefix(string2, V2RayTypeURLHeader)
|
||||||
}
|
}
|
||||||
func V2TypeHumanReadable(v *anypb.Any) string {
|
func V2TypeHumanReadable(v *anypb.Any) string {
|
||||||
return v.TypeUrl
|
return v.TypeUrl
|
||||||
|
Loading…
x
Reference in New Issue
Block a user