dubbo-go-hessian2
dubbo-go-hessian2 copied to clipboard
how to rewrite attachment
背景
在 service mesh
环境下,需要在 sidecar
中解析dubbo
的attachment
,并根据需求添加一些自定义的参数进去,就像SetHeader
一样,然后重新构建 dubbo
包
问题
如果使用hessian.NewDecoder
,传递的参数没有对象是可以的,如果参数中有对象会报错,参考 #163 的解决办法,使用 hessian.NewDecoderWithSkip
可以解决,但是重新构建的时候arg
类型是interface{}
,值是nil
解决
能否多提供一个Decode
方法,直接返回[]byte
内容,重新构建的时候直接encode.Append(arg)
就可以重新构建dubbo
包
solve
decode
- use
hessian.NewDecoderWithSkip
Decode dubboVersion/path/version/method/argsTypes/args/attachment info. - create hessian encode object, encode attachment.
- calc encode len
encode
- encode.Append(payload[len(payload]-attachment_encode_len)
- encode.Encode(attachment)
hello folks ..! I am good at java and I wanted to resolve this issue so please explain this issue some more detail as this is my first contribution .
some materials:
- dubbo rpc protocol: https://cn.dubbo.apache.org/zh/blog/2018/10/05/dubbo-%e5%8d%8f%e8%ae%ae%e8%af%a6%e8%a7%a3/
- dubbo rpc protocol implement : https://github.com/apache/dubbo-go/blob/master/protocol/dubbo/dubbo_protocol.go
dubbo rpc attachments belongs to the Variable Part, but u can't get where it starts from, u must skip the parts before it, include Dubbo version, Service name, Service version, Method name, Method parameter types, Method arguments. But for hessian2 serialization protocol , u must decode the data to find where it ends with. There is't a length to tell the length of the data. So it costs a lot for the sidecar of mesh to update the attachments.
And I'm not sure whether the MOSN has already implemented this feature.