mirror of
https://github.com/duanhf2012/origin.git
synced 2026-02-15 00:04:46 +08:00
优化本结点与跨结点Rpc结构&简化原始Rpc接口
This commit is contained in:
@@ -3,6 +3,7 @@ package rpc
|
||||
import (
|
||||
"github.com/duanhf2012/origin/util/sync"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
var json = jsoniter.ConfigCompatibleWithStandardLibrary
|
||||
@@ -119,6 +120,22 @@ func (jsonRpcResponseData *JsonRpcResponseData) GetReply() []byte{
|
||||
}
|
||||
|
||||
|
||||
func (jsonProcessor *JsonProcessor) Clone(src interface{}) (interface{},error){
|
||||
dstValue := reflect.New(reflect.ValueOf(src).Type().Elem())
|
||||
bytes,err := json.Marshal(src)
|
||||
if err != nil {
|
||||
return nil,err
|
||||
}
|
||||
|
||||
dst := dstValue.Interface()
|
||||
err = json.Unmarshal(bytes,dst)
|
||||
if err != nil {
|
||||
return nil,err
|
||||
}
|
||||
|
||||
return dst,nil
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user