mirror of
https://github.com/openimsdk/open-im-server.git
synced 2025-05-03 00:12:48 +08:00
1
This commit is contained in:
parent
c16a994fd4
commit
0c9ca254e6
@ -6,21 +6,6 @@ import (
|
|||||||
"reflect"
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CopyAny(from, to interface{}) {
|
|
||||||
t := reflect.ValueOf(to)
|
|
||||||
if t.Kind() == reflect.Ptr {
|
|
||||||
t = t.Elem()
|
|
||||||
}
|
|
||||||
if !t.CanSet() {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
f := reflect.ValueOf(from)
|
|
||||||
if isBaseNil(f) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
copyAny(f, t)
|
|
||||||
}
|
|
||||||
|
|
||||||
func setBaseValue(from, to reflect.Value) {
|
func setBaseValue(from, to reflect.Value) {
|
||||||
if isBaseNil(from) {
|
if isBaseNil(from) {
|
||||||
return
|
return
|
||||||
@ -40,6 +25,21 @@ func setBaseValue(from, to reflect.Value) {
|
|||||||
to.Set(v)
|
to.Set(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func CopyAny(from, to interface{}) {
|
||||||
|
t := reflect.ValueOf(to)
|
||||||
|
if t.Kind() == reflect.Ptr {
|
||||||
|
t = t.Elem()
|
||||||
|
}
|
||||||
|
if !t.CanSet() {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
f := reflect.ValueOf(from)
|
||||||
|
if isBaseNil(f) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
copyAny(f, t)
|
||||||
|
}
|
||||||
|
|
||||||
func copyAny(from, to reflect.Value) {
|
func copyAny(from, to reflect.Value) {
|
||||||
if !to.CanSet() {
|
if !to.CanSet() {
|
||||||
return
|
return
|
||||||
@ -47,6 +47,9 @@ func copyAny(from, to reflect.Value) {
|
|||||||
if isBaseNil(from) {
|
if isBaseNil(from) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if isBaseNil(to) {
|
||||||
|
to.Set(getBaseZeroValue(to.Type()))
|
||||||
|
}
|
||||||
btfrom := baseType(from.Type())
|
btfrom := baseType(from.Type())
|
||||||
btto := baseType(to.Type())
|
btto := baseType(to.Type())
|
||||||
if typeEq(btfrom, btto) {
|
if typeEq(btfrom, btto) {
|
||||||
@ -118,6 +121,15 @@ func baseType(t reflect.Type) reflect.Type {
|
|||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func baseLayer(t reflect.Type) int {
|
||||||
|
var layer int
|
||||||
|
for t.Kind() == reflect.Ptr {
|
||||||
|
layer++
|
||||||
|
t = t.Elem()
|
||||||
|
}
|
||||||
|
return layer
|
||||||
|
}
|
||||||
|
|
||||||
func typeEq(t1, t2 reflect.Type) bool {
|
func typeEq(t1, t2 reflect.Type) bool {
|
||||||
return t1.String() == t2.String()
|
return t1.String() == t2.String()
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user