mirror of
https://github.com/XTLS/Xray-core.git
synced 2025-04-29 16:58:34 +00:00
Remove slices dependency. (#2930)
* Remove slices dependency. * Fix nil pointer dereference bug. --------- Co-authored-by: nobody <nobody@nowhere.mars>
This commit is contained in:
parent
2b08d8638e
commit
961cf9d3b1
2 changed files with 31 additions and 26 deletions
|
@ -3,7 +3,6 @@ package reflect
|
|||
import (
|
||||
"encoding/json"
|
||||
"reflect"
|
||||
"slices"
|
||||
|
||||
cserial "github.com/xtls/xray-core/common/serial"
|
||||
)
|
||||
|
@ -18,6 +17,9 @@ func MarshalToJson(v interface{}) (string, bool) {
|
|||
}
|
||||
|
||||
func marshalTypedMessage(v *cserial.TypedMessage, ignoreNullValue bool) interface{} {
|
||||
if v == nil {
|
||||
return nil
|
||||
}
|
||||
tmsg, err := v.GetInstance()
|
||||
if err != nil {
|
||||
return nil
|
||||
|
@ -111,28 +113,29 @@ func marshalKnownType(v interface{}, ignoreNullValue bool) (interface{}, bool) {
|
|||
}
|
||||
}
|
||||
|
||||
var valueKinds = []reflect.Kind{
|
||||
reflect.Bool,
|
||||
reflect.Int,
|
||||
reflect.Int8,
|
||||
reflect.Int16,
|
||||
reflect.Int32,
|
||||
reflect.Int64,
|
||||
reflect.Uint,
|
||||
reflect.Uint8,
|
||||
reflect.Uint16,
|
||||
reflect.Uint32,
|
||||
reflect.Uint64,
|
||||
reflect.Uintptr,
|
||||
reflect.Float32,
|
||||
reflect.Float64,
|
||||
reflect.Complex64,
|
||||
reflect.Complex128,
|
||||
reflect.String,
|
||||
}
|
||||
|
||||
func isValueKind(kind reflect.Kind) bool {
|
||||
return slices.Contains(valueKinds, kind)
|
||||
switch kind {
|
||||
case reflect.Bool,
|
||||
reflect.Int,
|
||||
reflect.Int8,
|
||||
reflect.Int16,
|
||||
reflect.Int32,
|
||||
reflect.Int64,
|
||||
reflect.Uint,
|
||||
reflect.Uint8,
|
||||
reflect.Uint16,
|
||||
reflect.Uint32,
|
||||
reflect.Uint64,
|
||||
reflect.Uintptr,
|
||||
reflect.Float32,
|
||||
reflect.Float64,
|
||||
reflect.Complex64,
|
||||
reflect.Complex128,
|
||||
reflect.String:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
func marshalInterface(v interface{}, ignoreNullValue bool) interface{} {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue