Closed shinxiang closed 1 year ago
copy内建函数使用时,要求dst必须预分配足够的容量,比如:
按你的建议,更正server.go代码
func (t *Arith) Echo(ctx context.Context, args []byte, reply *[]byte) error {
*reply = make([]byte, 1024)
n := copy(*reply, args)
*reply = (*reply)[:n]
return nil
}
依然报错,信息如下:
panic: reflect: reflect.Value.SetBytes using unaddressable value
goroutine 46 [running]:
reflect.flag.mustBeAssignableSlow(0x97)
C:/Program Files/Go/src/reflect/value.go:262 +0xbd
reflect.flag.mustBeAssignable(0x97)
C:/Program Files/Go/src/reflect/value.go:249 +0x4e
reflect.Value.SetBytes({0x1351a20, 0xc0000094e8, 0x97}, {0xc000374158, 0x3, 0x3})
C:/Program Files/Go/src/reflect/value.go:2259 +0x3e
github.com/smallnest/rpcx/codec.ByteCodec.Decode({}, {0xc000374158, 0x3, 0x3}, {0x1351a20, 0xc0000094e8})
C:/Users/Admin/go/pkg/mod/github.com/smallnest/rpcx@v1.8.11/codec/codec.go:42 +0x9b
github.com/smallnest/rpcx/client.(*Client).input(0xc00015a620)
C:/Users/Admin/go/pkg/mod/github.com/smallnest/rpcx@v1.8.11/client/client.go:694 +0xbc4
created by github.com/smallnest/rpcx/client.(*Client).Connect
C:/Users/Admin/go/pkg/mod/github.com/smallnest/rpcx@v1.8.11/client/connection.go:70 +0x94c
看日志是你的client端代码调用的时候使用unaddressable值
如果你是按照你最开始代码修改的,是没问题的,我测试过
问题已经解决了,谢谢!
我想实现的目的是, 不使用序列化,直接传递 []byte 数据流,代码如下: server.go
client.go
server.go代码调试时 Echo函数参数reply 为nil