-
Notifications
You must be signed in to change notification settings - Fork 584
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protobuf中带有二进制数组使用rpc会改变二进制数组cap #141
Comments
我最近也用到了protobuf的bytes类型,貌似么有发现问题,是必现吗?是否有示例参考一下 |
嗯 我把我大概使用场景贴给你看看
rpc调用方
rpc接收方 UpdatePlayerData接口
这是我第一个使用bytes在rpc间进行传输的协议,一开始我的data数据是一个protobuf的二进制又经过了snappy压缩,出现的问题是发送时的请求参数encode的protobuf二进制的cap要比接收方收到的大,二进制数据时对的,所以proto解码req这个请求参数时报了一个无效二进制的报错。 然后我就尝试去掉了data的snppy过程,直接把一个数据通过protobuf进行encode然后放进了data进行传输,这次通讯时完成了但是接收方的req里的数据都是nil,表现像是拿一个nil进行了decode 然后我把二进制搞了下base64字符串,再尝试就没有出现问题。 时间问题我当时尝试成功就先用base64进行传输了,二进制的问题断点看了一点,只看到了第一次的cap问题,等有时间我再尝试看看 |
我又排查了一下,上面说的我漏掉了中间的string,编辑补充上了
接收方都是用proto 发送方使用ArgType: []byte不会有个问题 具体问题还是没有排查到 |
我知道为啥了,和我的名字叫data有关系,ProtocolMarshal接口内的func叫做GetData(),这样我生成的proto的data字段会带有GetData(),这个结构就会被识别为ProtocolMarshal,然后底层2Bytes或者2Args的时候会判定进ProtocolMarshal,通过接口的GetData来获取二进制,这样就把二进制给损坏了。 |
如题,使用这套rpc进行通信是,请求参数使用protobuf,如果含有protobuf的bytes类型,可能导致rpc_server接收到的二进制数组cap发生改变,进而导致解析报错。
The text was updated successfully, but these errors were encountered: