serialize in library
This commit is contained in:
parent
cc99c892f2
commit
e8a5154c5c
@ -17,7 +17,7 @@ func (self *TsIpcApi) Div(
|
|||||||
) (
|
) (
|
||||||
int, error,
|
int, error,
|
||||||
) {
|
) {
|
||||||
results, err := self.Ipc.Call("TsIpcApi.Div", self.Ipc.Serialize(a), self.Ipc.Serialize(b))
|
results, err := self.Ipc.Call("TsIpcApi.Div", a, b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, fmt.Errorf("call to TsIpcApi.Div failed: %w", err)
|
return 0, fmt.Errorf("call to TsIpcApi.Div failed: %w", err)
|
||||||
}
|
}
|
||||||
@ -30,7 +30,7 @@ func (self *TsIpcApi) XorData(
|
|||||||
) (
|
) (
|
||||||
[]byte, error,
|
[]byte, error,
|
||||||
) {
|
) {
|
||||||
results, err := self.Ipc.Call("TsIpcApi.XorData", self.Ipc.Serialize(data1), self.Ipc.Serialize(data2))
|
results, err := self.Ipc.Call("TsIpcApi.XorData", data1, data2)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return []byte{}, fmt.Errorf("call to TsIpcApi.XorData failed: %w", err)
|
return []byte{}, fmt.Errorf("call to TsIpcApi.XorData failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -22,7 +22,7 @@ func ({{ $e.Name | receiver }} *{{ $e.Name }}) {{ $mtd.Name }}(
|
|||||||
) (
|
) (
|
||||||
{{ range $mtd.Ret }}{{ .Type | typedef }}, {{ end }}error,
|
{{ range $mtd.Ret }}{{ .Type | typedef }}, {{ end }}error,
|
||||||
) {
|
) {
|
||||||
results, err := {{ $e.Name | receiver }}.Ipc.Call("{{ $e.Name }}.{{ $mtd.Name }}"{{ range $mtd.Params }}, self.Ipc.Serialize({{ .Name }}){{ end }})
|
results, err := {{ $e.Name | receiver }}.Ipc.Call("{{ $e.Name }}.{{ $mtd.Name }}"{{ range $mtd.Params }}, {{ .Name }}{{ end }})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return {{ range $mtd.Ret }}{{ .Type | zerovalue }}, {{ end }} fmt.Errorf("call to {{ $e.Name }}.{{ $mtd.Name }} failed: %w", err)
|
return {{ range $mtd.Ret }}{{ .Type | zerovalue }}, {{ end }} fmt.Errorf("call to {{ $e.Name }}.{{ $mtd.Name }} failed: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,6 @@ type Message struct {
|
|||||||
type IpcCommon interface {
|
type IpcCommon interface {
|
||||||
Call(method string, params ...any) (Vals, error)
|
Call(method string, params ...any) (Vals, error)
|
||||||
ConvType(needType reflect.Type, gotType reflect.Type, arg any) any
|
ConvType(needType reflect.Type, gotType reflect.Type, arg any) any
|
||||||
Serialize(arg any) any
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type pendingCall struct {
|
type pendingCall struct {
|
||||||
@ -236,6 +235,10 @@ func (ipc *ipcCommon) Call(method string, params ...any) (Vals, error) {
|
|||||||
ipc.pendingCalls[id] = call
|
ipc.pendingCalls[id] = call
|
||||||
ipc.mu.Unlock()
|
ipc.mu.Unlock()
|
||||||
|
|
||||||
|
for i := range params {
|
||||||
|
params[i] = ipc.serialize(params[i])
|
||||||
|
}
|
||||||
|
|
||||||
msg := Message{
|
msg := Message{
|
||||||
Type: MsgCall,
|
Type: MsgCall,
|
||||||
Id: id,
|
Id: id,
|
||||||
@ -295,7 +298,7 @@ func (ipc *ipcCommon) ConvType(needType reflect.Type, gotType reflect.Type, arg
|
|||||||
return arg
|
return arg
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ipc *ipcCommon) Serialize(arg any) any {
|
func (ipc *ipcCommon) serialize(arg any) any {
|
||||||
t := reflect.TypeOf(arg)
|
t := reflect.TypeOf(arg)
|
||||||
switch t.Kind() {
|
switch t.Kind() {
|
||||||
case reflect.Slice:
|
case reflect.Slice:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user