-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5d9e6b0
commit e33b7df
Showing
72 changed files
with
727 additions
and
791 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package loader | ||
|
||
import ( | ||
"errors" | ||
"reflect" | ||
|
||
"github.com/golang/protobuf/proto" | ||
) | ||
|
||
func NewTypedSettings(message proto.Message) *TypedSettings { | ||
if message == nil { | ||
return nil | ||
} | ||
settings, _ := proto.Marshal(message) | ||
return &TypedSettings{ | ||
Type: GetType(message), | ||
Settings: settings, | ||
} | ||
} | ||
|
||
func GetType(message proto.Message) string { | ||
return proto.MessageName(message) | ||
} | ||
|
||
func GetInstance(messageType string) (interface{}, error) { | ||
mType := proto.MessageType(messageType) | ||
if mType == nil { | ||
return nil, errors.New("Unknown type: " + messageType) | ||
} | ||
return reflect.New(mType).Interface(), nil | ||
} | ||
|
||
func (this *TypedSettings) Load(message proto.Message) error { | ||
targetType := GetType(message) | ||
if targetType != this.Type { | ||
return errors.New("Have type " + this.Type + ", but retrieved for " + targetType) | ||
} | ||
return proto.Unmarshal(this.Settings, message) | ||
} | ||
|
||
func (this *TypedSettings) GetInstance() (interface{}, error) { | ||
instance, err := GetInstance(this.Type) | ||
if err != nil { | ||
return nil, err | ||
} | ||
if err := proto.Unmarshal(this.Settings, instance.(proto.Message)); err != nil { | ||
return nil, err | ||
} | ||
return instance, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
syntax = "proto3"; | ||
|
||
package v2ray.core.common.loader; | ||
option go_package = "loader"; | ||
option java_package = "com.v2ray.core.common.loader"; | ||
option java_outer_classname = "TypeProto"; | ||
|
||
message TypedSettings { | ||
string type = 1; | ||
bytes settings = 2; | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.