serialize in library

This commit is contained in:
Egor Aristov 2025-12-06 11:57:30 +03:00
parent cc99c892f2
commit e8a5154c5c
Signed by: egor3f
GPG Key ID: 40482A264AAEC85F
3 changed files with 8 additions and 5 deletions

View File

@ -17,7 +17,7 @@ func (self *TsIpcApi) Div(
) (
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 {
return 0, fmt.Errorf("call to TsIpcApi.Div failed: %w", err)
}
@ -30,7 +30,7 @@ func (self *TsIpcApi) XorData(
) (
[]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 {
return []byte{}, fmt.Errorf("call to TsIpcApi.XorData failed: %w", err)
}

View File

@ -22,7 +22,7 @@ func ({{ $e.Name | receiver }} *{{ $e.Name }}) {{ $mtd.Name }}(
) (
{{ 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 {
return {{ range $mtd.Ret }}{{ .Type | zerovalue }}, {{ end }} fmt.Errorf("call to {{ $e.Name }}.{{ $mtd.Name }} failed: %w", err)
}

View File

@ -49,7 +49,6 @@ type Message struct {
type IpcCommon interface {
Call(method string, params ...any) (Vals, error)
ConvType(needType reflect.Type, gotType reflect.Type, arg any) any
Serialize(arg any) any
}
type pendingCall struct {
@ -236,6 +235,10 @@ func (ipc *ipcCommon) Call(method string, params ...any) (Vals, error) {
ipc.pendingCalls[id] = call
ipc.mu.Unlock()
for i := range params {
params[i] = ipc.serialize(params[i])
}
msg := Message{
Type: MsgCall,
Id: id,
@ -295,7 +298,7 @@ func (ipc *ipcCommon) ConvType(needType reflect.Type, gotType reflect.Type, arg
return arg
}
func (ipc *ipcCommon) Serialize(arg any) any {
func (ipc *ipcCommon) serialize(arg any) any {
t := reflect.TypeOf(arg)
switch t.Kind() {
case reflect.Slice: